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 {}
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()?;