Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add some useful methods to Cycle #1780

Merged
merged 3 commits into from
Apr 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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