Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

支持 .NET 6.0 框架 #4

Merged
merged 1 commit into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,21 +9,27 @@
/// </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 静态变量

/// <summary>
/// 向量维度。
/// </summary>
public static abstract int Dimension { get; }

Check warning on line 27 in DotNetCampus.Numerics/IVector.cs

View workflow job for this annotation

GitHub Actions / build

Using both 'static' and 'abstract' modifiers requires opting into preview features. See https://aka.ms/dotnet-warnings/preview-features for more information. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2252)

Check warning on line 27 in DotNetCampus.Numerics/IVector.cs

View workflow job for this annotation

GitHub Actions / build

Using both 'static' and 'abstract' modifiers requires opting into preview features. See https://aka.ms/dotnet-warnings/preview-features for more information. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2252)

Check warning on line 27 in DotNetCampus.Numerics/IVector.cs

View workflow job for this annotation

GitHub Actions / publish

Using both 'static' and 'abstract' modifiers requires opting into preview features. See https://aka.ms/dotnet-warnings/preview-features for more information. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2252)

Check warning on line 27 in DotNetCampus.Numerics/IVector.cs

View workflow job for this annotation

GitHub Actions / publish

Using both 'static' and 'abstract' modifiers requires opting into preview features. See https://aka.ms/dotnet-warnings/preview-features for more information. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2252)

/// <summary>
/// 零向量。
/// </summary>
public static abstract TSelf Zero { get; }

Check warning on line 32 in DotNetCampus.Numerics/IVector.cs

View workflow job for this annotation

GitHub Actions / build

Using both 'static' and 'abstract' modifiers requires opting into preview features. See https://aka.ms/dotnet-warnings/preview-features for more information. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2252)

Check warning on line 32 in DotNetCampus.Numerics/IVector.cs

View workflow job for this annotation

GitHub Actions / build

Using both 'static' and 'abstract' modifiers requires opting into preview features. See https://aka.ms/dotnet-warnings/preview-features for more information. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2252)

Check warning on line 32 in DotNetCampus.Numerics/IVector.cs

View workflow job for this annotation

GitHub Actions / publish

Using both 'static' and 'abstract' modifiers requires opting into preview features. See https://aka.ms/dotnet-warnings/preview-features for more information. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2252)

Check warning on line 32 in DotNetCampus.Numerics/IVector.cs

View workflow job for this annotation

GitHub Actions / publish

Using both 'static' and 'abstract' modifiers requires opting into preview features. See https://aka.ms/dotnet-warnings/preview-features for more information. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2252)

#endregion

Expand Down Expand Up @@ -67,11 +73,11 @@

#pragma warning disable CS1591

public static abstract TSelf operator +(TSelf vector1, TSelf vector2);

Check warning on line 76 in DotNetCampus.Numerics/IVector.cs

View workflow job for this annotation

GitHub Actions / build

Using both 'static' and 'abstract' modifiers requires opting into preview features. See https://aka.ms/dotnet-warnings/preview-features for more information. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2252)

Check warning on line 76 in DotNetCampus.Numerics/IVector.cs

View workflow job for this annotation

GitHub Actions / publish

Using both 'static' and 'abstract' modifiers requires opting into preview features. See https://aka.ms/dotnet-warnings/preview-features for more information. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2252)

public static abstract TSelf operator -(TSelf vector1, TSelf vector2);

Check warning on line 78 in DotNetCampus.Numerics/IVector.cs

View workflow job for this annotation

GitHub Actions / build

Using both 'static' and 'abstract' modifiers requires opting into preview features. See https://aka.ms/dotnet-warnings/preview-features for more information. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2252)

Check warning on line 78 in DotNetCampus.Numerics/IVector.cs

View workflow job for this annotation

GitHub Actions / publish

Using both 'static' and 'abstract' modifiers requires opting into preview features. See https://aka.ms/dotnet-warnings/preview-features for more information. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2252)

public static abstract TNum operator *(TSelf vector1, TSelf vector2);

Check warning on line 80 in DotNetCampus.Numerics/IVector.cs

View workflow job for this annotation

GitHub Actions / build

Using both 'static' and 'abstract' modifiers requires opting into preview features. See https://aka.ms/dotnet-warnings/preview-features for more information. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2252)

Check warning on line 80 in DotNetCampus.Numerics/IVector.cs

View workflow job for this annotation

GitHub Actions / publish

Using both 'static' and 'abstract' modifiers requires opting into preview features. See https://aka.ms/dotnet-warnings/preview-features for more information. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2252)

public static abstract TSelf operator *(TSelf vector, TNum scalar);

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 @@
/// <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 @@
/// <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 @@
/// 未使用构造函数创建的区间是空集。
/// 区间起点大于等于终点的区间是空集。
/// </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

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

View workflow job for this annotation

GitHub Actions / publish

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 @@
/// <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 @@
/// <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 @@
/// <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 @@
&& 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 @@
/// <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 @@

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 @@
{
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 @@
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,18 +80,24 @@
/// <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 静态变量

/// <summary>
/// 零矩阵。
/// </summary>
public static abstract TSelf Zero { get; }

Check warning on line 100 in DotNetCampus.Numerics/Matrix/IMatrix.cs

View workflow job for this annotation

GitHub Actions / build

Using both 'static' and 'abstract' modifiers requires opting into preview features. See https://aka.ms/dotnet-warnings/preview-features for more information. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2252)

Check warning on line 100 in DotNetCampus.Numerics/Matrix/IMatrix.cs

View workflow job for this annotation

GitHub Actions / publish

Using both 'static' and 'abstract' modifiers requires opting into preview features. See https://aka.ms/dotnet-warnings/preview-features for more information. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2252)

#endregion

Expand Down Expand Up @@ -125,7 +134,10 @@
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,14 +162,17 @@
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 静态变量

/// <summary>
/// 单位矩阵。
/// </summary>
public static abstract TSelf Identity { get; }

Check warning on line 175 in DotNetCampus.Numerics/Matrix/IMatrix.cs

View workflow job for this annotation

GitHub Actions / build

Using both 'static' and 'abstract' modifiers requires opting into preview features. See https://aka.ms/dotnet-warnings/preview-features for more information. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2252)

Check warning on line 175 in DotNetCampus.Numerics/Matrix/IMatrix.cs

View workflow job for this annotation

GitHub Actions / publish

Using both 'static' and 'abstract' modifiers requires opting into preview features. See https://aka.ms/dotnet-warnings/preview-features for more information. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2252)

#endregion

Expand Down