#[derive(Debug, Copy, Clone, PartialEq)]
pub struct ScissorBox {
pub x: i32,
pub y: i32,
pub width: u32,
pub height: u32,
}
impl ScissorBox {
pub fn new_at_origo(width: u32, height: u32) -> Self {
Self {
x: 0,
y: 0,
width,
height,
}
}
pub fn intersection(&self, other: impl Into<Self>) -> Self {
let other = other.into();
let x = self.x.max(other.x);
let y = self.y.max(other.y);
let width = (self.x + self.width as i32 - x)
.min(other.x + other.width as i32 - x)
.max(0) as u32;
let height = (self.y + self.height as i32 - y)
.min(other.y + other.height as i32 - y)
.max(0) as u32;
Self {
x,
y,
width,
height,
}
}
}
impl From<crate::core::Viewport> for ScissorBox {
fn from(viewport: crate::core::Viewport) -> Self {
Self {
x: viewport.x,
y: viewport.y,
width: viewport.width,
height: viewport.height,
}
}
}
impl From<crate::core::ScissorBox> for crate::core::Viewport {
fn from(viewport: crate::core::ScissorBox) -> Self {
Self {
x: viewport.x,
y: viewport.y,
width: viewport.width,
height: viewport.height,
}
}
}