From aa02b5376d57ee1cf1561486f251c5dffb18827b Mon Sep 17 00:00:00 2001 From: Maximilian Ammann Date: Sat, 2 Apr 2022 13:25:32 +0200 Subject: [PATCH] Add is_in_view and fix paddings --- src/coords.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/coords.rs b/src/coords.rs index e07b0134..dc229463 100644 --- a/src/coords.rs +++ b/src/coords.rs @@ -384,9 +384,17 @@ impl ViewRegion { } } + pub fn is_in_view(&self, &world_coords: &WorldTileCoords) -> bool { + world_coords.x <= self.max_tile.x + self.padding + && world_coords.y <= self.max_tile.y + self.padding + && world_coords.x >= self.min_tile.x - self.padding + && world_coords.y >= self.min_tile.y - self.padding + && world_coords.z == self.z + } + pub fn iter(&self) -> impl Iterator + '_ { - (self.min_tile.x..self.max_tile.x + self.padding).flat_map(move |x| { - (self.min_tile.y..self.max_tile.y + self.padding).map(move |y| { + (self.min_tile.x - self.padding..self.max_tile.x + 1 + self.padding).flat_map(move |x| { + (self.min_tile.y - self.padding..self.max_tile.y + 1 + self.padding).map(move |y| { let tile_coord: WorldTileCoords = (x, y, self.z as u8).into(); tile_coord })