mod circle;
mod line;
mod rectangle;
mod rounded_rectangle;
pub use circle::Circle;
pub use line::Line;
pub use rectangle::Rectangle;
pub use rounded_rectangle::RoundedRectangle;
use super::Point;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum PathEl {
MoveTo(Point),
LineTo(Point),
QuadTo(Point, Point),
CurveTo(Point, Point, Point),
ClosePath,
}
pub trait Shape {
type PathElementsIter<'iter>: Iterator<Item = PathEl> + 'iter
where
Self: 'iter;
fn path_elements(&self, tolerance: u16) -> Self::PathElementsIter<'_>;
fn bounding_box(&self) -> Rectangle;
fn as_line(&self) -> Option<Line> {
None
}
fn as_rect(&self) -> Option<Rectangle> {
None
}
fn as_rounded_rect(&self) -> Option<RoundedRectangle> {
None
}
fn as_circle(&self) -> Option<Circle> {
None
}
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct ShapePathIter<const N: usize> {
elements: [PathEl; N],
index: usize,
}
impl<const N: usize> Iterator for ShapePathIter<N> {
type Item = PathEl;
fn next(&mut self) -> Option<Self::Item> {
if self.index < N {
let element = self.elements[self.index];
self.index += 1;
Some(element)
} else {
None
}
}
}
impl<const N: usize> ShapePathIter<N> {
#[must_use]
pub const fn new(elements: [PathEl; N]) -> Self {
Self { elements, index: 0 }
}
}