#[derive(Clone, Copy, Debug)]
pub struct Rect {
pub x: f64, pub y: f64, pub width: f64, pub height: f64, }
impl Rect {
pub fn new(x: f64, y: f64, width: f64, height: f64) -> Self {
Rect {
x,
y,
width,
height,
}
}
pub fn expand(&self, bleed: f64) -> Self {
Rect {
x: self.x - bleed,
y: self.y - bleed,
width: self.width + 2.0 * bleed,
height: self.height + 2.0 * bleed,
}
}
pub fn from_corners(x0: f64, y0: f64, x1: f64, y1: f64) -> Self {
Rect {
x: x0.min(x1),
y: y0.min(y1),
width: (x1 - x0).abs(),
height: (y1 - y0).abs(),
}
}
pub fn to_pdf_array(&self) -> [f64; 4] {
[self.x, self.y, self.right(), self.top()]
}
pub fn from_pdf_array(arr: &[f64]) -> Self {
Rect::from_corners(arr[0], arr[1], arr[2], arr[3])
}
pub fn right(&self) -> f64 {
self.x + self.width
}
pub fn top(&self) -> f64 {
self.y + self.height
}
pub fn is_outside(&self, trim: &Rect) -> bool {
self.right() <= trim.x || self.x >= trim.right() || self.top() <= trim.y || self.y >= trim.top() }
}