#[cfg(feature = "alloc")]
extern crate alloc;
use super::PointF;
pub const MAX_STATIC_POINTS: usize = 16;
#[repr(C)]
#[derive(Clone, Copy, Debug)]
pub struct StaticPolygon {
points: [PointF; MAX_STATIC_POINTS],
count: usize,
closed: bool,
}
impl Default for StaticPolygon {
fn default() -> Self {
Self::new()
}
}
impl StaticPolygon {
#[inline]
pub const fn new() -> Self {
Self {
points: [PointF::ZERO; MAX_STATIC_POINTS],
count: 0,
closed: true,
}
}
#[inline]
pub const fn len(&self) -> usize {
self.count
}
#[inline]
pub const fn is_empty(&self) -> bool {
self.count == 0
}
#[inline]
pub const fn is_closed(&self) -> bool {
self.closed
}
#[inline]
pub fn set_closed(&mut self, closed: bool) {
self.closed = closed;
}
#[inline]
pub fn push(&mut self, point: PointF) -> bool {
if self.count >= MAX_STATIC_POINTS {
return false;
}
self.points[self.count] = point;
self.count += 1;
true
}
#[inline]
pub fn get(&self, index: usize) -> Option<PointF> {
if index < self.count {
Some(self.points[index])
} else {
None
}
}
#[inline]
pub fn iter(&self) -> impl Iterator<Item = &PointF> {
self.points[..self.count].iter()
}
#[inline]
pub fn clear(&mut self) {
self.count = 0;
}
#[inline]
pub fn triangle(p1: PointF, p2: PointF, p3: PointF) -> Self {
let mut poly = Self::new();
poly.push(p1);
poly.push(p2);
poly.push(p3);
poly
}
#[inline]
pub fn quad(p1: PointF, p2: PointF, p3: PointF, p4: PointF) -> Self {
let mut poly = Self::new();
poly.push(p1);
poly.push(p2);
poly.push(p3);
poly.push(p4);
poly
}
}
#[repr(u8)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum PathSegment {
MoveTo = 0,
LineTo = 1,
QuadTo = 2,
CubicTo = 3,
Close = 4,
}
impl PathSegment {
#[inline]
pub const fn point_count(&self) -> usize {
match self {
Self::MoveTo | Self::LineTo => 1,
Self::QuadTo => 2,
Self::CubicTo => 3,
Self::Close => 0,
}
}
}
#[repr(u8)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Default, Hash)]
pub enum FillRule {
#[default]
NonZero = 0,
EvenOdd = 1,
}