use crate::geometry::Point;
use clipper2_rust::{PathD, PathsD, Point as ClipperPoint};
pub(crate) const PRECISION: i32 = 4;
pub(crate) fn to_path_d(points: &[Point], reverse: bool) -> PathD {
let mut path = PathD::with_capacity(points.len());
if reverse {
for p in points.iter().rev() {
path.push(ClipperPoint::<f64>::new(p.x, p.y));
}
} else {
for p in points {
path.push(ClipperPoint::<f64>::new(p.x, p.y));
}
}
path
}
pub(crate) fn to_paths_d(rings: &[&[Point]]) -> PathsD {
rings
.iter()
.filter(|r| !r.is_empty())
.map(|r| to_path_d(r, false))
.collect()
}
pub(crate) fn from_paths_d(paths: &PathsD) -> Vec<Vec<Point>> {
let mut out = Vec::with_capacity(paths.len());
for path in paths {
let mut ring = Vec::with_capacity(path.len());
for pt in path {
ring.push(Point::new(pt.x, pt.y));
}
if !ring.is_empty() {
out.push(ring);
}
}
out
}