11use crate :: { Point , Rectangle , Vector } ;
22
33use std:: f32:: consts:: { FRAC_PI_2 , PI } ;
4- use std:: ops:: { Add , AddAssign , Div , Mul , RangeInclusive , Sub , SubAssign } ;
4+ use std:: ops:: { Add , AddAssign , Div , Mul , RangeInclusive , Rem , Sub , SubAssign } ;
55
66/// Degrees
77#[ derive( Debug , Copy , Clone , PartialEq , PartialOrd ) ]
88pub struct Degrees ( pub f32 ) ;
99
10+ impl Degrees {
11+ /// The range of degrees of a circle.
12+ pub const RANGE : RangeInclusive < Self > = Self ( 0.0 ) ..=Self ( 360.0 ) ;
13+ }
14+
1015impl PartialEq < f32 > for Degrees {
1116 fn eq ( & self , other : & f32 ) -> bool {
1217 self . 0 . eq ( other)
@@ -19,6 +24,52 @@ impl PartialOrd<f32> for Degrees {
1924 }
2025}
2126
27+ impl From < f32 > for Degrees {
28+ fn from ( degrees : f32 ) -> Self {
29+ Self ( degrees)
30+ }
31+ }
32+
33+ impl From < u8 > for Degrees {
34+ fn from ( degrees : u8 ) -> Self {
35+ Self ( f32:: from ( degrees) )
36+ }
37+ }
38+
39+ impl From < Degrees > for f32 {
40+ fn from ( degrees : Degrees ) -> Self {
41+ degrees. 0
42+ }
43+ }
44+
45+ impl From < Degrees > for f64 {
46+ fn from ( degrees : Degrees ) -> Self {
47+ Self :: from ( degrees. 0 )
48+ }
49+ }
50+
51+ impl Mul < f32 > for Degrees {
52+ type Output = Degrees ;
53+
54+ fn mul ( self , rhs : f32 ) -> Self :: Output {
55+ Self ( self . 0 * rhs)
56+ }
57+ }
58+
59+ impl num_traits:: FromPrimitive for Degrees {
60+ fn from_i64 ( n : i64 ) -> Option < Self > {
61+ Some ( Self ( n as f32 ) )
62+ }
63+
64+ fn from_u64 ( n : u64 ) -> Option < Self > {
65+ Some ( Self ( n as f32 ) )
66+ }
67+
68+ fn from_f64 ( n : f64 ) -> Option < Self > {
69+ Some ( Self ( n as f32 ) )
70+ }
71+ }
72+
2273/// Radians
2374#[ derive( Debug , Copy , Clone , PartialEq , PartialOrd ) ]
2475pub struct Radians ( pub f32 ) ;
@@ -65,6 +116,12 @@ impl From<u8> for Radians {
65116 }
66117}
67118
119+ impl From < Radians > for f32 {
120+ fn from ( radians : Radians ) -> Self {
121+ radians. 0
122+ }
123+ }
124+
68125impl From < Radians > for f64 {
69126 fn from ( radians : Radians ) -> Self {
70127 Self :: from ( radians. 0 )
@@ -107,6 +164,14 @@ impl Add for Radians {
107164 }
108165}
109166
167+ impl Add < Degrees > for Radians {
168+ type Output = Self ;
169+
170+ fn add ( self , rhs : Degrees ) -> Self :: Output {
171+ Self ( self . 0 + rhs. 0 . to_radians ( ) )
172+ }
173+ }
174+
110175impl AddAssign for Radians {
111176 fn add_assign ( & mut self , rhs : Radians ) {
112177 self . 0 = self . 0 + rhs. 0 ;
@@ -153,6 +218,14 @@ impl Div for Radians {
153218 }
154219}
155220
221+ impl Rem for Radians {
222+ type Output = Self ;
223+
224+ fn rem ( self , rhs : Self ) -> Self :: Output {
225+ Self ( self . 0 % rhs. 0 )
226+ }
227+ }
228+
156229impl PartialEq < f32 > for Radians {
157230 fn eq ( & self , other : & f32 ) -> bool {
158231 self . 0 . eq ( other)
0 commit comments