use crate::pdfium_types::FS_RECTF;
#[derive(Debug, Copy, Clone)]
pub struct PdfiumRect {
pub left: f32,
pub top: f32,
pub right: f32,
pub bottom: f32,
}
impl PdfiumRect {
pub fn zero() -> Self {
Self {
left: 0.0,
top: 0.0,
right: 0.0,
bottom: 0.0,
}
}
pub fn new(left: f32, top: f32, right: f32, bottom: f32) -> Self {
Self {
left,
top,
right,
bottom,
}
}
pub fn new_from_lbrt(value: (f32, f32, f32, f32)) -> Self {
Self {
left: value.0,
bottom: value.1,
right: value.2,
top: value.3,
}
}
pub fn transpose(&self) -> Self {
Self {
left: self.bottom,
bottom: self.left,
right: self.top,
top: self.right,
}
}
#[inline]
pub fn width(&self) -> f32 {
self.right - self.left
}
#[inline]
pub fn height(&self) -> f32 {
self.top - self.bottom
}
}
impl From<FS_RECTF> for PdfiumRect {
fn from(rect: FS_RECTF) -> Self {
Self::new(rect.left, rect.top, rect.right, rect.bottom)
}
}
impl From<&PdfiumRect> for FS_RECTF {
fn from(rect: &PdfiumRect) -> Self {
FS_RECTF {
left: rect.left,
top: rect.top,
right: rect.right,
bottom: rect.bottom,
}
}
}