From 331128b0cb5ab0f4da0cf49f9620f93085f48207 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 26 Apr 2023 09:38:06 +0200 Subject: [PATCH 1/2] 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 {} From a59304fc4f5845ae37d50f8c437589ff07402261 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 26 Apr 2023 09:39:23 +0200 Subject: [PATCH 2/2] Migrate test away from `CycleBuilder` --- crates/fj-kernel/src/validate/cycle.rs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/crates/fj-kernel/src/validate/cycle.rs b/crates/fj-kernel/src/validate/cycle.rs index 599df865a..53f502280 100644 --- a/crates/fj-kernel/src/validate/cycle.rs +++ b/crates/fj-kernel/src/validate/cycle.rs @@ -96,7 +96,6 @@ mod tests { use crate::{ assert_contains_err, - builder::CycleBuilder, objects::{Cycle, HalfEdge}, operations::{BuildCycle, BuildHalfEdge, Insert, UpdateCycle}, services::Services, @@ -107,11 +106,8 @@ mod tests { fn half_edges_connected() -> anyhow::Result<()> { let mut services = Services::new(); - let valid = CycleBuilder::polygon( - [[0.0, 0.0], [1.0, 0.0], [1.0, 1.0]], - &mut services, - ) - .build(&mut services); + let valid = + Cycle::polygon([[0.0, 0.0], [1.0, 0.0], [1.0, 1.0]], &mut services); valid.validate_and_return_first_error()?;