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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
quantity! {
quantity: Angle; "angle";
dimension: ISQ<
Z0,
Z0,
Z0,
Z0,
Z0,
Z0,
Z0>;
kind: ::si::marker::AngleKind;
units {
@radian: 1.0_E0; "rad", "radian", "radians";
@revolution: 6.283_185_307_179_586_E0; "r", "revolution", "revolutions";
@degree: 1.745_329_251_994_329_5_E-2; "°", "degree", "degrees";
@gon: 1.570_796_326_794_896_7_E-2; "gon", "gon", "gons";
@mil: 9.817_477_E-4; "mil", "mil", "mils";
@minute: 2.908_882_086_657_216_E-4; "′", "minute", "minutes";
@second: 4.848_136_811_095_36_E-6; "″", "second", "seconds";
}
}
mod convert {
use super::*;
impl<U, V> ::lib::convert::From<V> for Angle<U, V>
where
U: ::si::Units<V> + ?Sized,
V: ::num::Num + ::Conversion<V>,
{
fn from(t: V) -> Self {
Angle {
dimension: ::lib::marker::PhantomData,
units: ::lib::marker::PhantomData,
value: t,
}
}
}
storage_types! {
use super::*;
impl<U> ::lib::convert::From<Angle<U, V>> for V
where
U: ::si::Units<V> + ?Sized,
V: ::num::Num + ::Conversion<V>,
{
fn from(t: Angle<U, V>) -> Self {
t.value
}
}
}
}
#[cfg(test)]
mod tests {
storage_types! {
use ::lib::f64::consts::PI;
use num::{FromPrimitive, One};
use si::angle as a;
use si::quantities::*;
use tests::Test;
#[test]
fn from() {
let r1: Angle<V> = Angle::<V>::from(V::one());
let r2: Angle<V> = V::one().into();
let _: V = V::from(r1);
let _: V = r2.into();
}
#[test]
fn check_units() {
Test::assert_eq(&Angle::new::<a::radian>(V::from_f64(2.0 * PI).unwrap()),
&Angle::new::<a::revolution>(V::one()));
Test::assert_eq(&Angle::new::<a::degree>(V::from_f64(360.0).unwrap()),
&Angle::new::<a::revolution>(V::one()));
Test::assert_approx_eq(&Angle::new::<a::gon>(V::from_f64(400.0).unwrap()),
&Angle::new::<a::revolution>(V::one()));
Test::assert_eq(&Angle::new::<a::minute>(V::from_f64(60.0).unwrap()),
&Angle::new::<a::degree>(V::one()));
Test::assert_eq(&Angle::new::<a::second>(V::from_f64(60.0 * 60.0).unwrap()),
&Angle::new::<a::degree>(V::one()));
}
}
}