put back land2d.map accidentally replaced by testing code
authoralfadur
Thu, 18 Oct 2018 07:27:14 +0300
changeset 13961 1c30793b1cea
parent 13960 665b4c6612ee
child 13962 3f69a70063a5
put back land2d.map accidentally replaced by testing code
rust/land2d/src/lib.rs
--- a/rust/land2d/src/lib.rs	Thu Oct 18 06:50:21 2018 +0300
+++ b/rust/land2d/src/lib.rs	Thu Oct 18 07:27:14 2018 +0300
@@ -50,22 +50,17 @@
     }
 
     #[inline]
-    pub fn get_mut(&mut self, y: i32, x: i32) -> Option<&mut T> {
+    pub fn map<U: Default, F: FnOnce(&mut T) -> U>(&mut self, y: i32, x: i32, f: F) -> U {
         if self.is_valid_coordinate(x, y) {
             unsafe {
                 // hey, I just checked that coordinates are valid!
-                Some(self.pixels.get_unchecked_mut(y as usize, x as usize))
+                f(self.pixels.get_unchecked_mut(y as usize, x as usize))
             }
         } else {
-            None
+            U::default()
         }
     }
 
-    #[inline]
-    pub fn map<U: Default, F: FnOnce(&mut T) -> U>(&mut self, y: i32, x: i32, f: F) -> U {
-        self.get_mut(y, x).map(f).unwrap_or_default()
-    }
-
     fn apply_along_line<U: Default + ops::AddAssign, F: FnMut(i32, i32) -> U>(
         x1: i32,
         y1: i32,
@@ -156,7 +151,7 @@
     pub fn fill_from_iter<I>(&mut self, i: I, value: T) -> usize
         where I: std::iter::Iterator<Item = Point>
     {
-        i.map(|p| self.get_mut(p.y, p.x).map(|v| *v = value)).count()
+        i.map(|p| self.map(p.y, p.x, |v| {*v = value; 1})).count()
     }
 
     pub fn draw_line(&mut self, from: Point, to: Point, value: T) -> usize {