rust/land2d/src/lib.rs
branchtransitional_engine
changeset 15942 6e22f4390b7e
parent 15934 022ec6b916b7
child 15943 c5684cc62de8
--- a/rust/land2d/src/lib.rs	Wed Jan 04 15:26:30 2023 +0100
+++ b/rust/land2d/src/lib.rs	Mon Jan 30 15:50:14 2023 +0100
@@ -2,13 +2,14 @@
 use vec2d::Vec2D;
 use integral_geometry::{ArcPoints, EquidistantPoints, Line, Point, PotSize, Rect, Size, SizeMask};
 
+#[derive(Debug)]
 pub struct Land2D<T> {
     pixels: vec2d::Vec2D<T>,
     play_box: Rect,
     mask: SizeMask,
 }
 
-impl<T: Copy + PartialEq> Land2D<T> {
+impl<T: Copy + PartialEq + Default> Land2D<T> {
     pub fn new(play_size: &Size, fill_value: T) -> Self {
         let real_size = play_size.next_power_of_two();
         let top_left = Point::new(
@@ -99,6 +100,18 @@
     }
 
     #[inline]
+    pub fn get(&self, y: i32, x: i32) -> T {
+        if self.is_valid_coordinate(x, y) {
+            unsafe {
+                // hey, I just checked that coordinates are valid!
+                *self.pixels.get_unchecked(y as usize, x as usize)
+            }
+        } else {
+            T::default()
+        }
+    }
+
+    #[inline]
     pub fn map_point<U: Default, F: FnOnce(&mut T) -> U>(&mut self, point: Point, f: F) -> U {
         self.map(point.y, point.x, f)
     }