mod cleanup;
mod clip;
mod curve;
mod nan;
mod queue;
mod simplify;
mod sketch;
mod snap;
mod source;
mod string;
pub use cleanup::{CleanupOptions, Conditioned, SimplifySettings, VertexSegments};
pub use clip::Clipper;
pub use curve::CurveFlattener;
pub use nan::NanRemover;
pub use simplify::Simplifier;
pub use sketch::{SketchParams, Sketcher};
pub use snap::{SnapMode, Snapper};
pub use source::{PathVertices, Transformed};
pub use string::{StringCodes, StringOptions};
use super::{Path, PathCode};
use crate::{Affine2D, Bbox, Point};
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct Vertex {
pub code: PathCode,
pub point: Point,
}
impl Vertex {
pub const fn new(code: PathCode, point: Point) -> Self {
Self { code, point }
}
pub const fn move_to(point: Point) -> Self {
Self::new(PathCode::MoveTo, point)
}
pub const fn line_to(point: Point) -> Self {
Self::new(PathCode::LineTo, point)
}
pub const fn is_vertex(&self) -> bool {
!matches!(self.code, PathCode::ClosePoly)
}
}
const fn extra_vertices(code: PathCode) -> usize {
match code {
PathCode::Curve3 => 1,
PathCode::Curve4 => 2,
PathCode::MoveTo | PathCode::LineTo | PathCode::ClosePoly => 0,
}
}
pub trait VertexSource: Iterator<Item = Vertex> + Sized {
fn rewind(&mut self);
fn transform(self, transform: Affine2D) -> Transformed<Self> {
Transformed::new(self, transform)
}
fn remove_nans(self, enabled: bool, has_codes: bool) -> NanRemover<Self> {
NanRemover::new(self, enabled, has_codes)
}
fn clip_to(self, rect: Option<Bbox>) -> Clipper<Self> {
Clipper::new(self, rect)
}
fn snap(self, mode: SnapMode, total_vertices: usize, stroke_width: f64) -> Snapper<Self> {
Snapper::new(self, mode, total_vertices, stroke_width)
}
fn simplify(self, threshold: Option<f64>) -> Simplifier<Self> {
Simplifier::new(self, threshold)
}
fn flatten_curves(self, enabled: bool) -> CurveFlattener<Self> {
CurveFlattener::new(self, enabled)
}
fn sketch(self, params: Option<SketchParams>) -> Sketcher<Self> {
Sketcher::new(self, params)
}
fn segments(self) -> VertexSegments<Self> {
VertexSegments::new(self)
}
fn collect_path(self) -> Path {
let mut path = Path::default();
self.collect_path_into(&mut path);
path
}
fn collect_path_into(self, path: &mut Path) {
let codes = path.codes.get_or_insert_with(Vec::new);
path.vertices.clear();
codes.clear();
for vertex in self {
path.vertices.push(vertex.point);
codes.push(vertex.code);
}
path.interpolation_steps = 1;
}
}