use super::OfdGraphics2DDrawParam;
#[derive(Debug, Clone)]
pub struct OfdPageGraphics2D {
pub page_width: f64,
pub page_height: f64,
pub draw_param: OfdGraphics2DDrawParam,
pub object_count: u32,
}
impl OfdPageGraphics2D {
#[must_use]
pub fn new(page_width: f64, page_height: f64) -> Self {
Self {
page_width,
page_height,
draw_param: OfdGraphics2DDrawParam::new(),
object_count: 0,
}
}
#[must_use]
pub fn draw_param(mut self, param: OfdGraphics2DDrawParam) -> Self {
self.draw_param = param;
self
}
#[must_use]
pub fn page_width(&self) -> f64 {
self.page_width
}
#[must_use]
pub fn page_height(&self) -> f64 {
self.page_height
}
#[must_use]
pub fn object_count(&self) -> u32 {
self.object_count
}
pub fn increment_object_count(&mut self) {
self.object_count += 1;
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_new() {
let g = OfdPageGraphics2D::new(210.0, 297.0);
assert!((g.page_width() - 210.0).abs() < f64::EPSILON);
assert!((g.page_height() - 297.0).abs() < f64::EPSILON);
assert_eq!(g.object_count(), 0);
}
#[test]
fn test_draw_param() {
let param = OfdGraphics2DDrawParam::new().line_width(3.0);
let g = OfdPageGraphics2D::new(100.0, 100.0).draw_param(param);
assert!((g.draw_param.line_width - 3.0).abs() < f64::EPSILON);
}
#[test]
fn test_increment_object_count() {
let mut g = OfdPageGraphics2D::new(100.0, 100.0);
g.increment_object_count();
g.increment_object_count();
assert_eq!(g.object_count(), 2);
}
#[test]
fn test_clone_debug() {
let g = OfdPageGraphics2D::new(100.0, 200.0);
let g2 = g.clone();
assert!((g2.page_width - 100.0).abs() < f64::EPSILON);
assert!(format!("{g:?}").contains("OfdPageGraphics2D"));
}
}