a bit of simplification
authoralfadur
Sat, 03 Nov 2018 02:21:45 +0300
changeset 14106 5c1ce63114a5
parent 14105 7e25f4800af8
child 14107 6a3bcb7c2981
a bit of simplification
rust/integral-geometry/src/lib.rs
rust/landgen/src/outline.rs
--- a/rust/integral-geometry/src/lib.rs	Sat Nov 03 02:16:13 2018 +0300
+++ b/rust/integral-geometry/src/lib.rs	Sat Nov 03 02:21:45 2018 +0300
@@ -58,6 +58,11 @@
             matrix[2] * self.x + matrix[3] * self.y,
         )
     }
+
+    #[inline]
+    pub fn rotate90(self) -> Self {
+        Point::new(-self.y, self.x)
+    }
 }
 
 #[derive(PartialEq, Eq, Clone, Copy, Debug)]
@@ -416,6 +421,11 @@
     pub fn center(&self) -> Point {
         (self.start + self.end) / 2
     }
+
+    #[inline]
+    pub fn scaled_normal(&self) -> Point {
+        (self.end - self.start).rotate90()
+    }
 }
 
 impl IntoIterator for Line {
--- a/rust/landgen/src/outline.rs	Sat Nov 03 02:16:13 2018 +0300
+++ b/rust/landgen/src/outline.rs	Sat Nov 03 02:21:45 2018 +0300
@@ -105,10 +105,7 @@
         // new point should fall inside this box
         let map_box = self.play_box.with_margin(min_distance);
 
-        let p = Point::new(
-            segment.end.y - segment.start.y,
-            segment.start.x - segment.end.x,
-        );
+        let p = -segment.scaled_normal();
         let mid_point = segment.center();
 
         if (p.integral_norm() < min_distance as u32 * 3) || !map_box.contains_inside(mid_point) {