1use crate::{
4 math::Matrix2d,
5 triangulation,
6 types::{Color, Radius, Rectangle, Resolution, Scalar},
7 DrawState, Graphics,
8};
9
10#[derive(Copy, Clone)]
12pub struct CircleArc {
13 pub color: Color,
15
16 pub radius: Radius,
18
19 pub start: Scalar,
21
22 pub end: Scalar,
24
25 pub resolution: Resolution,
27}
28
29impl CircleArc {
30 pub fn new(color: Color, radius: Radius, start: Scalar, end: Scalar) -> CircleArc {
32 CircleArc {
33 color,
34 radius,
35 start,
36 end,
37 resolution: 128,
38 }
39 }
40
41 pub fn color(mut self, value: Color) -> Self {
43 self.color = value;
44 self
45 }
46
47 pub fn radius(mut self, value: Radius) -> Self {
49 self.radius = value;
50 self
51 }
52
53 pub fn start(mut self, value: Scalar) -> Self {
55 self.start = value;
56 self
57 }
58
59 pub fn end(mut self, value: Scalar) -> Self {
61 self.end = value;
62 self
63 }
64
65 pub fn resolution(mut self, value: Resolution) -> Self {
67 self.resolution = value;
68 self
69 }
70
71 #[inline(always)]
73 pub fn draw<R: Into<Rectangle>, G>(
74 &self,
75 rectangle: R,
76 draw_state: &DrawState,
77 transform: Matrix2d,
78 g: &mut G,
79 ) where
80 G: Graphics,
81 {
82 g.circle_arc(self, rectangle, draw_state, transform);
83 }
84
85 pub fn draw_tri<R: Into<Rectangle>, G>(
87 &self,
88 rectangle: R,
89 draw_state: &DrawState,
90 transform: Matrix2d,
91 g: &mut G,
92 ) where
93 G: Graphics,
94 {
95 let rectangle = rectangle.into();
96 g.tri_list(draw_state, &self.color, |f| {
97 triangulation::with_arc_tri_list(
98 self.start,
99 self.end,
100 self.resolution,
101 transform,
102 rectangle,
103 self.radius,
104 |vertices| f(vertices),
105 )
106 });
107 }
108}
109
110#[cfg(test)]
111mod test {
112 use super::*;
113 use crate::{radians::Radians, types::Scalar};
114
115 #[test]
116 fn test_circle_arc() {
117 let _arc = CircleArc::new([1.0; 4], 4.0, 0.0, Radians::_180())
118 .color([0.0; 4])
119 .radius(4.0)
120 .start(<Scalar as Radians>::_180() * 0.25)
121 .end(<Scalar as Radians>::_180() * 1.25);
122 }
123}