Struct truck_polymesh::Faces

source ·
pub struct Faces<V = StandardVertex> { /* private fields */ }
Expand description

Faces of polygon mesh

To optimize for the case where the polygon mesh consists only triangles and quadrangle, there are vectors which consist by each triangles and quadrilaterals, internally.

Implementations§

source§

impl<V: Copy> Faces<V>

source

pub fn extend<U: Copy + Into<V>, T: AsRef<[U]>, I: IntoIterator<Item = T>>( &mut self, iter: I, )

Extends faces by an iterator.

source

pub const fn from_tri_and_quad_faces( tri_faces: Vec<[V; 3]>, quad_faces: Vec<[V; 4]>, ) -> Self

Creates faces of a polygon mesh by the vectors of triangle and quadrangle.

§Examples
// Creates faces consisis only triangles.
use truck_polymesh::*;
let tri_faces: Vec<[StandardVertex; 3]> = vec![
    [[0, 0, 0].into(), [1, 1, 1].into(), [2, 2, 2].into()],
    [[0, 0, 0].into(), [2, 2, 2].into(), [3, 3, 3].into()],
];
let faces = Faces::from_tri_and_quad_faces(tri_faces, Vec::new());
source

pub fn push<U: Copy + Into<V>, T: AsRef<[U]>>(&mut self, face: T)

Push a face to the faces.

If face.len() < 3, the face is ignored with warning.

§Examples
use truck_polymesh::*;
let mut faces = Faces::<StandardVertex>::default(); // empty faces
faces.push(&[[0, 0, 0], [1, 1, 1], [2, 2, 2]]);
faces.push(&[[3, 3, 3], [0, 0, 0], [2, 2, 2]]);
faces.push(&[[0, 0, 0], [4, 4, 4], [5, 5, 5], [1, 1, 1]]);
faces.push(&[[100, 1000, 10]]); // Wargning: ignored one vertex "face"
source

pub const fn tri_faces(&self) -> &Vec<[V; 3]>

Returns the vector of triangles.

source

pub fn tri_faces_mut(&mut self) -> &mut [[V; 3]]

Returns the mutable slice of triangles.

source

pub const fn quad_faces(&self) -> &Vec<[V; 4]>

Returns the vector of quadrangles.

source

pub fn quad_faces_mut(&mut self) -> &mut [[V; 4]]

Returns the mutable slice of quadrangles.

source

pub const fn other_faces(&self) -> &Vec<Vec<V>>

Returns the vector of n-gons (n > 4).

source

pub fn other_faces_mut(&mut self) -> impl Iterator<Item = &mut [V]>

Returns the mutable iterator of n-gons (n > 4).

source

pub fn face_iter(&self) -> impl Iterator<Item = &[V]>

Returns the iterator of the slice.

By the internal optimization, this iterator does not runs in the simple order in which they are registered, but runs order: triangle, square, and the others.

§Examples
use truck_polymesh::*;
let slice: &[&[usize]] = &[
    &[0, 1, 2],
    &[0, 4, 5, 1],
    &[1, 2, 6, 7, 8, 9],
    &[0, 2, 3],
];
let faces = Faces::<usize>::from_iter(slice);
let mut iter = faces.face_iter();
assert_eq!(iter.next(), Some([0, 1, 2].as_ref()));
assert_eq!(iter.next(), Some([0, 2, 3].as_ref()));
assert_eq!(iter.next(), Some([0, 4, 5, 1].as_ref()));
assert_eq!(iter.next(), Some([1, 2, 6, 7, 8, 9].as_ref()));
assert_eq!(iter.next(), None);
source

pub fn face_iter_mut(&mut self) -> impl Iterator<Item = &mut [V]>

Returns the iterator of the slice.

By the internal optimization, this iterator does not runs in the simple order in which they are registered, but runs order: triangle, square, and the others. cf: Faces:face_iter

source

pub fn is_empty(&self) -> bool

Returns true if the faces is empty.

source

pub fn len(&self) -> usize

Returns the number of faces.

source

pub fn naive_concat(&mut self, other: Self)

Merges other into self.

source

pub fn triangle_iter(&self) -> TriangleIterator<'_, V>

Returns iterator with triangulation faces

§Examples
use truck_polymesh::*;
let slice: &[&[usize]] = &[
    &[0, 1, 2],
    &[0, 4, 5, 1],
    &[1, 2, 6, 7, 8, 9],
    &[1, 2, 4, 3],
    &[0, 2, 3],
];
let faces = Faces::<usize>::from_iter(slice);
let mut iter = faces.triangle_iter();
assert_eq!(iter.len(), 10);
assert_eq!(iter.next(), Some([0, 1, 2]));
assert_eq!(iter.next(), Some([0, 2, 3]));
assert_eq!(iter.next(), Some([0, 4, 5]));
assert_eq!(iter.next(), Some([0, 5, 1]));
assert_eq!(iter.next(), Some([1, 2, 4]));
assert_eq!(iter.next(), Some([1, 4, 3]));
assert_eq!(iter.next(), Some([1, 2, 6]));
assert_eq!(iter.next(), Some([1, 6, 7]));
assert_eq!(iter.next(), Some([1, 7, 8]));
assert_eq!(iter.next(), Some([1, 8, 9]));
assert_eq!(iter.len(), 0);
assert_eq!(iter.next(), None);

Trait Implementations§

source§

impl<V: Clone> Clone for Faces<V>

source§

fn clone(&self) -> Faces<V>

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<V: Debug> Debug for Faces<V>

source§

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

Formats the value using the given formatter. Read more
source§

impl<V> Default for Faces<V>

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl<'de, V> Deserialize<'de> for Faces<V>
where V: Deserialize<'de>,

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl<S: AsRef<[usize]>> FromIterator<S> for Faces<usize>

source§

fn from_iter<I: IntoIterator<Item = S>>(iter: I) -> Faces<usize>

Creates a value from an iterator. Read more
source§

impl<T: AsVertexSlice> FromIterator<T> for Faces

source§

fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Faces

Creates a value from an iterator. Read more
source§

impl<V> Index<usize> for Faces<V>

source§

type Output = [V]

The returned type after indexing.
source§

fn index(&self, idx: usize) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
source§

impl IndexMut<usize> for Faces

source§

fn index_mut(&mut self, idx: usize) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
source§

impl<V: Copy> Invertible for Faces<V>

source§

fn invert(&mut self)

Inverts self
source§

fn inverse(&self) -> Self

Returns the inverse.
source§

impl<V: PartialEq> PartialEq for Faces<V>

source§

fn eq(&self, other: &Faces<V>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<V> Serialize for Faces<V>
where V: Serialize,

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl<V: Eq> Eq for Faces<V>

source§

impl<V> StructuralPartialEq for Faces<V>

Auto Trait Implementations§

§

impl<V> Freeze for Faces<V>

§

impl<V> RefUnwindSafe for Faces<V>
where V: RefUnwindSafe,

§

impl<V> Send for Faces<V>
where V: Send,

§

impl<V> Sync for Faces<V>
where V: Sync,

§

impl<V> Unpin for Faces<V>
where V: Unpin,

§

impl<V> UnwindSafe for Faces<V>
where V: UnwindSafe,

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, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
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.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,