Move flip and mirror to outline methods
authorunc0rr
Fri, 02 Nov 2018 20:30:22 +0100
changeset 14100 b2feb190e4bc
parent 14099 d0b0d61b7d5e
child 14101 133f648c5fbd
Move flip and mirror to outline methods
rust/landgen/src/outline.rs
rust/landgen/src/template_based.rs
--- a/rust/landgen/src/outline.rs	Fri Nov 02 21:30:48 2018 +0300
+++ b/rust/landgen/src/outline.rs	Fri Nov 02 20:30:22 2018 +0100
@@ -191,6 +191,17 @@
             index: 0,
         }
     }
+
+    pub fn mirror(&mut self) {
+        self.iter_mut()
+            .for_each(|p| p.x = self.size.width() - 1 - p.x);
+    }
+
+    pub fn flip(&mut self) {
+        points
+            .iter_mut()
+            .for_each(|p| p.y = self.size.height() - 1 - p.y);
+    }
 }
 
 struct OutlineSegmentsIterator<'a> {
--- a/rust/landgen/src/template_based.rs	Fri Nov 02 21:30:48 2018 +0300
+++ b/rust/landgen/src/template_based.rs	Fri Nov 02 20:30:22 2018 +0100
@@ -32,9 +32,7 @@
         if self.outline_template.can_mirror {
             if let Some(b) = random_numbers.next() {
                 if b & 1 != 0 {
-                    points
-                        .iter_mut()
-                        .for_each(|p| p.x = land.width() as i32 - 1 - p.x);
+                    points.mirror();
                 }
             }
         }
@@ -43,9 +41,7 @@
         if self.outline_template.can_flip {
             if let Some(b) = random_numbers.next() {
                 if b & 1 != 0 {
-                    points
-                        .iter_mut()
-                        .for_each(|p| p.y = land.height() as i32 - 1 - p.y);
+                    points.flip();
                 }
             }
         }