diff -r b4809653f9d6 -r 6e22f4390b7e rust/land2d/src/lib.rs --- 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 { pixels: vec2d::Vec2D, play_box: Rect, mask: SizeMask, } -impl Land2D { +impl Land2D { 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>(&mut self, point: Point, f: F) -> U { self.map(point.y, point.x, f) }