From: Tomas Wenström Date: Mon, 8 Feb 2021 18:53:46 +0000 (+0100) Subject: Implemented PartialEq for Angle X-Git-Url: http://git.dolda2000.com/gitweb/?a=commitdiff_plain;h=a9eacb2b9cd3d003b21ddc9c192ec414ac63afed;p=kaka%2Frust-sdl-test.git Implemented PartialEq for Angle --- diff --git a/src/common/geometry.rs b/src/common/geometry.rs index d767d8e..50d1994 100644 --- a/src/common/geometry.rs +++ b/src/common/geometry.rs @@ -154,7 +154,7 @@ impl From for Point { ////////// ANGLE /////////////////////////////////////////////////////////////// -#[derive(Debug, Default, PartialEq, Clone, Copy)] +#[derive(Debug, Default, Clone, Copy)] pub struct Angle(pub f64); pub trait ToAngle { @@ -223,7 +223,11 @@ impl Angle { } } -// TODO override eq, 0==360 osv +impl PartialEq for Angle { + fn eq(&self, rhs: &Angle) -> bool { + self.0 % std::f64::consts::TAU == rhs.0 % std::f64::consts::TAU + } +} // addition and subtraction of angles @@ -468,6 +472,7 @@ mod tests { #[test] fn angles() { assert_eq!(0.radians(), 0.degrees()); + assert_eq!(0.degrees(), 360.degrees()); assert_eq!(180.degrees(), std::f64::consts::PI.radians()); assert_eq!(std::f64::consts::PI.radians().to_degrees(), 180.0); assert!((Point::from(90.degrees()) - point!(0.0, 1.0)).length() < 0.001);