Fixed a bunch of clippy suggestions
[kaka/rust-sdl-test.git] / src / common / geometry.rs
index d767d8e..540db53 100644 (file)
@@ -154,7 +154,7 @@ impl From<Angle> for Point<f64> {
 
 ////////// 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
 
@@ -274,7 +278,7 @@ impl Intersection {
            let s = (-s1.y * (p1.x - p3.x) + s1.x * (p1.y - p3.y)) / denomimator;
            let t = ( s2.x * (p1.y - p3.y) - s2.y * (p1.x - p3.x)) / denomimator;
 
-           if s >= 0.0 && s <= 1.0 && t >= 0.0 && t <= 1.0 {
+           if (0.0..=1.0).contains(&s) && (0.0..=1.0).contains(&t) {
                return Intersection::Point(p1 + (s1 * t))
            }
        }
@@ -331,7 +335,7 @@ pub fn supercover_line_int(p1: Point<isize>, p2: Point<isize>) -> Vec<Point<isiz
        if d.y > 0 { 1 } else { -1 }
     );
 
-    let mut p = p1.clone();
+    let mut p = p1;
     let mut points = vec!(point!(p.x as isize, p.y as isize));
     let mut i = point!(0, 0);
     while i.x < n.x || i.y < n.y {
@@ -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);