Skip to content

Commit

Permalink
Merge pull request #1780 from hannobraun/cycle
Browse files Browse the repository at this point in the history
Add some useful methods to `Cycle`
  • Loading branch information
hannobraun authored Apr 21, 2023
2 parents d4fb4bb + 27b60d1 commit 265fe10
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions crates/fj-kernel/src/objects/full/cycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,33 @@ impl Cycle {
self.half_edges.iter()
}

/// Access the half-edge with the provided index
pub fn nth_half_edge(&self, index: usize) -> Option<&Handle<HalfEdge>> {
self.half_edges.get(index)
}

/// Access the half-edge after the provided one
///
/// # Panics
///
/// Panics, if the provided half-edge is not part of this cycle.
pub fn half_edge_after(
&self,
half_edge: &Handle<HalfEdge>,
) -> Option<&Handle<HalfEdge>> {
self.index_of(half_edge).map(|index| {
let next_index = (index + 1) % self.half_edges.len();
&self.half_edges[next_index]
})
}

/// Return the index of the provided half-edge, if it is in this cycle
pub fn index_of(&self, half_edge: &Handle<HalfEdge>) -> Option<usize> {
self.half_edges
.iter()
.position(|edge| edge.id() == half_edge.id())
}

/// Indicate the cycle's winding, assuming a right-handed coordinate system
///
/// Please note that this is not *the* winding of the cycle, only one of the
Expand Down

0 comments on commit 265fe10

Please sign in to comment.