pub struct Walker<'a> { /* private fields */ }
Expand description
Used for easy and efficient traversal of the mesh. Also see Connectivity for common connectivity utility functionality.
Use Mesh::walker_from_vertex, Mesh::walker_from_halfedge or Mesh::walker_from_face to construct a walker and the examples below for instructions on how to use a walker.
Note: If you walk outside the mesh at some point, no error will be returned,
instead, all methods to extract an ID will return None
.
Examples
# 1
// Find the id of the vertex pointed to by a half-edge.
let vertex_id = mesh.walker_from_halfedge(halfedge_id).vertex_id().unwrap();
# 2
let mut walker = mesh.walker_from_halfedge(halfedge_id);
// Walk around the three sides of a face..
let result_halfedge_id = walker.as_next().as_next().next_id().unwrap();
// .. ending up at the same half-edge
assert_eq!(halfedge_id, result_halfedge_id);
# 3
// Find one neighbouring face to the given face
let neighbour_face_id = mesh.walker_from_face(face_id).into_twin().face_id().unwrap();
# 4
// Find the circumference of a face
let mut walker = mesh.walker_from_face(face_id);
let mut circumference = mesh.edge_length(walker.halfedge_id().unwrap());
walker.as_next();
circumference += mesh.edge_length(walker.halfedge_id().unwrap());
circumference += mesh.edge_length(walker.next_id().unwrap());
# 5
// Check if the half-edge is on the boundary of the mesh
let mut walker = mesh.walker_from_halfedge(halfedge_id);
let is_on_boundary = walker.face_id().is_none() || walker.as_twin().face_id().is_none();
# 6
// Compute the average edge length
let mut avg_edge_length = 0.0f64;
for halfedge_id in mesh.edge_iter()
{
let mut walker = mesh.walker_from_halfedge(halfedge_id);
let p0 = mesh.vertex_position(walker.vertex_id().unwrap());
let p1 = mesh.vertex_position(walker.as_twin().vertex_id().unwrap());
avg_edge_length += (p0 - p1).magnitude();
}
avg_edge_length /= mesh.no_edges() as f64;
Implementations
sourceimpl<'a> Walker<'a>
impl<'a> Walker<'a>
sourcepub fn into_previous(self) -> Self
pub fn into_previous(self) -> Self
Walk to the previous half-edge in the adjacent face.
sourcepub fn as_previous(&mut self) -> &mut Self
pub fn as_previous(&mut self) -> &mut Self
Walk to the previous half-edge in the adjacent face.
sourcepub fn vertex_id(&self) -> Option<VertexID>
pub fn vertex_id(&self) -> Option<VertexID>
Returns the id of the vertex pointed to by the current half-edge or None
if the walker has walked outside of the mesh at some point.
sourcepub fn next_id(&self) -> Option<HalfEdgeID>
pub fn next_id(&self) -> Option<HalfEdgeID>
Returns the id of the next half-edge in the adjacent face or None
if the half-edge is at the boundary of the mesh
or if the walker has walked outside of the mesh at some point.
sourcepub fn previous_id(&self) -> Option<HalfEdgeID>
pub fn previous_id(&self) -> Option<HalfEdgeID>
Returns the id of the previous half-edge in the adjacent face or None
if the half-edge is at the boundary of the mesh
or if the walker has walked outside of the mesh at some point.
sourcepub fn twin_id(&self) -> Option<HalfEdgeID>
pub fn twin_id(&self) -> Option<HalfEdgeID>
Returns the id of the twin half-edge to the current half-edge or None
if the walker has walked outside of the mesh at some point.
sourcepub fn halfedge_id(&self) -> Option<HalfEdgeID>
pub fn halfedge_id(&self) -> Option<HalfEdgeID>
Returns the id of the current half-edge or None
if the walker has walked outside of the mesh at some point.