Struct Walker

Source
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§

Source§

impl<'a> Walker<'a>

Source

pub fn into_next(self) -> Self

Walk to the next half-edge in the adjacent face.

Source

pub fn into_previous(self) -> Self

Walk to the previous half-edge in the adjacent face.

Source

pub fn into_twin(self) -> Self

Walk to the twin half-edge.

Source

pub fn as_next(&mut self) -> &mut Self

Walk to the next half-edge in the adjacent face.

Source

pub fn as_previous(&mut self) -> &mut Self

Walk to the previous half-edge in the adjacent face.

Source

pub fn as_twin(&mut self) -> &mut Self

Walk to the twin half-edge.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn face_id(&self) -> Option<FaceID>

Returns the id of 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.

Trait Implementations§

Source§

impl<'a> Clone for Walker<'a>

Source§

fn clone(&self) -> Walker<'a>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for Walker<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Walker<'a>

§

impl<'a> !RefUnwindSafe for Walker<'a>

§

impl<'a> !Send for Walker<'a>

§

impl<'a> !Sync for Walker<'a>

§

impl<'a> Unpin for Walker<'a>

§

impl<'a> !UnwindSafe for Walker<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.