use super::ShapeTrait;
use crate::base::{PointF, RectF};
use crate::kernel::{PainterTrait, PathTrait};
use crate::platforms::Path;
const DEFAULT_END_ANGLE: f64 = std::f64::consts::TAU;
#[allow(clippy::module_name_repetitions)]
#[derive(Debug)]
pub struct CircularShape {
center: PointF,
radius: f64,
start_angle: f64,
end_angle: f64,
path: Path,
path_is_dirty: bool,
}
impl CircularShape {
#[must_use]
pub fn new(center: PointF, radius: f64) -> Self {
assert!(radius >= 0.0);
let path = Path::new();
Self {
center,
radius,
start_angle: 0.0,
end_angle: DEFAULT_END_ANGLE,
path,
path_is_dirty: true,
}
}
#[must_use]
pub const fn center(&self) -> PointF {
self.center
}
pub fn set_center(&mut self, center: PointF) {
self.center = center;
self.path_is_dirty = true;
}
#[must_use]
pub const fn radius(&self) -> f64 {
self.radius
}
pub fn set_radius(&mut self, radius: f64) {
assert!(radius >= 0.0);
self.radius = radius;
self.path_is_dirty = true;
}
#[must_use]
pub const fn start_angle(&self) -> f64 {
self.start_angle
}
pub fn set_start_angle(&mut self, start_angle: f64) {
self.start_angle = start_angle;
self.path_is_dirty = true;
}
#[must_use]
pub const fn end_angle(&self) -> f64 {
self.end_angle
}
pub fn set_end_angle(&mut self, end_angle: f64) {
self.end_angle = end_angle;
self.path_is_dirty = true;
}
fn update_path(&mut self) {
if !self.path_is_dirty {
return;
}
self.path.clear();
self.path
.arc(self.center, self.radius, self.start_angle, self.end_angle);
self.path_is_dirty = false;
}
}
impl ShapeTrait for CircularShape {
fn bounding_rect(&self) -> RectF {
todo!()
}
fn repaint(&mut self, painter: &mut dyn PainterTrait) {
self.update_path();
painter.stroke(&self.path);
}
}