Only collide with walls from the front
[kaka/rust-sdl-test.git] / src / geometry.rs
index 540db53..7ddc3ec 100644 (file)
@@ -38,6 +38,10 @@ impl Point<f64> {
            y: self.y as i32,
        }
     }
+
+    pub fn cross_product(&self, p: Self) -> f64 {
+        return self.x * p.y - self.y * p.x;
+    }
 }
 
 macro_rules! impl_point_op {
@@ -330,10 +334,7 @@ impl<T> From<Dimension<T>> for (T, T) {
 pub fn supercover_line_int(p1: Point<isize>, p2: Point<isize>) -> Vec<Point<isize>> {
     let d = p2 - p1;
     let n = point!(d.x.abs(), d.y.abs());
-    let step = point!(
-       if d.x > 0 { 1 } else { -1 },
-       if d.y > 0 { 1 } else { -1 }
-    );
+    let step = point!(d.x.signum(), d.y.signum());
 
     let mut p = p1;
     let mut points = vec!(point!(p.x as isize, p.y as isize));