#[derive(Clone, Copy, Debug)]
pub struct RectInt {
pub min: glam::IVec2,
pub extent: glam::UVec2,
}
impl RectInt {
#[inline]
pub fn from_middle_and_extent(middle: glam::IVec2, size: glam::UVec2) -> Self {
Self {
min: middle - size.as_ivec2() / 2,
extent: size,
}
}
#[inline]
pub fn width(self) -> u32 {
self.extent.x
}
#[inline]
pub fn height(self) -> u32 {
self.extent.y
}
#[inline]
pub fn min(self) -> glam::IVec2 {
self.min
}
#[inline]
pub fn max(self) -> glam::IVec2 {
self.min + self.extent.as_ivec2()
}
#[inline]
pub fn wgpu_origin(self) -> wgpu::Origin3d {
wgpu::Origin3d {
x: self.min.x as u32,
y: self.min.y as u32,
z: 0,
}
}
#[inline]
pub fn wgpu_extent(self) -> wgpu::Extent3d {
wgpu::Extent3d {
width: self.extent.x,
height: self.extent.y,
depth_or_array_layers: 1,
}
}
}
#[derive(Clone, Copy, Debug)]
pub struct RectF32 {
pub min: glam::Vec2,
pub extent: glam::Vec2,
}
impl RectF32 {
pub const UNIT: Self = Self {
min: glam::Vec2::ZERO,
extent: glam::Vec2::ONE,
};
#[inline]
pub fn max(self) -> glam::Vec2 {
self.min + self.extent
}
#[inline]
pub fn center(self) -> glam::Vec2 {
self.min + self.extent / 2.0
}
#[inline]
pub fn scale_extent(self, factor: f32) -> Self {
Self {
min: self.min * factor,
extent: self.extent * factor,
}
}
}
impl From<RectInt> for RectF32 {
#[inline]
fn from(rect: RectInt) -> Self {
Self {
min: rect.min.as_vec2(),
extent: rect.extent.as_vec2(),
}
}
}