From 331128b0cb5ab0f4da0cf49f9620f93085f48207 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 26 Apr 2023 09:38:06 +0200 Subject: [PATCH] Add `BuildCycle::polygon` --- .../fj-kernel/src/operations/build/cycle.rs | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/crates/fj-kernel/src/operations/build/cycle.rs b/crates/fj-kernel/src/operations/build/cycle.rs index 93dae568e..ffb76f516 100644 --- a/crates/fj-kernel/src/operations/build/cycle.rs +++ b/crates/fj-kernel/src/operations/build/cycle.rs @@ -1,4 +1,13 @@ -use crate::objects::Cycle; +use fj_math::Point; +use itertools::Itertools; + +use crate::{ + objects::{Cycle, HalfEdge}, + operations::Insert, + services::Services, +}; + +use super::BuildHalfEdge; /// Build a [`Cycle`] pub trait BuildCycle { @@ -6,6 +15,25 @@ pub trait BuildCycle { fn empty() -> Cycle { Cycle::new([]) } + + /// Build a polygon + fn polygon(points: Ps, services: &mut Services) -> Cycle + where + P: Into>, + Ps: IntoIterator, + 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 {}