easyofd_core/graphics2d/
ofd_page_graphics2d.rs1use super::OfdGraphics2DDrawParam;
9
10#[derive(Debug, Clone)]
18pub struct OfdPageGraphics2D {
19 pub page_width: f64,
21 pub page_height: f64,
23 pub draw_param: OfdGraphics2DDrawParam,
25 pub object_count: u32,
27}
28
29impl OfdPageGraphics2D {
30 #[must_use]
32 pub fn new(page_width: f64, page_height: f64) -> Self {
33 Self {
34 page_width,
35 page_height,
36 draw_param: OfdGraphics2DDrawParam::new(),
37 object_count: 0,
38 }
39 }
40
41 #[must_use]
43 pub fn draw_param(mut self, param: OfdGraphics2DDrawParam) -> Self {
44 self.draw_param = param;
45 self
46 }
47
48 #[must_use]
50 pub fn page_width(&self) -> f64 {
51 self.page_width
52 }
53
54 #[must_use]
56 pub fn page_height(&self) -> f64 {
57 self.page_height
58 }
59
60 #[must_use]
62 pub fn object_count(&self) -> u32 {
63 self.object_count
64 }
65
66 pub fn increment_object_count(&mut self) {
68 self.object_count += 1;
69 }
70}
71
72#[cfg(test)]
73mod tests {
74 use super::*;
75
76 #[test]
77 fn test_new() {
78 let g = OfdPageGraphics2D::new(210.0, 297.0);
79 assert!((g.page_width() - 210.0).abs() < f64::EPSILON);
80 assert!((g.page_height() - 297.0).abs() < f64::EPSILON);
81 assert_eq!(g.object_count(), 0);
82 }
83
84 #[test]
85 fn test_draw_param() {
86 let param = OfdGraphics2DDrawParam::new().line_width(3.0);
87 let g = OfdPageGraphics2D::new(100.0, 100.0).draw_param(param);
88 assert!((g.draw_param.line_width - 3.0).abs() < f64::EPSILON);
89 }
90
91 #[test]
92 fn test_increment_object_count() {
93 let mut g = OfdPageGraphics2D::new(100.0, 100.0);
94 g.increment_object_count();
95 g.increment_object_count();
96 assert_eq!(g.object_count(), 2);
97 }
98
99 #[test]
100 fn test_clone_debug() {
101 let g = OfdPageGraphics2D::new(100.0, 200.0);
102 let g2 = g.clone();
103 assert!((g2.page_width - 100.0).abs() < f64::EPSILON);
104 assert!(format!("{g:?}").contains("OfdPageGraphics2D"));
105 }
106}