use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
pub struct BBox {
#[serde(rename = "left")]
pub x0: f64,
pub top: f64,
#[serde(rename = "right")]
pub x1: f64,
pub bottom: f64,
}
#[derive(Debug, Clone, Copy)]
pub struct Glyph {
pub ch: char,
pub bbox: BBox,
}
impl BBox {
pub fn width(&self) -> f64 {
self.x1 - self.x0
}
pub fn height(&self) -> f64 {
self.bottom - self.top
}
pub fn cx(&self) -> f64 {
(self.x0 + self.x1) / 2.0
}
pub fn cy(&self) -> f64 {
(self.top + self.bottom) / 2.0
}
pub fn contains_point(&self, cx: f64, cy: f64) -> bool {
cx >= self.x0 && cx < self.x1 && cy >= self.top && cy < self.bottom
}
pub fn contains_center(&self, inner: &BBox) -> bool {
self.contains_point(inner.cx(), inner.cy())
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum Orientation {
Horizontal,
Vertical,
}
#[derive(Debug, Clone, Copy)]
pub struct Edge {
pub x0: f64,
pub top: f64,
pub x1: f64,
pub bottom: f64,
pub orientation: Orientation,
}
impl Edge {
pub fn length(&self) -> f64 {
match self.orientation {
Orientation::Horizontal => self.x1 - self.x0,
Orientation::Vertical => self.bottom - self.top,
}
}
}
#[derive(Debug, Clone, Serialize)]
pub struct Cell {
pub text: String,
pub bbox: BBox,
}
#[derive(Debug, Clone, Serialize)]
pub struct Table {
pub extraction_method: &'static str,
pub bbox: BBox,
pub n_rows: usize,
pub n_cols: usize,
pub data: Vec<Vec<Cell>>,
}
#[derive(Debug, Clone, Serialize)]
pub struct Page {
pub page_number: usize,
pub width: f64,
pub height: f64,
pub tables: Vec<Table>,
}
#[derive(Debug, Clone, Serialize)]
pub struct Document {
pub source: String,
pub pages: Vec<Page>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub warnings: Vec<String>,
}