-
-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2077 from hannobraun/sibling
Add query API for half-edge siblings
- Loading branch information
Showing
4 changed files
with
66 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters