From ef992ef4fdaf4baecf061812438a4edd298ff85e Mon Sep 17 00:00:00 2001 From: lindexi Date: Thu, 12 Sep 2024 17:55:37 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=20.NET=206.0=20=E6=A1=86?= =?UTF-8?q?=E6=9E=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DotNetCampus.Numerics.Geometry.csproj | 2 +- .../IBezierCurve.cs | 5 ++- DotNetCampus.Numerics.Geometry/IPoint.cs | 5 ++- .../DotNetCampus.Numerics.csproj | 2 +- DotNetCampus.Numerics/IVector.cs | 10 ++++- DotNetCampus.Numerics/Interval.cs | 41 +++++++++++++++++-- DotNetCampus.Numerics/Matrix/IMatrix.cs | 25 ++++++++--- 7 files changed, 75 insertions(+), 15 deletions(-) diff --git a/DotNetCampus.Numerics.Geometry/DotNetCampus.Numerics.Geometry.csproj b/DotNetCampus.Numerics.Geometry/DotNetCampus.Numerics.Geometry.csproj index 0be1b94..5f66025 100644 --- a/DotNetCampus.Numerics.Geometry/DotNetCampus.Numerics.Geometry.csproj +++ b/DotNetCampus.Numerics.Geometry/DotNetCampus.Numerics.Geometry.csproj @@ -1,7 +1,7 @@ - net8.0 + net6.0;net8.0 enable diff --git a/DotNetCampus.Numerics.Geometry/IBezierCurve.cs b/DotNetCampus.Numerics.Geometry/IBezierCurve.cs index df8d0cc..397db3e 100644 --- a/DotNetCampus.Numerics.Geometry/IBezierCurve.cs +++ b/DotNetCampus.Numerics.Geometry/IBezierCurve.cs @@ -8,7 +8,10 @@ namespace DotNetCampus.Numerics.Geometry; public interface IBezierCurve : ICurve where TPoint :unmanaged, IPoint where TVector : unmanaged, IVector - where TNum : unmanaged, IFloatingPoint + where TNum : unmanaged +#if NET8_0_OR_GREATER + , IFloatingPoint +#endif { /// /// 获取曲线上的点。 diff --git a/DotNetCampus.Numerics.Geometry/IPoint.cs b/DotNetCampus.Numerics.Geometry/IPoint.cs index dfe3168..5478c9c 100644 --- a/DotNetCampus.Numerics.Geometry/IPoint.cs +++ b/DotNetCampus.Numerics.Geometry/IPoint.cs @@ -13,7 +13,10 @@ namespace DotNetCampus.Numerics.Geometry; public interface IPoint where TSelf : unmanaged, IPoint where TVector : unmanaged, IVector - where TNum : unmanaged, IFloatingPoint + where TNum : unmanaged +#if NET8_0_OR_GREATER + , IFloatingPoint +#endif { /// /// 获取两个点的中点。 diff --git a/DotNetCampus.Numerics/DotNetCampus.Numerics.csproj b/DotNetCampus.Numerics/DotNetCampus.Numerics.csproj index 143c463..569d2fa 100644 --- a/DotNetCampus.Numerics/DotNetCampus.Numerics.csproj +++ b/DotNetCampus.Numerics/DotNetCampus.Numerics.csproj @@ -1,7 +1,7 @@ - net8.0 + net6.0;net8.0 enable diff --git a/DotNetCampus.Numerics/IVector.cs b/DotNetCampus.Numerics/IVector.cs index c9a32b8..32c3370 100644 --- a/DotNetCampus.Numerics/IVector.cs +++ b/DotNetCampus.Numerics/IVector.cs @@ -9,9 +9,15 @@ namespace DotNetCampus.Numerics; /// /// 实现此接口的类型。 /// 向量元素的类型。 -public interface IVector : IEqualityOperators +public interface IVector +#if NET8_0_OR_GREATER + : IEqualityOperators +#endif where TSelf : unmanaged, IVector - where TNum : unmanaged, IFloatingPoint + where TNum : unmanaged +#if NET8_0_OR_GREATER + , IFloatingPoint +#endif { #region 静态变量 diff --git a/DotNetCampus.Numerics/Interval.cs b/DotNetCampus.Numerics/Interval.cs index cb591d0..c0122ac 100644 --- a/DotNetCampus.Numerics/Interval.cs +++ b/DotNetCampus.Numerics/Interval.cs @@ -11,7 +11,10 @@ namespace DotNetCampus.Numerics; /// 区间的左端点。 /// 区间的右端点。 public readonly record struct Interval(TNum Start, TNum End) - where TNum : unmanaged, IFloatingPoint + where TNum : unmanaged +#if NET8_0_OR_GREATER + , IFloatingPoint +#endif { #region 静态方法 @@ -23,7 +26,11 @@ public readonly record struct Interval(TNum Start, TNum End) /// public static Interval Create(TNum a, TNum b) { +#if NET8_0_OR_GREATER return a > b ? new Interval(b, a) : new Interval(a, b); +#else + throw new NotSupportedException(); +#endif } #endregion @@ -37,7 +44,12 @@ public static Interval Create(TNum a, TNum b) /// 未使用构造函数创建的区间是空集。 /// 区间起点大于等于终点的区间是空集。 /// - private readonly bool _isNotEmpty = Start <= End; + private readonly bool _isNotEmpty +#if NET8_0_OR_GREATER + = Start <= End; +#else + ; +#endif #endregion @@ -51,7 +63,12 @@ public static Interval Create(TNum a, TNum b) /// /// 区间长度。 /// - 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 @@ -64,7 +81,11 @@ public static Interval Create(TNum a, TNum b) /// public bool Contains(TNum value) { +#if NET8_0_OR_GREATER return Start <= value && value <= End; +#else + throw new NotSupportedException(); +#endif } /// @@ -90,6 +111,7 @@ public static class IntervalExtensions /// /// public static bool IsProperSubsetOf(this Interval interval, Interval other) +#if NET8_0_OR_GREATER where TNum : unmanaged, IFloatingPoint { if (other.IsEmpty) @@ -102,6 +124,10 @@ public static bool IsProperSubsetOf(this Interval interval, Interval && interval.End <= other.End && (!interval.Start.Equals(other.Start) || !interval.End.Equals(other.End)); } +#else + where TNum : unmanaged + => throw new NotSupportedException(); +#endif /// /// 是否是一个区间的子集。 @@ -110,6 +136,7 @@ public static bool IsProperSubsetOf(this Interval interval, Interval /// /// public static bool IsSubsetOf(this Interval interval, Interval other) +#if NET8_0_OR_GREATER where TNum : unmanaged, IFloatingPoint { if (interval.IsEmpty) @@ -120,7 +147,12 @@ public static bool IsSubsetOf(this Interval interval, Interval return interval.Start >= other.Start && interval.End <= other.End; } +#else + where TNum : unmanaged + => throw new NotSupportedException(); +#endif +#if NET8_0_OR_GREATER /// /// 是否是一个区间的真超集。 /// @@ -144,6 +176,7 @@ public static bool IsSupersetOf(this Interval interval, Interval where TRow : unmanaged, IVector where TColumn : unmanaged, IVector - where TNum : unmanaged, IFloatingPoint + where TNum : unmanaged +#if NET8_0_OR_GREATER + , IFloatingPoint +#endif { #region 静态变量 @@ -77,11 +80,17 @@ public interface IMatrix /// 每行的向量。 /// 每一列的向量。 /// 矩阵元素的类型。 -public interface IMatrix : IMatrix, IEqualityOperators +public interface IMatrix : IMatrix +#if NET8_0_OR_GREATER + , IEqualityOperators +#endif where TSelf : IMatrix where TRow : unmanaged, IVector where TColumn : unmanaged, IVector - where TNum : unmanaged, IFloatingPoint + where TNum : unmanaged +#if NET8_0_OR_GREATER + , IFloatingPoint +#endif { #region 静态变量 @@ -125,7 +134,10 @@ public interface IMatrix : IMatrix where TRow : unmanaged, IVector where TColumn : unmanaged, IVector - where TNum : unmanaged, IFloatingPoint + where TNum : unmanaged +#if NET8_0_OR_GREATER + , IFloatingPoint +#endif where TTranspose : IMatrix { #region 属性 @@ -150,7 +162,10 @@ public interface IMatrix : IMatrix : IMatrix where TSelf : ISquareMatrix where TVector : unmanaged, IVector - where TNum : unmanaged, IFloatingPoint + where TNum : unmanaged +#if NET8_0_OR_GREATER + , IFloatingPoint +#endif { #region 静态变量