use std::ops::{Deref, DerefMut};
use super::curve::Curve;
use super::curve_path::delegate_curve_path;
use super::path::Path;
use crate::math::Vector2;
#[derive(Clone, Debug, Default)]
pub struct Shape {
pub path: Path,
pub holes: Vec<Path>,
}
impl Deref for Shape {
type Target = Path;
fn deref(&self) -> &Self::Target {
&self.path
}
}
impl DerefMut for Shape {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.path
}
}
delegate_curve_path!(Shape, path, Vector2, "Shape");
#[derive(Clone, Debug, Default, PartialEq)]
pub struct ShapePoints {
pub shape: Vec<Vector2>,
pub holes: Vec<Vec<Vector2>>,
}
impl Shape {
pub fn new() -> Self {
Self::default()
}
pub fn from_points(points: &[Vector2]) -> Self {
Self {
path: Path::from_points(points),
holes: Vec::new(),
}
}
pub fn get_points_holes(&self, divisions: usize) -> Vec<Vec<Vector2>> {
self.holes
.iter()
.map(|hole| hole.get_points(divisions))
.collect()
}
pub fn extract_points(&self, divisions: usize) -> ShapePoints {
ShapePoints {
shape: self.get_points(divisions),
holes: self.get_points_holes(divisions),
}
}
}