Add equivalence test for angles
This commit is contained in:
parent
3449fe8a73
commit
8a184c39b4
2 changed files with 25 additions and 2 deletions
|
@ -63,7 +63,7 @@ pub trait Angle
|
|||
S: Float
|
||||
>
|
||||
: Clone + Zero
|
||||
+ Eq + Ord
|
||||
+ Eq + Equiv<Self> + Ord
|
||||
+ ApproxEq<S>
|
||||
+ Neg<Self>
|
||||
+ ToRad<S>
|
||||
|
@ -144,6 +144,18 @@ impl<S: Float> Deg<S> {
|
|||
#[inline] pub fn turn_div_6() -> Deg<S> { Angle::turn_div_6() }
|
||||
}
|
||||
|
||||
impl<S: Float> Equiv<Rad<S>> for Rad<S> {
|
||||
fn equiv(&self, other: &Rad<S>) -> bool {
|
||||
self.normalize() == other.normalize()
|
||||
}
|
||||
}
|
||||
|
||||
impl<S: Float> Equiv<Deg<S>> for Deg<S> {
|
||||
fn equiv(&self, other: &Deg<S>) -> bool {
|
||||
self.normalize() == other.normalize()
|
||||
}
|
||||
}
|
||||
|
||||
impl<S: Float> Angle<S> for Rad<S> {
|
||||
#[inline] fn from<A: Angle<S>>(theta: A) -> Rad<S> { theta.to_rad() }
|
||||
#[inline] fn full_turn() -> Rad<S> { rad(Real::two_pi()) }
|
||||
|
|
|
@ -16,10 +16,21 @@
|
|||
use cgmath::angle::*;
|
||||
|
||||
#[test]
|
||||
fn angle_conv() {
|
||||
fn conv() {
|
||||
assert_approx_eq!(deg(-5.0).to_rad().to_deg(), deg(-5.0));
|
||||
assert_approx_eq!(deg(30.0).to_rad().to_deg(), deg(30.0));
|
||||
|
||||
assert_approx_eq!(rad(-5.0).to_deg().to_rad(), rad(-5.0));
|
||||
assert_approx_eq!(rad(30.0).to_deg().to_rad(), rad(30.0));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn equiv() {
|
||||
assert!(Deg::<f32>::full_turn().equiv(&-Deg::<f32>::full_turn()))
|
||||
assert!(Deg::<f32>::turn_div_2().equiv(&-Deg::<f32>::turn_div_2()))
|
||||
assert!(Deg::<f32>::turn_div_3().sub_a(Deg::<f32>::full_turn()).equiv(&Deg::<f32>::turn_div_3()))
|
||||
|
||||
assert!(Rad::<f32>::full_turn().equiv(&-Rad::<f32>::full_turn()))
|
||||
assert!(Rad::<f32>::turn_div_2().equiv(&-Rad::<f32>::turn_div_2()))
|
||||
assert!(Rad::<f32>::turn_div_3().sub_a(Rad::<f32>::full_turn()).equiv(&Rad::<f32>::turn_div_3()))
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue