Skip to content

Commit

Permalink
Merge pull request #4 from dotnet-campus/t/lindexi/DotNet
Browse files Browse the repository at this point in the history
支持 .NET 6.0 框架
  • Loading branch information
SeWZC authored Sep 12, 2024
2 parents 8fd2a5e + ef992ef commit 06d467b
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFrameworks>net6.0;net8.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

Expand Down
5 changes: 4 additions & 1 deletion DotNetCampus.Numerics.Geometry/IBezierCurve.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ namespace DotNetCampus.Numerics.Geometry;
public interface IBezierCurve<TPoint, TVector, TNum> : ICurve
where TPoint :unmanaged, IPoint<TPoint, TVector, TNum>
where TVector : unmanaged, IVector<TVector, TNum>
where TNum : unmanaged, IFloatingPoint<TNum>
where TNum : unmanaged
#if NET8_0_OR_GREATER
, IFloatingPoint<TNum>
#endif
{
/// <summary>
/// 获取曲线上的点。
Expand Down
5 changes: 4 additions & 1 deletion DotNetCampus.Numerics.Geometry/IPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ namespace DotNetCampus.Numerics.Geometry;
public interface IPoint<TSelf, TVector, TNum>
where TSelf : unmanaged, IPoint<TSelf, TVector, TNum>
where TVector : unmanaged, IVector<TVector, TNum>
where TNum : unmanaged, IFloatingPoint<TNum>
where TNum : unmanaged
#if NET8_0_OR_GREATER
, IFloatingPoint<TNum>
#endif
{
/// <summary>
/// 获取两个点的中点。
Expand Down
2 changes: 1 addition & 1 deletion DotNetCampus.Numerics/DotNetCampus.Numerics.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFrameworks>net6.0;net8.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

Expand Down
10 changes: 8 additions & 2 deletions DotNetCampus.Numerics/IVector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,15 @@ namespace DotNetCampus.Numerics;
/// </summary>
/// <typeparam name="TSelf">实现此接口的类型。</typeparam>
/// <typeparam name="TNum">向量元素的类型。</typeparam>
public interface IVector<TSelf, TNum> : IEqualityOperators<TSelf, TSelf, bool>
public interface IVector<TSelf, TNum>
#if NET8_0_OR_GREATER
: IEqualityOperators<TSelf, TSelf, bool>
#endif
where TSelf : unmanaged, IVector<TSelf, TNum>
where TNum : unmanaged, IFloatingPoint<TNum>
where TNum : unmanaged
#if NET8_0_OR_GREATER
, IFloatingPoint<TNum>
#endif
{
#region 静态变量

Expand Down
41 changes: 37 additions & 4 deletions DotNetCampus.Numerics/Interval.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ namespace DotNetCampus.Numerics;
/// <param name="Start">区间的左端点。</param>
/// <param name="End">区间的右端点。</param>
public readonly record struct Interval<TNum>(TNum Start, TNum End)
where TNum : unmanaged, IFloatingPoint<TNum>
where TNum : unmanaged
#if NET8_0_OR_GREATER
, IFloatingPoint<TNum>
#endif
{
#region 静态方法

Expand All @@ -23,7 +26,11 @@ public readonly record struct Interval<TNum>(TNum Start, TNum End)
/// <returns></returns>
public static Interval<TNum> Create(TNum a, TNum b)
{
#if NET8_0_OR_GREATER
return a > b ? new Interval<TNum>(b, a) : new Interval<TNum>(a, b);
#else
throw new NotSupportedException();
#endif
}

#endregion
Expand All @@ -37,7 +44,12 @@ public static Interval<TNum> Create(TNum a, TNum b)
/// 未使用构造函数创建的区间是空集。
/// 区间起点大于等于终点的区间是空集。
/// </remarks>
private readonly bool _isNotEmpty = Start <= End;
private readonly bool _isNotEmpty

Check warning on line 47 in DotNetCampus.Numerics/Interval.cs

View workflow job for this annotation

GitHub Actions / build

Field 'Interval<TNum>._isNotEmpty' is never assigned to, and will always have its default value false
#if NET8_0_OR_GREATER
= Start <= End;
#else
;
#endif

#endregion

Expand All @@ -51,7 +63,12 @@ public static Interval<TNum> Create(TNum a, TNum b)
/// <summary>
/// 区间长度。
/// </summary>
public TNum Length => Start >= End ? TNum.Zero : End - Start;
public TNum Length
#if NET8_0_OR_GREATER
=> Start >= End ? TNum.Zero : End - Start;
#else
=> throw new NotSupportedException();
#endif

#endregion

Expand All @@ -64,7 +81,11 @@ public static Interval<TNum> Create(TNum a, TNum b)
/// <returns></returns>
public bool Contains(TNum value)
{
#if NET8_0_OR_GREATER
return Start <= value && value <= End;
#else
throw new NotSupportedException();
#endif
}

/// <inheritdoc />
Expand All @@ -90,6 +111,7 @@ public static class IntervalExtensions
/// <param name="other"></param>
/// <returns></returns>
public static bool IsProperSubsetOf<TNum>(this Interval<TNum> interval, Interval<TNum> other)
#if NET8_0_OR_GREATER
where TNum : unmanaged, IFloatingPoint<TNum>
{
if (other.IsEmpty)
Expand All @@ -102,6 +124,10 @@ public static bool IsProperSubsetOf<TNum>(this Interval<TNum> interval, Interval
&& interval.End <= other.End
&& (!interval.Start.Equals(other.Start) || !interval.End.Equals(other.End));
}
#else
where TNum : unmanaged
=> throw new NotSupportedException();
#endif

/// <summary>
/// 是否是一个区间的子集。
Expand All @@ -110,6 +136,7 @@ public static bool IsProperSubsetOf<TNum>(this Interval<TNum> interval, Interval
/// <param name="other"></param>
/// <returns></returns>
public static bool IsSubsetOf<TNum>(this Interval<TNum> interval, Interval<TNum> other)
#if NET8_0_OR_GREATER
where TNum : unmanaged, IFloatingPoint<TNum>
{
if (interval.IsEmpty)
Expand All @@ -120,7 +147,12 @@ public static bool IsSubsetOf<TNum>(this Interval<TNum> interval, Interval<TNum>

return interval.Start >= other.Start && interval.End <= other.End;
}
#else
where TNum : unmanaged
=> throw new NotSupportedException();
#endif

#if NET8_0_OR_GREATER
/// <summary>
/// 是否是一个区间的真超集。
/// </summary>
Expand All @@ -144,6 +176,7 @@ public static bool IsSupersetOf<TNum>(this Interval<TNum> interval, Interval<TNu
{
return other.IsSubsetOf(interval);
}
#endif

#endregion
}
}
25 changes: 20 additions & 5 deletions DotNetCampus.Numerics/Matrix/IMatrix.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ namespace DotNetCampus.Numerics.Matrix;
public interface IMatrix<TRow, TColumn, TNum>
where TRow : unmanaged, IVector<TRow, TNum>
where TColumn : unmanaged, IVector<TColumn, TNum>
where TNum : unmanaged, IFloatingPoint<TNum>
where TNum : unmanaged
#if NET8_0_OR_GREATER
, IFloatingPoint<TNum>
#endif
{
#region 静态变量

Expand Down Expand Up @@ -77,11 +80,17 @@ public interface IMatrix<TRow, TColumn, TNum>
/// <typeparam name="TRow">每行的向量。</typeparam>
/// <typeparam name="TColumn">每一列的向量。</typeparam>
/// <typeparam name="TNum">矩阵元素的类型。</typeparam>
public interface IMatrix<TSelf, TRow, TColumn, TNum> : IMatrix<TRow, TColumn, TNum>, IEqualityOperators<TSelf, TSelf, bool>
public interface IMatrix<TSelf, TRow, TColumn, TNum> : IMatrix<TRow, TColumn, TNum>
#if NET8_0_OR_GREATER
, IEqualityOperators<TSelf, TSelf, bool>
#endif
where TSelf : IMatrix<TSelf, TRow, TColumn, TNum>
where TRow : unmanaged, IVector<TRow, TNum>
where TColumn : unmanaged, IVector<TColumn, TNum>
where TNum : unmanaged, IFloatingPoint<TNum>
where TNum : unmanaged
#if NET8_0_OR_GREATER
, IFloatingPoint<TNum>
#endif
{
#region 静态变量

Expand Down Expand Up @@ -125,7 +134,10 @@ public interface IMatrix<TSelf, TRow, TColumn, TNum, TTranspose> : IMatrix<TSelf
where TSelf : IMatrix<TSelf, TRow, TColumn, TNum, TTranspose>
where TRow : unmanaged, IVector<TRow, TNum>
where TColumn : unmanaged, IVector<TColumn, TNum>
where TNum : unmanaged, IFloatingPoint<TNum>
where TNum : unmanaged
#if NET8_0_OR_GREATER
, IFloatingPoint<TNum>
#endif
where TTranspose : IMatrix<TTranspose, TColumn, TRow, TNum>
{
#region 属性
Expand All @@ -150,7 +162,10 @@ public interface IMatrix<TSelf, TRow, TColumn, TNum, TTranspose> : IMatrix<TSelf
public interface ISquareMatrix<TSelf, TVector, TNum> : IMatrix<TSelf, TVector, TVector, TNum, TSelf>
where TSelf : ISquareMatrix<TSelf, TVector, TNum>
where TVector : unmanaged, IVector<TVector, TNum>
where TNum : unmanaged, IFloatingPoint<TNum>
where TNum : unmanaged
#if NET8_0_OR_GREATER
, IFloatingPoint<TNum>
#endif
{
#region 静态变量

Expand Down

0 comments on commit 06d467b

Please sign in to comment.