From a9eacb2b9cd3d003b21ddc9c192ec414ac63afed Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tomas=20Wenstr=C3=B6m?= Date: Mon, 8 Feb 2021 19:53:46 +0100 Subject: [PATCH] Implemented PartialEq for Angle --- src/common/geometry.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) 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); -- 2.11.0