1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
use std::f64::consts::PI;
use std::ops::{Add, Mul, Sub};
#[derive(Clone, Copy, Debug, Default, PartialEq)]
pub struct Radians<T>(pub T);
impl Radians<f64> {
pub fn from_degrees(degrees: f64) -> Radians<f64> {
Radians(degrees * PI / 180.0)
}
pub fn to_degrees(self) -> f64 {
self.0 * 180.0 / PI
}
}
impl Add for Radians<f64> {
type Output = Radians<f64>;
fn add(self, other: Radians<f64>) -> Radians<f64> {
Radians(self.0 + other.0)
}
}
impl Sub for Radians<f64> {
type Output = Radians<f64>;
fn sub(self, other: Radians<f64>) -> Radians<f64> {
Radians(self.0 - other.0)
}
}
impl Mul<Radians<f64>> for f64 {
type Output = Radians<f64>;
fn mul(self, other: Radians<f64>) -> Radians<f64> {
Radians(self * other.0)
}
}