Refactor tests, add fn center() for Line
authorunC0Rr
Fri, 02 Nov 2018 13:30:04 +0100
changeset 14082 5ade484f3351
parent 14081 e5904ead4864
child 14083 bf40b5f938b0
Refactor tests, add fn center() for Line
rust/integral-geometry/src/lib.rs
rust/landgen/src/outline.rs
--- a/rust/integral-geometry/src/lib.rs	Fri Nov 02 13:17:46 2018 +0100
+++ b/rust/integral-geometry/src/lib.rs	Fri Nov 02 13:30:04 2018 +0100
@@ -229,6 +229,11 @@
     pub fn zero() -> Self {
         Self::new(Point::zero(), Point::zero())
     }
+
+    #[inline]
+    pub fn center(&self) -> Point {
+        (self.start + self.end) / Point::new(2, 2) // point div point, really?
+    }
 }
 
 impl IntoIterator for Line {
@@ -377,17 +382,19 @@
 
     #[test]
     fn line_basic() {
-        let line = Line::new(Point::new(0, 0), Point::new(3, 3)).into_iter();
-        let v = get_points(&[(0, 0), (1, 1), (2, 2), (3, 3), (123, 456)]);
+        let line: Vec<Point> = Line::new(Point::new(0, 0), Point::new(3, 3))
+            .into_iter()
+            .collect();
+        let v = get_points(&[(0, 0), (1, 1), (2, 2), (3, 3)]);
 
-        for (&a, b) in v.iter().zip(line) {
-            assert_eq!(a, b);
-        }
+        assert_eq!(line, v);
     }
 
     #[test]
     fn line_skewed() {
-        let line = Line::new(Point::new(0, 0), Point::new(5, -7)).into_iter();
+        let line: Vec<Point> = Line::new(Point::new(0, 0), Point::new(5, -7))
+            .into_iter()
+            .collect();
         let v = get_points(&[
             (0, 0),
             (1, -1),
@@ -399,14 +406,12 @@
             (5, -7),
         ]);
 
-        for (&a, b) in v.iter().zip(line) {
-            assert_eq!(a, b);
-        }
+        assert_eq!(line, v);
     }
 
     #[test]
     fn equidistant_full() {
-        let n = EquidistantPoints::new(Point::new(1, 3));
+        let n: Vec<Point> = EquidistantPoints::new(Point::new(1, 3)).collect();
         let v = get_points(&[
             (-1, -3),
             (1, -3),
@@ -416,21 +421,23 @@
             (3, -1),
             (-3, 1),
             (3, 1),
-            (123, 456),
         ]);
 
-        for (&a, b) in v.iter().zip(n) {
-            assert_eq!(a, b);
-        }
+        assert_eq!(n, v);
     }
 
     #[test]
     fn equidistant_half() {
-        let n = EquidistantPoints::new(Point::new(2, 2));
-        let v = get_points(&[(-2, -2), (2, -2), (-2, 2), (2, 2), (123, 456)]);
+        let n: Vec<Point> = EquidistantPoints::new(Point::new(2, 2)).collect();
+        let v = get_points(&[(-2, -2), (2, -2), (-2, 2), (2, 2)]);
+
+        assert_eq!(n, v);
+    }
 
-        for (&a, b) in v.iter().zip(n) {
-            assert_eq!(a, b);
-        }
+    #[test]
+    fn line() {
+        let l = Line::new(Point::new(1, 1), Point::new(5, 6));
+
+        assert_eq!(l.center(), Point::new(3, 3));
     }
 }
--- a/rust/landgen/src/outline.rs	Fri Nov 02 13:17:46 2018 +0100
+++ b/rust/landgen/src/outline.rs	Fri Nov 02 13:30:04 2018 +0100
@@ -51,6 +51,7 @@
         segment: Line,
         random_numbers: &mut I,
     ) -> Option<Point> {
+
         None
     }