forked from hannobraun/fornjot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request hannobraun#1797 from hannobraun/builder
Expand operations API
- Loading branch information
Showing
2 changed files
with
31 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters