22
33namespace Pinta . Core ;
44
5- public readonly struct RadiansAngle
5+ public interface IAngle < TAngle > where TAngle : IAngle < TAngle >
66{
7- public const double MAX_RADIANS = Math . PI * 2 ;
7+ static abstract double FullTurn { get ; }
8+ static abstract bool operator == ( TAngle a , TAngle b ) ;
9+ static abstract bool operator != ( TAngle a , TAngle b ) ;
10+ static abstract TAngle operator + ( TAngle a , TAngle b ) ;
11+ static abstract TAngle operator - ( TAngle a , TAngle b ) ;
12+ }
13+
14+ public readonly struct RadiansAngle : IAngle < RadiansAngle >
15+ {
16+ public static double FullTurn => Math . PI * 2 ;
17+
18+ /// <remarks>The value can only be in the range [0, <see cref="FullTurn" />)</remarks>
819 public readonly double Radians { get ; }
920
21+ /// <remarks>
22+ /// <paramref name="radians"/> is wrapped around to be within the allowable
23+ /// range of the <see cref="Radians"/> property
24+ /// </remarks>
1025 public RadiansAngle ( double radians )
1126 {
1227 Radians = radians switch {
1328 0 => 0 ,
14- >= 0 => radians % MAX_RADIANS ,
15- _ => ( MAX_RADIANS + ( radians % MAX_RADIANS ) ) % MAX_RADIANS
29+ >= 0 => radians % FullTurn ,
30+ _ => ( FullTurn + ( radians % FullTurn ) ) % FullTurn
1631 } ;
1732 }
1833
@@ -26,8 +41,6 @@ public RadiansAngle (double radians)
2641 public static RadiansAngle operator - ( RadiansAngle a , RadiansAngle b ) => new ( a . Radians - b . Radians ) ;
2742 public static bool operator == ( RadiansAngle a , RadiansAngle b ) => a . Equals ( b ) ;
2843 public static bool operator != ( RadiansAngle a , RadiansAngle b ) => ! a . Equals ( b ) ;
29- public static bool operator > ( RadiansAngle a , RadiansAngle b ) => a . Radians > b . Radians ;
30- public static bool operator < ( RadiansAngle a , RadiansAngle b ) => a . Radians < b . Radians ;
3144 public override readonly int GetHashCode ( ) => Radians . GetHashCode ( ) ;
3245 public override readonly bool Equals ( object ? obj )
3346 {
@@ -36,17 +49,24 @@ public override readonly bool Equals (object? obj)
3649 }
3750}
3851
39- public readonly struct DegreesAngle
52+ public readonly struct DegreesAngle : IAngle < DegreesAngle >
4053{
41- public const double MAX_DEGREES = 360 ;
54+ public static double FullTurn => 360 ;
55+
56+
57+ /// <remarks>The value can only be in the range [0, <see cref="FullTurn" />)</remarks>
4258 public readonly double Degrees { get ; }
4359
60+ /// <remarks>
61+ /// <paramref name="degrees"/> is wrapped around to be within the allowable
62+ /// range of the <see cref="Degrees"/> property
63+ /// </remarks>
4464 public DegreesAngle ( double degrees )
4565 {
4666 Degrees = degrees switch {
4767 0 => 0 ,
48- >= 0 => degrees % MAX_DEGREES ,
49- _ => ( MAX_DEGREES + ( degrees % MAX_DEGREES ) ) % MAX_DEGREES
68+ >= 0 => degrees % FullTurn ,
69+ _ => ( FullTurn + ( degrees % FullTurn ) ) % FullTurn
5070 } ;
5171 }
5272
@@ -60,8 +80,6 @@ public DegreesAngle (double degrees)
6080 public static DegreesAngle operator - ( DegreesAngle a , DegreesAngle b ) => new ( a . Degrees - b . Degrees ) ;
6181 public static bool operator == ( DegreesAngle a , DegreesAngle b ) => a . Equals ( b ) ;
6282 public static bool operator != ( DegreesAngle a , DegreesAngle b ) => ! a . Equals ( b ) ;
63- public static bool operator > ( DegreesAngle a , DegreesAngle b ) => a . Degrees > b . Degrees ;
64- public static bool operator < ( DegreesAngle a , DegreesAngle b ) => a . Degrees < b . Degrees ;
6583 public override readonly int GetHashCode ( ) => Degrees . GetHashCode ( ) ;
6684 public override readonly bool Equals ( object ? obj )
6785 {
@@ -70,17 +88,23 @@ public override readonly bool Equals (object? obj)
7088 }
7189}
7290
73- public readonly struct RevolutionsAngle
91+ public readonly struct RevolutionsAngle : IAngle < RevolutionsAngle >
7492{
75- public const double MAX_REVOLUTIONS = 1 ;
93+ public static double FullTurn => 1 ;
94+
95+ /// <remarks>The value can only be in the range [0, <see cref="FullTurn" />)</remarks>
7696 public readonly double Revolutions { get ; }
7797
98+ /// <remarks>
99+ /// <paramref name="revolutions"/> is wrapped around to be within the allowable
100+ /// range of the <see cref="Revolutions"/> property
101+ /// </remarks>
78102 public RevolutionsAngle ( double revolutions )
79103 {
80104 Revolutions = revolutions switch {
81105 0 => 0 ,
82- >= 0 => revolutions % MAX_REVOLUTIONS ,
83- _ => ( MAX_REVOLUTIONS + ( revolutions % MAX_REVOLUTIONS ) ) % MAX_REVOLUTIONS
106+ >= 0 => revolutions % FullTurn ,
107+ _ => ( FullTurn + ( revolutions % FullTurn ) ) % FullTurn
84108 } ;
85109 }
86110
@@ -94,8 +118,6 @@ public RevolutionsAngle (double revolutions)
94118 public static RevolutionsAngle operator - ( RevolutionsAngle a , RevolutionsAngle b ) => new ( a . Revolutions - b . Revolutions ) ;
95119 public static bool operator == ( RevolutionsAngle a , RevolutionsAngle b ) => a . Revolutions == b . Revolutions ;
96120 public static bool operator != ( RevolutionsAngle a , RevolutionsAngle b ) => a . Revolutions != b . Revolutions ;
97- public static bool operator > ( RevolutionsAngle a , RevolutionsAngle b ) => a . Revolutions > b . Revolutions ;
98- public static bool operator < ( RevolutionsAngle a , RevolutionsAngle b ) => a . Revolutions < b . Revolutions ;
99121 public override readonly int GetHashCode ( ) => Revolutions . GetHashCode ( ) ;
100122 public override readonly bool Equals ( object ? obj )
101123 {
0 commit comments