From 06ad4d4f17946527876f4cca7295b5242154cabe Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 21 Apr 2023 11:40:13 +0200 Subject: [PATCH 1/3] Add `Cycle::index_of` --- crates/fj-kernel/src/objects/full/cycle.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/crates/fj-kernel/src/objects/full/cycle.rs b/crates/fj-kernel/src/objects/full/cycle.rs index 95e44fb7a..fd352614c 100644 --- a/crates/fj-kernel/src/objects/full/cycle.rs +++ b/crates/fj-kernel/src/objects/full/cycle.rs @@ -23,6 +23,13 @@ impl Cycle { self.half_edges.iter() } + /// Return the index of the provided half-edge, if it is in this cycle + pub fn index_of(&self, half_edge: &Handle) -> Option { + 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 From c3ce566741c8e1298733e462c0836b3b321a511a Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 21 Apr 2023 10:18:48 +0200 Subject: [PATCH 2/3] Add `Cycle::half_edge_after` --- crates/fj-kernel/src/objects/full/cycle.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/crates/fj-kernel/src/objects/full/cycle.rs b/crates/fj-kernel/src/objects/full/cycle.rs index fd352614c..b9b728ef2 100644 --- a/crates/fj-kernel/src/objects/full/cycle.rs +++ b/crates/fj-kernel/src/objects/full/cycle.rs @@ -23,6 +23,21 @@ impl Cycle { self.half_edges.iter() } + /// 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, + ) -> Option<&Handle> { + 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) -> Option { self.half_edges From 27b60d1b93de20ccf866dbd7edae2d77b4c94ddb Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 21 Apr 2023 11:47:17 +0200 Subject: [PATCH 3/3] Add `Cycle::nth_half_edge` --- crates/fj-kernel/src/objects/full/cycle.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/crates/fj-kernel/src/objects/full/cycle.rs b/crates/fj-kernel/src/objects/full/cycle.rs index b9b728ef2..c1910cc06 100644 --- a/crates/fj-kernel/src/objects/full/cycle.rs +++ b/crates/fj-kernel/src/objects/full/cycle.rs @@ -23,6 +23,11 @@ impl Cycle { self.half_edges.iter() } + /// Access the half-edge with the provided index + pub fn nth_half_edge(&self, index: usize) -> Option<&Handle> { + self.half_edges.get(index) + } + /// Access the half-edge after the provided one /// /// # Panics