use fj_math::Point;
use itertools::Itertools;
use crate::{
objects::{Cycle, HalfEdge},
operations::Insert,
services::Services,
};
use super::BuildHalfEdge;
pub trait BuildCycle {
fn empty() -> Cycle {
Cycle::new([])
}
fn polygon<P, Ps>(points: Ps, services: &mut Services) -> Cycle
where
P: Into<Point<2>>,
Ps: IntoIterator<Item = P>,
Ps::IntoIter: Clone + ExactSizeIterator,
{
let half_edges = points
.into_iter()
.map(Into::into)
.circular_tuple_windows()
.map(|(start, end)| {
HalfEdge::line_segment([start, end], None, services)
.insert(services)
});
Cycle::new(half_edges)
}
}
impl BuildCycle for Cycle {}