a5/coordinate_systems/
base.rs1#[derive(Debug, PartialEq, Copy, Clone, Default)]
15pub struct Degrees(pub f64);
16
17impl Degrees {
18 pub const fn new_unchecked(value: f64) -> Self {
19 Degrees(value)
20 }
21
22 pub fn new(value: f64) -> Self {
24 Degrees(value)
25 }
26
27 pub const fn get(&self) -> f64 {
29 self.0
30 }
31
32 pub fn to_radians(self) -> Radians {
34 Radians::new_unchecked(self.0.to_radians())
35 }
36}
37
38impl From<f64> for Degrees {
39 fn from(value: f64) -> Self {
40 Self::new(value)
41 }
42}
43
44impl From<Degrees> for f64 {
45 fn from(degrees: Degrees) -> Self {
46 degrees.get()
47 }
48}
49
50#[derive(Debug, PartialEq, Copy, Clone, Default)]
55pub struct Radians(pub f64);
56
57impl Radians {
58 pub const fn new_unchecked(value: f64) -> Self {
59 Radians(value)
60 }
61
62 pub fn new(value: f64) -> Self {
64 use std::f64::consts::TAU; let normalized = value % TAU;
66 Radians(if normalized < 0.0 {
67 normalized + TAU
68 } else {
69 normalized
70 })
71 }
72
73 pub const fn get(&self) -> f64 {
75 self.0
76 }
77
78 pub fn to_degrees(self) -> Degrees {
80 Degrees::new_unchecked(self.0.to_degrees())
81 }
82}
83
84impl From<f64> for Radians {
85 fn from(value: f64) -> Self {
86 Self::new(value)
87 }
88}
89
90impl From<Radians> for f64 {
91 fn from(radians: Radians) -> Self {
92 radians.get()
93 }
94}