use bevy::{prelude::UVec2, reflect::Reflect};
use crate::tilemap::map::Tilemap;
pub mod aabb;
pub mod extension;
#[derive(Debug, Clone, Copy, Reflect)]
pub struct FillArea {
pub(crate) origin: UVec2,
pub(crate) extent: UVec2,
pub(crate) dest: UVec2,
}
impl FillArea {
pub fn new(origin: UVec2, extent: Option<UVec2>, tilemap: &Tilemap) -> Self {
let extent = match extent {
Some(extent) => {
if tilemap.is_out_of_tilemap_uvec(origin + extent - 1) {
panic!("Part of the fill area is out of the tilemap");
};
extent
}
None => UVec2 {
x: tilemap.size.x - origin.x,
y: tilemap.size.y - origin.y,
},
};
Self {
origin,
extent,
dest: origin + extent - 1,
}
}
pub fn full(tilemap: &Tilemap) -> Self {
Self::new(UVec2::ZERO, None, tilemap)
}
pub fn size(&self) -> usize {
(self.extent.x * self.extent.y) as usize
}
}