Another project
1use bone_types::{Angle, Length, Point2};
2
3#[derive(Copy, Clone, Debug, PartialEq)]
4pub struct PreviewCircle {
5 pub center: Point2,
6 pub radius: Length,
7}
8
9#[derive(Copy, Clone, Debug, PartialEq)]
10pub struct PreviewArc {
11 pub center: Point2,
12 pub radius: Length,
13 pub start_angle: Angle,
14 pub sweep_angle: Angle,
15}
16
17#[derive(Clone, Debug, Default, PartialEq)]
18pub struct SketchPreview {
19 pub anchors: Vec<Point2>,
20 pub segments: Vec<(Point2, Point2)>,
21 pub circles: Vec<PreviewCircle>,
22 pub arcs: Vec<PreviewArc>,
23 pub snap: Option<Point2>,
24}
25
26impl SketchPreview {
27 #[must_use]
28 pub const fn empty() -> Self {
29 Self {
30 anchors: Vec::new(),
31 segments: Vec::new(),
32 circles: Vec::new(),
33 arcs: Vec::new(),
34 snap: None,
35 }
36 }
37
38 #[must_use]
39 pub fn is_empty(&self) -> bool {
40 self.anchors.is_empty()
41 && self.segments.is_empty()
42 && self.circles.is_empty()
43 && self.arcs.is_empty()
44 && self.snap.is_none()
45 }
46}
47
48#[cfg(test)]
49mod tests {
50 use super::{PreviewArc, PreviewCircle, SketchPreview};
51 use bone_types::{Angle, Length, Point2};
52 use uom::si::angle::radian;
53 use uom::si::length::millimeter;
54
55 #[test]
56 fn empty_has_no_overlay() {
57 let preview = SketchPreview::empty();
58 assert!(preview.is_empty());
59 }
60
61 #[test]
62 fn anchor_only_is_non_empty() {
63 let preview = SketchPreview {
64 anchors: vec![Point2::from_mm(1.0, 2.0)],
65 ..SketchPreview::empty()
66 };
67 assert!(!preview.is_empty());
68 }
69
70 #[test]
71 fn segment_only_is_non_empty() {
72 let preview = SketchPreview {
73 segments: vec![(Point2::from_mm(0.0, 0.0), Point2::from_mm(1.0, 1.0))],
74 ..SketchPreview::empty()
75 };
76 assert!(!preview.is_empty());
77 }
78
79 #[test]
80 fn snap_only_is_non_empty() {
81 let preview = SketchPreview {
82 snap: Some(Point2::from_mm(2.0, 3.0)),
83 ..SketchPreview::empty()
84 };
85 assert!(!preview.is_empty());
86 }
87
88 #[test]
89 fn circle_only_is_non_empty() {
90 let preview = SketchPreview {
91 circles: vec![PreviewCircle {
92 center: Point2::from_mm(0.0, 0.0),
93 radius: Length::new::<millimeter>(3.0),
94 }],
95 ..SketchPreview::empty()
96 };
97 assert!(!preview.is_empty());
98 }
99
100 #[test]
101 fn arc_only_is_non_empty() {
102 let preview = SketchPreview {
103 arcs: vec![PreviewArc {
104 center: Point2::from_mm(0.0, 0.0),
105 radius: Length::new::<millimeter>(2.0),
106 start_angle: Angle::new::<radian>(0.0),
107 sweep_angle: Angle::new::<radian>(1.0),
108 }],
109 ..SketchPreview::empty()
110 };
111 assert!(!preview.is_empty());
112 }
113}