mirror of
https://github.com/hannobraun/Fornjot
synced 2025-03-10 07:02:36 +00:00
Merge pull request #2077 from hannobraun/sibling
Add query API for half-edge siblings
This commit is contained in:
commit
e0c26d287e
@ -1,6 +1,5 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
objects::{handles::Handles, Face, HalfEdge},
|
objects::{handles::Handles, Face},
|
||||||
queries::BoundingVerticesOfHalfEdge,
|
|
||||||
storage::Handle,
|
storage::Handle,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -22,28 +21,4 @@ impl Shell {
|
|||||||
pub fn faces(&self) -> &Handles<Face> {
|
pub fn faces(&self) -> &Handles<Face> {
|
||||||
&self.faces
|
&self.faces
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Indicate whether the provided half-edges are siblings
|
|
||||||
pub fn are_siblings(
|
|
||||||
&self,
|
|
||||||
a: &Handle<HalfEdge>,
|
|
||||||
b: &Handle<HalfEdge>,
|
|
||||||
) -> bool {
|
|
||||||
let same_curve = a.curve().id() == b.curve().id();
|
|
||||||
let same_boundary = a.boundary() == b.boundary().reverse();
|
|
||||||
let same_vertices = {
|
|
||||||
let Some(a_vertices) = self.bounding_vertices_of_half_edge(a)
|
|
||||||
else {
|
|
||||||
return false;
|
|
||||||
};
|
|
||||||
let Some(b_vertices) = self.bounding_vertices_of_half_edge(b)
|
|
||||||
else {
|
|
||||||
return false;
|
|
||||||
};
|
|
||||||
|
|
||||||
a_vertices == b_vertices.reverse()
|
|
||||||
};
|
|
||||||
|
|
||||||
same_curve && same_boundary && same_vertices
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -11,8 +11,10 @@
|
|||||||
|
|
||||||
mod all_half_edges_with_surface;
|
mod all_half_edges_with_surface;
|
||||||
mod bounding_vertices_of_half_edge;
|
mod bounding_vertices_of_half_edge;
|
||||||
|
mod sibling_of_half_edge;
|
||||||
|
|
||||||
pub use self::{
|
pub use self::{
|
||||||
all_half_edges_with_surface::AllHalfEdgesWithSurface,
|
all_half_edges_with_surface::AllHalfEdgesWithSurface,
|
||||||
bounding_vertices_of_half_edge::BoundingVerticesOfHalfEdge,
|
bounding_vertices_of_half_edge::BoundingVerticesOfHalfEdge,
|
||||||
|
sibling_of_half_edge::SiblingOfHalfEdge,
|
||||||
};
|
};
|
||||||
|
60
crates/fj-core/src/queries/sibling_of_half_edge.rs
Normal file
60
crates/fj-core/src/queries/sibling_of_half_edge.rs
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
use crate::{
|
||||||
|
objects::{HalfEdge, Shell},
|
||||||
|
storage::Handle,
|
||||||
|
};
|
||||||
|
|
||||||
|
use super::BoundingVerticesOfHalfEdge;
|
||||||
|
|
||||||
|
/// Queries related to the sibling of a [`HalfEdge`]
|
||||||
|
pub trait SiblingOfHalfEdge {
|
||||||
|
/// Indicate whether the provided half-edges are siblings
|
||||||
|
fn are_siblings(&self, a: &Handle<HalfEdge>, b: &Handle<HalfEdge>) -> bool;
|
||||||
|
|
||||||
|
/// Retrieve the sibling of this half-edge
|
||||||
|
///
|
||||||
|
/// 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>>;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl SiblingOfHalfEdge for Shell {
|
||||||
|
fn are_siblings(&self, a: &Handle<HalfEdge>, b: &Handle<HalfEdge>) -> bool {
|
||||||
|
let same_curve = a.curve().id() == b.curve().id();
|
||||||
|
let same_boundary = a.boundary() == b.boundary().reverse();
|
||||||
|
let same_vertices = {
|
||||||
|
let Some(a_vertices) = self.bounding_vertices_of_half_edge(a)
|
||||||
|
else {
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
let Some(b_vertices) = self.bounding_vertices_of_half_edge(b)
|
||||||
|
else {
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
|
a_vertices == b_vertices.reverse()
|
||||||
|
};
|
||||||
|
|
||||||
|
same_curve && same_boundary && same_vertices
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_sibling_of(
|
||||||
|
&self,
|
||||||
|
half_edge: &Handle<HalfEdge>,
|
||||||
|
) -> Option<Handle<HalfEdge>> {
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
@ -5,7 +5,9 @@ use fj_math::{Point, Scalar};
|
|||||||
use crate::{
|
use crate::{
|
||||||
geometry::SurfaceGeometry,
|
geometry::SurfaceGeometry,
|
||||||
objects::{HalfEdge, Shell, Surface},
|
objects::{HalfEdge, Shell, Surface},
|
||||||
queries::{AllHalfEdgesWithSurface, BoundingVerticesOfHalfEdge},
|
queries::{
|
||||||
|
AllHalfEdgesWithSurface, BoundingVerticesOfHalfEdge, SiblingOfHalfEdge,
|
||||||
|
},
|
||||||
storage::{Handle, HandleWrapper},
|
storage::{Handle, HandleWrapper},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user