Skip to content

Commit

Permalink
Add BuildCycle::polygon
Browse files Browse the repository at this point in the history
  • Loading branch information
hannobraun committed Apr 26, 2023
1 parent f678e59 commit 331128b
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion crates/fj-kernel/src/operations/build/cycle.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,39 @@
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 {
/// Build an empty cycle
fn empty() -> Cycle {
Cycle::new([])
}

/// Build a polygon
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 {}

0 comments on commit 331128b

Please sign in to comment.