mirror of
https://github.com/hannobraun/Fornjot
synced 2025-05-03 17:38:27 +00:00
Merge pull request #2414 from hannobraun/queries
Improve query capabilities on `Shell`
This commit is contained in:
commit
ff1e7e6178
@ -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])
|
||||
|
32
crates/fj-core/src/queries/cycle_of_half_edge.rs
Normal file
32
crates/fj-core/src/queries/cycle_of_half_edge.rs
Normal file
@ -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<HalfEdge>,
|
||||
) -> Option<Handle<Cycle>>;
|
||||
}
|
||||
|
||||
impl CycleOfHalfEdge for Shell {
|
||||
fn find_cycle_of_half_edge(
|
||||
&self,
|
||||
half_edge: &Handle<HalfEdge>,
|
||||
) -> Option<Handle<Cycle>> {
|
||||
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
|
||||
}
|
||||
}
|
@ -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,
|
||||
sibling_of_half_edge::SiblingOfHalfEdge,
|
||||
cycle_of_half_edge::CycleOfHalfEdge,
|
||||
sibling_of_half_edge::{Sibling, SiblingOfHalfEdge},
|
||||
};
|
||||
|
@ -1,6 +1,6 @@
|
||||
use crate::{
|
||||
storage::Handle,
|
||||
topology::{HalfEdge, Shell},
|
||||
topology::{Cycle, Face, HalfEdge, Shell},
|
||||
};
|
||||
|
||||
use super::BoundingVerticesOfHalfEdge;
|
||||
@ -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<HalfEdge>,
|
||||
) -> Option<Handle<HalfEdge>>;
|
||||
fn get_sibling_of(&self, half_edge: &Handle<HalfEdge>) -> Option<Sibling>;
|
||||
}
|
||||
|
||||
impl SiblingOfHalfEdge for Shell {
|
||||
@ -40,15 +37,16 @@ impl SiblingOfHalfEdge for Shell {
|
||||
same_curve && same_vertices
|
||||
}
|
||||
|
||||
fn get_sibling_of(
|
||||
&self,
|
||||
half_edge: &Handle<HalfEdge>,
|
||||
) -> Option<Handle<HalfEdge>> {
|
||||
fn get_sibling_of(&self, half_edge: &Handle<HalfEdge>) -> Option<Sibling> {
|
||||
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(),
|
||||
cycle: cycle.clone(),
|
||||
face: face.clone(),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -57,3 +55,15 @@ impl SiblingOfHalfEdge for Shell {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
/// The sibling of a half-edge, plus some extra information
|
||||
pub struct Sibling {
|
||||
/// The sibling
|
||||
pub sibling: Handle<HalfEdge>,
|
||||
|
||||
/// The cycle in which the sibling was found
|
||||
pub cycle: Handle<Cycle>,
|
||||
|
||||
/// The face in which the sibling was found
|
||||
pub face: Handle<Face>,
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user