diff --git a/src/NetFabric.Numerics/IGeometricBase.cs b/src/NetFabric.Numerics/IGeometricBase.cs index 1fed53d..33c9082 100644 --- a/src/NetFabric.Numerics/IGeometricBase.cs +++ b/src/NetFabric.Numerics/IGeometricBase.cs @@ -3,17 +3,19 @@ /// /// Represents a geometric type. /// -/// The type that implements the interface. -public interface IGeometricBase +/// The type implementing the interface. +/// The type representing the coordinate system. +public interface IGeometricBase : IEquatable, IEqualityOperators - where TSelf : struct, IGeometricBase? + where TSelf : struct, IGeometricBase? + where TCoordinateSystem : ICoordinateSystem { /// - /// Gets a coordinate system of the point. + /// Gets the coordinate system of the point. /// /// The coordinate system of the point. - ICoordinateSystem CoordinateSystem { get; } + TCoordinateSystem CoordinateSystem { get; } /// /// Gets the value for a given coordinate of the point. @@ -30,11 +32,13 @@ public interface IGeometricBase /// object this[int index] { get; } - /// Gets the value 0 for the type. + /// + /// Gets the zero value for the type. + /// static abstract TSelf Zero { get; } /// - /// Determines whether is zero. + /// Determines whether a value is zero. /// /// The value to check. /// true if the value is a zero vector; otherwise, false. @@ -42,3 +46,4 @@ public interface IGeometricBase public static bool IsZero(TSelf value) => value.Equals(TSelf.Zero); } + diff --git a/src/NetFabric.Numerics/IMatrix.cs b/src/NetFabric.Numerics/IMatrix.cs index 036d9a8..58da40e 100644 --- a/src/NetFabric.Numerics/IMatrix.cs +++ b/src/NetFabric.Numerics/IMatrix.cs @@ -6,8 +6,7 @@ /// The type that implements the interface. /// The type of the matrix elements. public interface IMatrix - : IGeometricBase, - IAdditiveIdentity, + : IAdditiveIdentity, IUnaryPlusOperators, IAdditionOperators, IUnaryNegationOperators, diff --git a/src/NetFabric.Numerics/IPoint.cs b/src/NetFabric.Numerics/IPoint.cs index 1c4a4e6..d5cc7b1 100644 --- a/src/NetFabric.Numerics/IPoint.cs +++ b/src/NetFabric.Numerics/IPoint.cs @@ -3,9 +3,12 @@ namespace NetFabric.Numerics; /// /// Represents a point in a coordinate system. /// -public interface IPoint - : IGeometricBase, +/// The type implementing the interface. +/// The type representing the coordinate system. +public interface IPoint + : IGeometricBase, IMinMaxValue - where TSelf : struct, IPoint? + where TSelf : struct, IPoint? + where TCoordinateSystem : ICoordinateSystem { } \ No newline at end of file diff --git a/src/NetFabric.Numerics/IVector.cs b/src/NetFabric.Numerics/IVector.cs index 7245670..6dcec76 100644 --- a/src/NetFabric.Numerics/IVector.cs +++ b/src/NetFabric.Numerics/IVector.cs @@ -3,10 +3,11 @@ namespace NetFabric.Numerics; /// /// Represents a vector in a coordinate system. /// -/// The type that implements the interface. +/// The type implementing the interface. +/// The type representing the coordinate system. /// The type of the vector coordinates. -public interface IVector - : IGeometricBase, +public interface IVector + : IGeometricBase, IComparable, IComparable, IComparisonOperators, @@ -18,7 +19,8 @@ public interface IVector IMultiplyOperators, IDivisionOperators, IMinMaxValue - where TSelf : struct, IVector? + where TSelf : struct, IVector? + where TCoordinateSystem : ICoordinateSystem where T : struct, INumber, IMinMaxValue { } \ No newline at end of file diff --git a/src/NetFabric.Numerics/Polar/Point.cs b/src/NetFabric.Numerics/Polar/Point.cs index db58aeb..f0d609e 100644 --- a/src/NetFabric.Numerics/Polar/Point.cs +++ b/src/NetFabric.Numerics/Polar/Point.cs @@ -13,7 +13,7 @@ namespace NetFabric.Numerics.Polar; [System.Diagnostics.DebuggerDisplay("Radius = {Radius}, Azimuth = {Azimuth}")] [SkipLocalsInit] public readonly struct Point - : IPoint> + : IPoint, CoordinateSystem> where TAngleUnits : struct, IAngleUnits where T : struct, IFloatingPoint, IMinMaxValue { @@ -54,7 +54,7 @@ public Point(T radius, Angle azimuth) /// public static readonly PointReduced Zero = new(T.Zero, Angle.Zero); - static Point IGeometricBase>.Zero + static Point IGeometricBase, CoordinateSystem>.Zero => Zero; /// @@ -79,8 +79,6 @@ static Point IMinMaxValue>.MaxValue /// public CoordinateSystem CoordinateSystem => new(); - ICoordinateSystem IGeometricBase>.CoordinateSystem - => CoordinateSystem; /// /// Creates an instance of the current type from a value, @@ -127,7 +125,7 @@ public static Point CreateTruncating(in Point.CreateTruncating(point.Azimuth)); - object IGeometricBase>.this[int index] + object IGeometricBase, CoordinateSystem>.this[int index] => index switch { 0 => Radius, diff --git a/src/NetFabric.Numerics/Polar/PointReduced.cs b/src/NetFabric.Numerics/Polar/PointReduced.cs index f01f409..d32d9ff 100644 --- a/src/NetFabric.Numerics/Polar/PointReduced.cs +++ b/src/NetFabric.Numerics/Polar/PointReduced.cs @@ -15,7 +15,7 @@ namespace NetFabric.Numerics.Polar; [System.Diagnostics.DebuggerDisplay("Radius = {Radius}, Azimuth = {Azimuth}")] [SkipLocalsInit] public readonly record struct PointReduced(T Radius, AngleReduced Azimuth) - : IPoint> + : IPoint, CoordinateSystem> where TAngleUnits : struct, IAngleUnits where T : struct, IFloatingPoint, IMinMaxValue { @@ -26,7 +26,7 @@ public readonly record struct PointReduced(T Radius, AngleReduce /// public static readonly PointReduced Zero = new(T.Zero, Angle.Zero); - static PointReduced IGeometricBase>.Zero + static PointReduced IGeometricBase, CoordinateSystem>.Zero => Zero; /// @@ -51,8 +51,6 @@ static PointReduced IMinMaxValue>.M /// public CoordinateSystem CoordinateSystem => new(); - ICoordinateSystem IGeometricBase>.CoordinateSystem - => CoordinateSystem; /// /// Creates an instance of the current type from a value, @@ -107,7 +105,7 @@ public static PointReduced CreateTruncating(in PointRedu public static implicit operator Point(PointReduced angle) => new(angle.Radius, angle.Azimuth); - object IGeometricBase>.this[int index] + object IGeometricBase, CoordinateSystem>.this[int index] => index switch { 0 => Radius, diff --git a/src/NetFabric.Numerics/Polar/Vector.cs b/src/NetFabric.Numerics/Polar/Vector.cs index 8ac17a5..4860063 100644 --- a/src/NetFabric.Numerics/Polar/Vector.cs +++ b/src/NetFabric.Numerics/Polar/Vector.cs @@ -18,7 +18,7 @@ namespace NetFabric.Numerics.Polar; [System.Diagnostics.DebuggerDisplay("Radius = {Radius}, Azimuth = {Azimuth}")] [SkipLocalsInit] public readonly record struct Vector(T Radius, Angle Azimuth) - : IVector, T> + : IVector, CoordinateSystem, T> where TAngleUnits : struct, IAngleUnits where T : struct, IFloatingPoint, IMinMaxValue { @@ -30,7 +30,7 @@ public readonly record struct Vector(T Radius, Angle public static readonly Vector Zero = new(T.Zero, Angle.Zero); - static Vector IGeometricBase>.Zero + static Vector IGeometricBase, CoordinateSystem>.Zero => Zero; static Vector IAdditiveIdentity, Vector>.AdditiveIdentity @@ -58,8 +58,6 @@ static Vector IMinMaxValue>.MaxValue /// public CoordinateSystem CoordinateSystem => new(); - ICoordinateSystem IGeometricBase>.CoordinateSystem - => CoordinateSystem; /// /// Creates an instance of the current type from a value, @@ -106,7 +104,7 @@ public static Vector CreateTruncating(in Vector.CreateTruncating(vector.Azimuth)); - object IGeometricBase>.this[int index] + object IGeometricBase, CoordinateSystem>.this[int index] => index switch { 0 => Radius, diff --git a/src/NetFabric.Numerics/Rectangular2D/Point.cs b/src/NetFabric.Numerics/Rectangular2D/Point.cs index 129afc4..7927175 100644 --- a/src/NetFabric.Numerics/Rectangular2D/Point.cs +++ b/src/NetFabric.Numerics/Rectangular2D/Point.cs @@ -13,14 +13,14 @@ namespace NetFabric.Numerics.Rectangular2D; [System.Diagnostics.DebuggerDisplay("X = {X}, Y = {Y}")] [SkipLocalsInit] public readonly record struct Point(T X, T Y) - : IPoint> + : IPoint, CoordinateSystem> where T: struct, INumber, IMinMaxValue { #region constants public static readonly Point Zero = new(T.Zero, T.Zero); - static Point IGeometricBase>.Zero + static Point IGeometricBase, CoordinateSystem>.Zero => Zero; /// @@ -45,8 +45,6 @@ static Point IMinMaxValue>.MaxValue /// public CoordinateSystem CoordinateSystem => new(); - ICoordinateSystem IGeometricBase>.CoordinateSystem - => CoordinateSystem; /// /// Creates an instance of the current type from a value, @@ -116,7 +114,7 @@ public static Point CreateTruncating(in Point point) #endregion - object IGeometricBase>.this[int index] + object IGeometricBase, CoordinateSystem>.this[int index] => index switch { 0 => X, diff --git a/src/NetFabric.Numerics/Rectangular2D/Vector.cs b/src/NetFabric.Numerics/Rectangular2D/Vector.cs index c90826c..cc9f0b8 100644 --- a/src/NetFabric.Numerics/Rectangular2D/Vector.cs +++ b/src/NetFabric.Numerics/Rectangular2D/Vector.cs @@ -17,7 +17,7 @@ namespace NetFabric.Numerics.Rectangular2D; [System.Diagnostics.DebuggerDisplay("X = {X}, Y = {Y}")] [SkipLocalsInit] public readonly record struct Vector(T X, T Y) - : IVector, T> + : IVector, CoordinateSystem, T> where T : struct, INumber, IMinMaxValue { @@ -28,7 +28,7 @@ public readonly record struct Vector(T X, T Y) /// public static readonly Vector Zero = new(T.Zero, T.Zero); - static Vector IGeometricBase>.Zero + static Vector IGeometricBase, CoordinateSystem>.Zero => Zero; static Vector IAdditiveIdentity, Vector>.AdditiveIdentity @@ -66,8 +66,6 @@ static Vector IMinMaxValue>.MaxValue /// public CoordinateSystem CoordinateSystem => new(); - ICoordinateSystem IGeometricBase>.CoordinateSystem - => CoordinateSystem; /// /// Creates an instance of the current type from a value, @@ -117,7 +115,7 @@ public static Vector CreateTruncating(in Vector vector) T.CreateTruncating(vector.Y) ); - object IGeometricBase>.this[int index] + object IGeometricBase, CoordinateSystem>.this[int index] => index switch { 0 => X, diff --git a/src/NetFabric.Numerics/Rectangular3D/Point.cs b/src/NetFabric.Numerics/Rectangular3D/Point.cs index 2accde9..a14e38e 100644 --- a/src/NetFabric.Numerics/Rectangular3D/Point.cs +++ b/src/NetFabric.Numerics/Rectangular3D/Point.cs @@ -15,14 +15,14 @@ namespace NetFabric.Numerics.Rectangular3D; [System.Diagnostics.DebuggerDisplay("X = {X}, Y = {Y}, Z = {Z}")] [SkipLocalsInit] public readonly record struct Point(T X, T Y, T Z) - : IPoint> + : IPoint, CoordinateSystem> where T: struct, INumber, IMinMaxValue { #region constants public static readonly Point Zero = new(T.Zero, T.Zero, T.Zero); - static Point IGeometricBase>.Zero + static Point IGeometricBase, CoordinateSystem>.Zero => Zero; /// @@ -47,8 +47,6 @@ static Point IMinMaxValue>.MaxValue /// public CoordinateSystem CoordinateSystem => new(); - ICoordinateSystem IGeometricBase>.CoordinateSystem - => CoordinateSystem; /// /// Creates an instance of the current type from a value, @@ -121,7 +119,7 @@ public static Point CreateTruncating(in Point point) #endregion - object IGeometricBase>.this[int index] + object IGeometricBase, CoordinateSystem>.this[int index] => index switch { 0 => X, diff --git a/src/NetFabric.Numerics/Rectangular3D/Vector.cs b/src/NetFabric.Numerics/Rectangular3D/Vector.cs index 08dded5..e93ea60 100644 --- a/src/NetFabric.Numerics/Rectangular3D/Vector.cs +++ b/src/NetFabric.Numerics/Rectangular3D/Vector.cs @@ -18,7 +18,7 @@ namespace NetFabric.Numerics.Rectangular3D; [System.Diagnostics.DebuggerDisplay("X = {X}, Y = {Y}, Z = {Z}")] [SkipLocalsInit] public readonly record struct Vector(T X, T Y, T Z) - : IVector, T> + : IVector, CoordinateSystem, T> where T : struct, INumber, IMinMaxValue { @@ -29,7 +29,7 @@ public readonly record struct Vector(T X, T Y, T Z) /// public static readonly Vector Zero = new(T.Zero, T.Zero, T.Zero); - static Vector IGeometricBase>.Zero + static Vector IGeometricBase, CoordinateSystem>.Zero => Zero; static Vector IAdditiveIdentity, Vector>.AdditiveIdentity @@ -72,8 +72,6 @@ static Vector IMinMaxValue>.MaxValue /// public CoordinateSystem CoordinateSystem => new(); - ICoordinateSystem IGeometricBase>.CoordinateSystem - => CoordinateSystem; /// /// Creates an instance of the current type from a value, @@ -126,7 +124,7 @@ public static Vector CreateTruncating(in Vector vector) T.CreateTruncating(vector.Z) ); - object IGeometricBase>.this[int index] + object IGeometricBase, CoordinateSystem>.this[int index] => index switch { 0 => X, diff --git a/src/NetFabric.Numerics/Spherical/Point.cs b/src/NetFabric.Numerics/Spherical/Point.cs index bdc0a7e..948be1a 100644 --- a/src/NetFabric.Numerics/Spherical/Point.cs +++ b/src/NetFabric.Numerics/Spherical/Point.cs @@ -14,7 +14,7 @@ namespace NetFabric.Numerics.Spherical; [System.Diagnostics.DebuggerDisplay("Radius = {Radius}, Azimuth = {Azimuth}, Polar = {Polar}")] [SkipLocalsInit] public readonly struct Point - : IPoint> + : IPoint, CoordinateSystem> where TAngleUnits : struct, IAngleUnits where T : struct, IFloatingPoint, IMinMaxValue { @@ -62,7 +62,7 @@ public Point(T radius, Angle azimuth, Angle pola public static readonly PointReduced Zero = new(T.Zero, Angle.Zero, Angle.Zero); - static Point IGeometricBase>.Zero + static Point IGeometricBase, CoordinateSystem>.Zero => Zero; /// @@ -87,8 +87,6 @@ static Point IMinMaxValue>.MaxValue /// public CoordinateSystem CoordinateSystem => new(); - ICoordinateSystem IGeometricBase>.CoordinateSystem - => CoordinateSystem; /// /// Creates an instance of the current type from a value, @@ -138,7 +136,7 @@ public static Point CreateTruncating(in Point.CreateTruncating(point.Azimuth), Angle.CreateTruncating(point.Polar)); - object IGeometricBase>.this[int index] + object IGeometricBase, CoordinateSystem>.this[int index] => index switch { 0 => Radius, diff --git a/src/NetFabric.Numerics/Spherical/PointReduced.cs b/src/NetFabric.Numerics/Spherical/PointReduced.cs index a0ee1d2..cf29171 100644 --- a/src/NetFabric.Numerics/Spherical/PointReduced.cs +++ b/src/NetFabric.Numerics/Spherical/PointReduced.cs @@ -17,7 +17,7 @@ namespace NetFabric.Numerics.Spherical; [System.Diagnostics.DebuggerDisplay("Radius = {Radius}, Azimuth = {Azimuth}, Polar = {Polar}")] [SkipLocalsInit] public readonly record struct PointReduced(T Radius, AngleReduced Azimuth, AngleReduced Polar) - : IPoint> + : IPoint, CoordinateSystem> where TAngleUnits : struct, IAngleUnits where T : struct, IFloatingPoint, IMinMaxValue { @@ -33,7 +33,7 @@ public readonly record struct PointReduced(T Radius, AngleReduce /// public static readonly PointReduced Zero = new(T.Zero, Angle.Zero, Angle.Zero); - static PointReduced IGeometricBase>.Zero + static PointReduced IGeometricBase, CoordinateSystem>.Zero => Zero; /// @@ -58,8 +58,6 @@ static PointReduced IMinMaxValue>.M /// public CoordinateSystem CoordinateSystem => new(); - ICoordinateSystem IGeometricBase>.CoordinateSystem - => CoordinateSystem; /// /// Creates an instance of the current type from a value, @@ -117,7 +115,7 @@ public static PointReduced CreateTruncating(in PointRedu public static implicit operator Point(PointReduced angle) => new(angle.Radius, angle.Azimuth, angle.Polar); - object IGeometricBase>.this[int index] + object IGeometricBase, CoordinateSystem>.this[int index] => index switch { 0 => Radius, diff --git a/src/NetFabric.Numerics/Spherical/Vector.cs b/src/NetFabric.Numerics/Spherical/Vector.cs index 04634e4..9c6dfd0 100644 --- a/src/NetFabric.Numerics/Spherical/Vector.cs +++ b/src/NetFabric.Numerics/Spherical/Vector.cs @@ -20,7 +20,7 @@ namespace NetFabric.Numerics.Spherical; [System.Diagnostics.DebuggerDisplay("Radius = {Radius}, Azimuth = {Azimuth}, Polar = {Polar}")] [SkipLocalsInit] public readonly record struct Vector(T Radius, Angle Azimuth, Angle Polar) - : IVector, T> + : IVector, CoordinateSystem, T> where TAngleUnits : struct, IAngleUnits where T : struct, IFloatingPoint, IMinMaxValue { @@ -32,7 +32,7 @@ public readonly record struct Vector(T Radius, Angle public static readonly Vector Zero = new(T.Zero, Angle.Zero, Angle.Zero); - static Vector IGeometricBase>.Zero + static Vector IGeometricBase, CoordinateSystem>.Zero => Zero; static Vector IAdditiveIdentity, Vector>.AdditiveIdentity @@ -60,8 +60,6 @@ static Vector IMinMaxValue>.MaxValue /// public CoordinateSystem CoordinateSystem => new(); - ICoordinateSystem IGeometricBase>.CoordinateSystem - => CoordinateSystem; /// /// Creates an instance of the current type from a value, @@ -111,7 +109,7 @@ public static Vector CreateTruncating(in Vector.CreateTruncating(vector.Azimuth), Angle.CreateTruncating(vector.Polar)); - object IGeometricBase>.this[int index] + object IGeometricBase, CoordinateSystem>.this[int index] => index switch { 0 => Radius,