use crate::{
math::Matrix2d,
triangulation,
types::{Color, Radius, Rectangle, Resolution, Scalar},
DrawState, Graphics,
};
#[derive(Copy, Clone)]
pub struct CircleArc {
pub color: Color,
pub radius: Radius,
pub start: Scalar,
pub end: Scalar,
pub resolution: Resolution,
}
impl CircleArc {
pub fn new(color: Color, radius: Radius, start: Scalar, end: Scalar) -> CircleArc {
CircleArc {
color,
radius,
start,
end,
resolution: 128,
}
}
pub fn color(mut self, value: Color) -> Self {
self.color = value;
self
}
pub fn radius(mut self, value: Radius) -> Self {
self.radius = value;
self
}
pub fn start(mut self, value: Scalar) -> Self {
self.start = value;
self
}
pub fn end(mut self, value: Scalar) -> Self {
self.end = value;
self
}
pub fn resolution(mut self, value: Resolution) -> Self {
self.resolution = value;
self
}
#[inline(always)]
pub fn draw<R: Into<Rectangle>, G>(
&self,
rectangle: R,
draw_state: &DrawState,
transform: Matrix2d,
g: &mut G,
) where
G: Graphics,
{
g.circle_arc(self, rectangle, draw_state, transform);
}
pub fn draw_tri<R: Into<Rectangle>, G>(
&self,
rectangle: R,
draw_state: &DrawState,
transform: Matrix2d,
g: &mut G,
) where
G: Graphics,
{
let rectangle = rectangle.into();
g.tri_list(draw_state, &self.color, |f| {
triangulation::with_arc_tri_list(
self.start,
self.end,
self.resolution,
transform,
rectangle,
self.radius,
|vertices| f(vertices),
)
});
}
}
#[cfg(test)]
mod test {
use super::*;
use crate::{radians::Radians, types::Scalar};
#[test]
fn test_circle_arc() {
let _arc = CircleArc::new([1.0; 4], 4.0, 0.0, Radians::_180())
.color([0.0; 4])
.radius(4.0)
.start(<Scalar as Radians>::_180() * 0.25)
.end(<Scalar as Radians>::_180() * 1.25);
}
}