diff --git a/src/map.rs b/src/map.rs index 584b5e3..5d2ba60 100644 --- a/src/map.rs +++ b/src/map.rs @@ -607,12 +607,14 @@ impl Index> for Map { type Output = Tiles; fn index(&self, position: Vector2) -> &Tiles { + assert!(0 <= position.x && position.x < self.dimensions.x && 0 <= position.y); &self.data[(position.y * self.dimensions.x + position.x) as usize] } } impl IndexMut> for Map { fn index_mut(&mut self, position: Vector2) -> &mut Tiles { + assert!(0 <= position.x && position.x < self.dimensions.x && 0 <= position.y); &mut self.data[(position.y * self.dimensions.x + position.x) as usize] } }