From cf6e1626c50f79c47e149d44ad3e40c8c2199711 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Tue, 9 Jul 2024 20:41:52 +0200 Subject: [PATCH 1/3] Add `Sibling` --- crates/fj-core/src/operations/split/edge.rs | 5 +++-- crates/fj-core/src/queries/mod.rs | 2 +- .../src/queries/sibling_of_half_edge.rs | 18 +++++++++--------- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/crates/fj-core/src/operations/split/edge.rs b/crates/fj-core/src/operations/split/edge.rs index 80cc3c778..bd669e921 100644 --- a/crates/fj-core/src/operations/split/edge.rs +++ b/crates/fj-core/src/operations/split/edge.rs @@ -43,7 +43,8 @@ impl SplitEdge for Shell { let [half_edge_a, half_edge_b] = half_edge.split_half_edge(point, core); let siblings = { - let [sibling_a, sibling_b] = sibling.split_half_edge(point, core); + let [sibling_a, sibling_b] = + sibling.sibling.split_half_edge(point, core); let sibling_b = sibling_b .update_start_vertex( |_, _| half_edge_b.start_vertex().clone(), @@ -65,7 +66,7 @@ impl SplitEdge for Shell { core, ) .into_inner() - .replace_half_edge(&sibling, siblings.clone(), core) + .replace_half_edge(&sibling.sibling, siblings.clone(), core) .into_inner(); (shell, [[half_edge_a, half_edge_b], siblings]) diff --git a/crates/fj-core/src/queries/mod.rs b/crates/fj-core/src/queries/mod.rs index 6f6488caf..ef15e3073 100644 --- a/crates/fj-core/src/queries/mod.rs +++ b/crates/fj-core/src/queries/mod.rs @@ -16,5 +16,5 @@ mod sibling_of_half_edge; pub use self::{ all_half_edges_with_surface::AllHalfEdgesWithSurface, bounding_vertices_of_half_edge::BoundingVerticesOfHalfEdge, - sibling_of_half_edge::SiblingOfHalfEdge, + sibling_of_half_edge::{Sibling, SiblingOfHalfEdge}, }; diff --git a/crates/fj-core/src/queries/sibling_of_half_edge.rs b/crates/fj-core/src/queries/sibling_of_half_edge.rs index 52c30758d..cf2036513 100644 --- a/crates/fj-core/src/queries/sibling_of_half_edge.rs +++ b/crates/fj-core/src/queries/sibling_of_half_edge.rs @@ -15,10 +15,7 @@ pub trait SiblingOfHalfEdge { /// Returns `None`, if the provided half-edge is not part of the object this /// method is called on, or if the provided half-edge has no sibling within /// the object. - fn get_sibling_of( - &self, - half_edge: &Handle, - ) -> Option>; + fn get_sibling_of(&self, half_edge: &Handle) -> Option; } impl SiblingOfHalfEdge for Shell { @@ -40,15 +37,12 @@ impl SiblingOfHalfEdge for Shell { same_curve && same_vertices } - fn get_sibling_of( - &self, - half_edge: &Handle, - ) -> Option> { + fn get_sibling_of(&self, half_edge: &Handle) -> Option { for face in self.faces() { for cycle in face.region().all_cycles() { for h in cycle.half_edges() { if self.are_siblings(half_edge, h) { - return Some(h.clone()); + return Some(Sibling { sibling: h.clone() }); } } } @@ -57,3 +51,9 @@ impl SiblingOfHalfEdge for Shell { None } } + +/// The sibling of a half-edge, plus some extra information +pub struct Sibling { + /// The sibling + pub sibling: Handle, +} From 61ef8f024cf317aaf7486f5a5a7f623902e97115 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Tue, 9 Jul 2024 20:43:01 +0200 Subject: [PATCH 2/3] Add more information to `Sibling` --- crates/fj-core/src/queries/sibling_of_half_edge.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/crates/fj-core/src/queries/sibling_of_half_edge.rs b/crates/fj-core/src/queries/sibling_of_half_edge.rs index cf2036513..3cc1e786f 100644 --- a/crates/fj-core/src/queries/sibling_of_half_edge.rs +++ b/crates/fj-core/src/queries/sibling_of_half_edge.rs @@ -1,6 +1,6 @@ use crate::{ storage::Handle, - topology::{HalfEdge, Shell}, + topology::{Cycle, Face, HalfEdge, Shell}, }; use super::BoundingVerticesOfHalfEdge; @@ -42,7 +42,11 @@ impl SiblingOfHalfEdge for Shell { for cycle in face.region().all_cycles() { for h in cycle.half_edges() { if self.are_siblings(half_edge, h) { - return Some(Sibling { sibling: h.clone() }); + return Some(Sibling { + sibling: h.clone(), + cycle: cycle.clone(), + face: face.clone(), + }); } } } @@ -56,4 +60,10 @@ impl SiblingOfHalfEdge for Shell { pub struct Sibling { /// The sibling pub sibling: Handle, + + /// The cycle in which the sibling was found + pub cycle: Handle, + + /// The face in which the sibling was found + pub face: Handle, } From 610c99cf9dfabd0db179a2b1823cc16e67ff9486 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Tue, 9 Jul 2024 20:49:59 +0200 Subject: [PATCH 3/3] Add `CycleOfHalfEdge` --- .../fj-core/src/queries/cycle_of_half_edge.rs | 32 +++++++++++++++++++ crates/fj-core/src/queries/mod.rs | 2 ++ 2 files changed, 34 insertions(+) create mode 100644 crates/fj-core/src/queries/cycle_of_half_edge.rs diff --git a/crates/fj-core/src/queries/cycle_of_half_edge.rs b/crates/fj-core/src/queries/cycle_of_half_edge.rs new file mode 100644 index 000000000..4ac4ec68e --- /dev/null +++ b/crates/fj-core/src/queries/cycle_of_half_edge.rs @@ -0,0 +1,32 @@ +use crate::{ + storage::Handle, + topology::{Cycle, HalfEdge, Shell}, +}; + +/// Query to find the cycle that a half-edge is part of +pub trait CycleOfHalfEdge { + /// Find the cycle that a half-edge is part of + fn find_cycle_of_half_edge( + &self, + half_edge: &Handle, + ) -> Option>; +} + +impl CycleOfHalfEdge for Shell { + fn find_cycle_of_half_edge( + &self, + half_edge: &Handle, + ) -> Option> { + for face in self.faces() { + for cycle in face.region().all_cycles() { + for h in cycle.half_edges() { + if h == half_edge { + return Some(cycle.clone()); + } + } + } + } + + None + } +} diff --git a/crates/fj-core/src/queries/mod.rs b/crates/fj-core/src/queries/mod.rs index ef15e3073..d2b45e2f4 100644 --- a/crates/fj-core/src/queries/mod.rs +++ b/crates/fj-core/src/queries/mod.rs @@ -11,10 +11,12 @@ mod all_half_edges_with_surface; mod bounding_vertices_of_half_edge; +mod cycle_of_half_edge; mod sibling_of_half_edge; pub use self::{ all_half_edges_with_surface::AllHalfEdgesWithSurface, bounding_vertices_of_half_edge::BoundingVerticesOfHalfEdge, + cycle_of_half_edge::CycleOfHalfEdge, sibling_of_half_edge::{Sibling, SiblingOfHalfEdge}, };