Skip to content

Commit

Permalink
Refactor interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
aalmada committed Nov 3, 2023
1 parent e3db11d commit 686a3c9
Show file tree
Hide file tree
Showing 67 changed files with 1,293 additions and 800 deletions.
24 changes: 12 additions & 12 deletions NetFabric.Numerics.sln
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetFabric.Numerics.Angle",
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetFabric.Numerics.Angle.UnitTests", "src\NetFabric.Numerics.Angle.UnitTests\NetFabric.Numerics.Angle.UnitTests.csproj", "{D3F1C490-2386-4BBC-8559-35AC6F53D2F3}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetFabric.Numerics.Geography", "src\NetFabric.Numerics.Geography\NetFabric.Numerics.Geography.csproj", "{EF5F4630-2DBC-42F3-A4CA-15DEF059BE84}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetFabric.Numerics.Geography.UnitTests", "src\NetFabric.Numerics.Geography.UnitTests\NetFabric.Numerics.Geography.UnitTests.csproj", "{76EF4513-5310-4345-8A04-BDB18E0F74CF}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetFabric.Numerics.UnitTests", "src\NetFabric.Numerics.UnitTests\NetFabric.Numerics.UnitTests.csproj", "{F269C2EB-68AF-490B-B728-7E4EDE43F1B0}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Workflows", "Workflows", "{9991D38D-9E7A-42B8-B4EB-E2FB4183D266}"
Expand Down Expand Up @@ -56,6 +52,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Api", "Api", "{83BDB68A-4F4
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetFabric.Numerics.Benchmarks", "src\NetFabric.Numerics.Benchmarks\NetFabric.Numerics.Benchmarks.csproj", "{22D5FBE1-04E3-4B84-94A5-C2B959A51D68}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetFabric.Numerics.Geodesy", "src\NetFabric.Numerics.Geodesy\NetFabric.Numerics.Geodesy.csproj", "{4ACC5E06-26C9-41FB-BEAD-620CBB0DB1CC}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetFabric.Numerics.Geodesy.UnitTests", "src\NetFabric.Numerics.Geodesy.UnitTests\NetFabric.Numerics.Geodesy.UnitTests.csproj", "{4E4414C1-E5CF-4679-9016-7C3F70F13110}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -74,14 +74,6 @@ Global
{D3F1C490-2386-4BBC-8559-35AC6F53D2F3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D3F1C490-2386-4BBC-8559-35AC6F53D2F3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D3F1C490-2386-4BBC-8559-35AC6F53D2F3}.Release|Any CPU.Build.0 = Release|Any CPU
{EF5F4630-2DBC-42F3-A4CA-15DEF059BE84}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EF5F4630-2DBC-42F3-A4CA-15DEF059BE84}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EF5F4630-2DBC-42F3-A4CA-15DEF059BE84}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EF5F4630-2DBC-42F3-A4CA-15DEF059BE84}.Release|Any CPU.Build.0 = Release|Any CPU
{76EF4513-5310-4345-8A04-BDB18E0F74CF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{76EF4513-5310-4345-8A04-BDB18E0F74CF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{76EF4513-5310-4345-8A04-BDB18E0F74CF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{76EF4513-5310-4345-8A04-BDB18E0F74CF}.Release|Any CPU.Build.0 = Release|Any CPU
{F269C2EB-68AF-490B-B728-7E4EDE43F1B0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F269C2EB-68AF-490B-B728-7E4EDE43F1B0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F269C2EB-68AF-490B-B728-7E4EDE43F1B0}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand All @@ -90,6 +82,14 @@ Global
{22D5FBE1-04E3-4B84-94A5-C2B959A51D68}.Debug|Any CPU.Build.0 = Debug|Any CPU
{22D5FBE1-04E3-4B84-94A5-C2B959A51D68}.Release|Any CPU.ActiveCfg = Release|Any CPU
{22D5FBE1-04E3-4B84-94A5-C2B959A51D68}.Release|Any CPU.Build.0 = Release|Any CPU
{4ACC5E06-26C9-41FB-BEAD-620CBB0DB1CC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4ACC5E06-26C9-41FB-BEAD-620CBB0DB1CC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4ACC5E06-26C9-41FB-BEAD-620CBB0DB1CC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4ACC5E06-26C9-41FB-BEAD-620CBB0DB1CC}.Release|Any CPU.Build.0 = Release|Any CPU
{4E4414C1-E5CF-4679-9016-7C3F70F13110}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4E4414C1-E5CF-4679-9016-7C3F70F13110}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4E4414C1-E5CF-4679-9016-7C3F70F13110}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4E4414C1-E5CF-4679-9016-7C3F70F13110}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ To get started with **NetFabric.Numerics**, you need to install the library's Nu

- [NetFabric.Numerics.Angle](https://www.nuget.org/packages/NetFabric.Numerics.Angle/): Provides strongly-typed angle implementations.
- [NetFabric.Numerics](https://www.nuget.org/packages/NetFabric.Numerics/): Provides strongly-typed rectangular, polar and spherical coordinate implementations.
- [NetFabric.Numerics.Geography](https://www.nuget.org/packages/NetFabric.Numerics.Geography/): Provides strongly-typed geodetic coordinate implementations.
- [NetFabric.Numerics.Geodesy](https://www.nuget.org/packages/NetFabric.Numerics.Geodesy/): Provides strongly-typed geodetic coordinate implementations.

Make sure to include the appropriate package(s) in your project, depending on your specific needs.

Expand Down Expand Up @@ -80,7 +80,7 @@ With **NetFabric.Numerics**, you can work with polar coordinates using different
**NetFabric.Numerics** also supports strongly-typed geodetic coordinate implementations, specifically latitude and longitude. Here's an example:

``` csharp
using NetFabric.Numerics.Geography.Geodetic2;
using NetFabric.Numerics.Geodesy.Geodetic2;

var wgs84Point = new Point<WGS84, Degrees, double>(new(0.0), new(0.0)); // Geodetic point using WGS84 datum
var wgs1972Point = new Point<WGS1972, Degrees, double>(new(0.0), new(0.0)); // Geodetic point using WGS1972 datum
Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ To get started with **NetFabric.Numerics**, you need to install the library's Nu

- [NetFabric.Numerics.Angle](https://www.nuget.org/packages/NetFabric.Numerics.Angle/): Provides strongly-typed angle implementations.
- [NetFabric.Numerics](https://www.nuget.org/packages/NetFabric.Numerics/): Provides strongly-typed rectangular 2D and 3D, polar, and spherical coordinate system implementations.
- [NetFabric.Numerics.Geography](https://www.nuget.org/packages/NetFabric.Numerics.Geography/): Provides strongly-typed geodetic coordinate implementations.
- [NetFabric.Numerics.Geodesy](https://www.nuget.org/packages/NetFabric.Numerics.Geodesy/): Provides strongly-typed geodetic coordinate implementations.

Make sure to include the appropriate package(s) in your project, depending on your specific needs.

Expand Down
22 changes: 22 additions & 0 deletions src/NetFabric.Numerics.Angle.UnitTests/DegreesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,28 @@

public class DegreesTests
{
[Fact]
public void IAngle_Should_Succeed()
{
// arrange
IAngle angle = Angle<Degrees, float>.Right;

// act
var units = angle.Units;
var value = angle.Value;
var valueType = angle.ValueType;

// assert
units.Name.Should().Be(Degrees.Name);
units.Symbol.Should().Be(Degrees.Symbol);
units.Zero.Should().Be(Degrees.Zero);
units.Right.Should().Be(Degrees.Right);
units.Straight.Should().Be(Degrees.Straight);
units.Full.Should().Be(Degrees.Full);
value.Should().Be(Degrees.Right);
valueType.Should().Be(typeof(float));
}

[Fact]
public void Constants_Should_Succeed()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<ItemGroup>
<PackageReference Include="FluentAssertions" Version="6.12.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
<PackageReference Include="xunit" Version="2.5.3" />
<PackageReference Include="xunit" Version="2.6.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
Expand Down
8 changes: 4 additions & 4 deletions src/NetFabric.Numerics.Angle.UnitTests/TrigonometryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class TrigonometryTests
public void Cos_Double_Should_Succeed(Angle<Radians, double> angle)
{
// arrange
var expected = Math.Cos(angle.Value);
var expected = double.Cos(angle.Value);

// act
var result = Angle.Cos(angle);
Expand All @@ -32,8 +32,8 @@ public void Cos_Double_Should_Succeed(Angle<Radians, double> angle)
public void ACos_Double_Should_Succeed(Angle<Radians, double> angle)
{
// arrange
var cos = Math.Cos(angle.Value);
var expected = new AngleReduced<Radians, double>(Math.Acos(cos));
var cos = double.Cos(angle.Value);
var expected = new AngleReduced<Radians, double>(double.Acos(cos));

// act
var result = Angle.Acos(cos);
Expand All @@ -58,7 +58,7 @@ public void ACos_Double_Should_Succeed(Angle<Radians, double> angle)
public void Cos_Float_Should_Succeed(Angle<Radians, float> angle)
{
// arrange
var expected = (float)Math.Cos(angle.Value);
var expected = float.Cos(angle.Value);

// act
var result = Angle.Cos(angle);
Expand Down
42 changes: 21 additions & 21 deletions src/NetFabric.Numerics.Angle/Angle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static partial class Angle
/// </returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Angle<TAngleUnits, T> Clamp<TAngleUnits, T>(Angle<TAngleUnits, T> vector, Angle<TAngleUnits, T> min, Angle<TAngleUnits, T> max)
where TAngleUnits : struct, IAngleUnits<TAngleUnits>
where TAngleUnits : IAngleUnits
where T : struct, IFloatingPoint<T>, IMinMaxValue<T>
=> new(T.Clamp(vector.Value, min.Value, max.Value));

Expand All @@ -61,7 +61,7 @@ public static Angle<TAngleUnits, T> Clamp<TAngleUnits, T>(Angle<TAngleUnits, T>
/// <returns>The reduced angle of <paramref name="angle"/>.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static AngleReduced<TUnits, T> Reduce<TUnits, T>(Angle<TUnits, T> angle)
where TUnits : IAngleUnits<TUnits>
where TUnits : IAngleUnits
where T : struct, IFloatingPoint<T>, IMinMaxValue<T>
{
var reduced = angle.Value % Angle<TUnits, T>.Full.Value;
Expand All @@ -87,7 +87,7 @@ public static AngleReduced<TUnits, T> Reduce<TUnits, T>(Angle<TUnits, T> angle)
/// <returns>The reference angle of <paramref name="angle"/>.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static AngleReduced<TUnits, T> GetReference<TUnits, T>(AngleReduced<TUnits, T> angle)
where TUnits : IAngleUnits<TUnits>
where TUnits : IAngleUnits
where T : struct, IFloatingPoint<T>, IMinMaxValue<T>
{
var quadrant = GetQuadrant(angle);
Expand Down Expand Up @@ -133,7 +133,7 @@ public static AngleReduced<TUnits, T> GetReference<TUnits, T>(AngleReduced<TUnit
/// <returns>The quadrant of <paramref name="angle"/>.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Quadrant GetQuadrant<TUnits, T>(AngleReduced<TUnits, T> angle)
where TUnits : IAngleUnits<TUnits>
where TUnits : IAngleUnits
where T : struct, IFloatingPoint<T>, IMinMaxValue<T>
{
var value = angle.Value;
Expand Down Expand Up @@ -172,7 +172,7 @@ public static Quadrant GetQuadrant<TUnits, T>(AngleReduced<TUnits, T> angle)
/// </para>
/// </remarks>
public static Angle<TUnits, T> Abs<TUnits, T>(Angle<TUnits, T> angle)
where TUnits : IAngleUnits<TUnits>
where TUnits : IAngleUnits
where T : struct, IFloatingPoint<T>, IMinMaxValue<T>
=> T.Sign(angle.Value) >= 0
? angle
Expand All @@ -187,7 +187,7 @@ public static Angle<TUnits, T> Abs<TUnits, T>(Angle<TUnits, T> angle)
/// <returns>A number that indicates the sign of value, -1 if value is less than zero, 0 if value equal to zero, 1 if value is grater than zero.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int Sign<TUnits, T>(Angle<TUnits, T> angle)
where TUnits : IAngleUnits<TUnits>
where TUnits : IAngleUnits
where T : struct, IFloatingPoint<T>, IMinMaxValue<T>
=> T.Sign(angle.Value);

Expand Down Expand Up @@ -219,7 +219,7 @@ public static int Sign<TUnits, T>(Angle<TUnits, T> angle)
/// <returns>The result of the linear interpolation.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Angle<TUnits, T> Lerp<TUnits, T>(Angle<TUnits, T> a1, Angle<TUnits, T> a2, T t)
where TUnits : IAngleUnits<TUnits>
where TUnits : IAngleUnits
where T : struct, IFloatingPointIeee754<T>, IMinMaxValue<T>
#if NET8_0_OR_GREATER
=> new(T.Lerp(a1.Value, a2.Value, t));
Expand All @@ -237,7 +237,7 @@ public static Angle<TUnits, T> Lerp<TUnits, T>(Angle<TUnits, T> a1, Angle<TUnits
/// <returns>The smallest of the two angles.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Angle<TUnits, T> Min<TUnits, T>(Angle<TUnits, T> left, Angle<TUnits, T> right)
where TUnits : IAngleUnits<TUnits>
where TUnits : IAngleUnits
where T : struct, IFloatingPoint<T>, IMinMaxValue<T>
=> new(T.Min(left.Value, right.Value));

Expand All @@ -251,7 +251,7 @@ public static Angle<TUnits, T> Min<TUnits, T>(Angle<TUnits, T> left, Angle<TUnit
/// <returns>The largest of the two angles.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Angle<TUnits, T> Max<TUnits, T>(Angle<TUnits, T> left, Angle<TUnits, T> right)
where TUnits : IAngleUnits<TUnits>
where TUnits : IAngleUnits
where T : struct, IFloatingPoint<T>, IMinMaxValue<T>
=> new(T.Max(left.Value, right.Value));

Expand All @@ -266,7 +266,7 @@ public static Angle<TUnits, T> Max<TUnits, T>(Angle<TUnits, T> left, Angle<TUnit
/// <returns>true if the reduction of the absolute angle is zero; otherwise false.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool IsZero<TUnits, T>(Angle<TUnits, T> angle)
where TUnits : IAngleUnits<TUnits>
where TUnits : IAngleUnits
where T : struct, IFloatingPoint<T>, IMinMaxValue<T>
=> angle == Angle<TUnits, T>.Zero;

Expand All @@ -281,7 +281,7 @@ public static bool IsZero<TUnits, T>(Angle<TUnits, T> angle)
/// </returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool IsNaN<TUnits, T>(Angle<TUnits, T> angle)
where TUnits : IAngleUnits<TUnits>
where TUnits : IAngleUnits
where T : struct, IFloatingPoint<T>, IMinMaxValue<T>
=> T.IsNaN(angle.Value);

Expand All @@ -296,7 +296,7 @@ public static bool IsNaN<TUnits, T>(Angle<TUnits, T> angle)
/// </returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool IsInfinity<TUnits, T>(Angle<TUnits, T> angle)
where TUnits : IAngleUnits<TUnits>
where TUnits : IAngleUnits
where T : struct, IFloatingPoint<T>, IMinMaxValue<T>
=> T.IsInfinity(angle.Value);

Expand All @@ -311,7 +311,7 @@ public static bool IsInfinity<TUnits, T>(Angle<TUnits, T> angle)
/// </returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool IsFinite<TUnits, T>(Angle<TUnits, T> angle)
where TUnits : IAngleUnits<TUnits>
where TUnits : IAngleUnits
where T : struct, IFloatingPoint<T>, IMinMaxValue<T>
=> T.IsFinite(angle.Value);

Expand All @@ -330,7 +330,7 @@ public static bool IsFinite<TUnits, T>(Angle<TUnits, T> angle)
/// otherwise false.
/// </returns>
public static bool IsAcute<TUnits, T>(AngleReduced<TUnits, T> angle)
where TUnits : IAngleUnits<TUnits>
where TUnits : IAngleUnits
where T : struct, IFloatingPoint<T>, IMinMaxValue<T>
=> angle.Value > Angle<TUnits, T>.Zero.Value && angle.Value < Angle<TUnits, T>.Right.Value;

Expand All @@ -347,7 +347,7 @@ public static bool IsAcute<TUnits, T>(AngleReduced<TUnits, T> angle)
/// </remarks>
/// <returns>true if the reduction of the absolute angle is 90 degrees; otherwise false.</returns>
public static bool IsRight<TUnits, T>(AngleReduced<TUnits, T> angle)
where TUnits : IAngleUnits<TUnits>
where TUnits : IAngleUnits
where T : struct, IFloatingPoint<T>, IMinMaxValue<T>
=> angle.Value == Angle<TUnits, T>.Right.Value;

Expand All @@ -367,7 +367,7 @@ public static bool IsRight<TUnits, T>(AngleReduced<TUnits, T> angle)
/// 180 degrees; otherwise false.
/// </returns>
public static bool IsObtuse<TUnits, T>(AngleReduced<TUnits, T> angle)
where TUnits : IAngleUnits<TUnits>
where TUnits : IAngleUnits
where T : struct, IFloatingPoint<T>, IMinMaxValue<T>
=> angle.Value > Angle<TUnits, T>.Right.Value && angle.Value < Angle<TUnits, T>.Straight.Value;

Expand All @@ -384,7 +384,7 @@ public static bool IsObtuse<TUnits, T>(AngleReduced<TUnits, T> angle)
/// </remarks>
/// <returns>true if the reduction of the absolute angle is 180 degrees; otherwise false.</returns>
public static bool IsStraight<TUnits, T>(AngleReduced<TUnits, T> angle)
where TUnits : IAngleUnits<TUnits>
where TUnits : IAngleUnits
where T : struct, IFloatingPoint<T>, IMinMaxValue<T>
=> angle.Value == Angle<TUnits, T>.Straight.Value;

Expand All @@ -404,7 +404,7 @@ public static bool IsStraight<TUnits, T>(AngleReduced<TUnits, T> angle)
/// 360 degrees; otherwise false.
/// </returns>
public static bool IsReflex<TUnits, T>(AngleReduced<TUnits, T> angle)
where TUnits : IAngleUnits<TUnits>
where TUnits : IAngleUnits
where T : struct, IFloatingPoint<T>, IMinMaxValue<T>
=> angle.Value > Angle<TUnits, T>.Straight.Value;

Expand All @@ -421,7 +421,7 @@ public static bool IsReflex<TUnits, T>(AngleReduced<TUnits, T> angle)
/// </remarks>
/// <returns>true if the angle is not right or a multiple of a right angle; otherwise false.</returns>
public static bool IsOblique<TUnits, T>(AngleReduced<TUnits, T> angle)
where TUnits : IAngleUnits<TUnits>
where TUnits : IAngleUnits
where T : struct, IFloatingPoint<T>, IMinMaxValue<T>
=> angle.Value % Angle<TUnits, T>.Right.Value != T.Zero;

Expand All @@ -437,7 +437,7 @@ public static bool IsOblique<TUnits, T>(AngleReduced<TUnits, T> angle)
/// a right angle value to determine if they are complementary.
/// </remarks>
public static bool AreComplementary<TUnits, T>(AngleReduced<TUnits, T> first, AngleReduced<TUnits, T> second)
where TUnits : IAngleUnits<TUnits>
where TUnits : IAngleUnits
where T : struct, IFloatingPoint<T>, IMinMaxValue<T>
=> first.Value + second.Value == Angle<TUnits, T>.Right.Value;

Expand All @@ -453,7 +453,7 @@ public static bool AreComplementary<TUnits, T>(AngleReduced<TUnits, T> first, An
/// a straight angle value to determine if they are supplementary.
/// </remarks>
public static bool AreSupplementary<TUnits, T>(AngleReduced<TUnits, T> first, AngleReduced<TUnits, T> second)
where TUnits : IAngleUnits<TUnits>
where TUnits : IAngleUnits
where T : struct, IFloatingPoint<T>, IMinMaxValue<T>
=> first.Value + second.Value == Angle<TUnits, T>.Straight.Value;

Expand Down
Loading

0 comments on commit 686a3c9

Please sign in to comment.