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>
impl<V: Copy> Faces<V>
sourcepub fn extend<U: Copy + Into<V>, T: AsRef<[U]>, I: IntoIterator<Item = T>>(
&mut self,
iter: I,
)
pub fn extend<U: Copy + Into<V>, T: AsRef<[U]>, I: IntoIterator<Item = T>>( &mut self, iter: I, )
Extends faces by an iterator.
sourcepub const fn from_tri_and_quad_faces(
tri_faces: Vec<[V; 3]>,
quad_faces: Vec<[V; 4]>,
) -> Self
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());
sourcepub fn push<U: Copy + Into<V>, T: AsRef<[U]>>(&mut self, face: T)
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"
sourcepub fn tri_faces_mut(&mut self) -> &mut [[V; 3]]
pub fn tri_faces_mut(&mut self) -> &mut [[V; 3]]
Returns the mutable slice of triangles.
sourcepub const fn quad_faces(&self) -> &Vec<[V; 4]>
pub const fn quad_faces(&self) -> &Vec<[V; 4]>
Returns the vector of quadrangles.
sourcepub fn quad_faces_mut(&mut self) -> &mut [[V; 4]]
pub fn quad_faces_mut(&mut self) -> &mut [[V; 4]]
Returns the mutable slice of quadrangles.
sourcepub const fn other_faces(&self) -> &Vec<Vec<V>>
pub const fn other_faces(&self) -> &Vec<Vec<V>>
Returns the vector of n-gons (n > 4).
sourcepub fn other_faces_mut(&mut self) -> impl Iterator<Item = &mut [V]>
pub fn other_faces_mut(&mut self) -> impl Iterator<Item = &mut [V]>
Returns the mutable iterator of n-gons (n > 4).
sourcepub fn face_iter(&self) -> impl Iterator<Item = &[V]>
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);
sourcepub fn face_iter_mut(&mut self) -> impl Iterator<Item = &mut [V]>
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
sourcepub fn naive_concat(&mut self, other: Self)
pub fn naive_concat(&mut self, other: Self)
Merges other
into self
.
sourcepub fn triangle_iter(&self) -> TriangleIterator<'_, V> ⓘ
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<'de, V> Deserialize<'de> for Faces<V>where
V: Deserialize<'de>,
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>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
source§impl<T: AsVertexSlice> FromIterator<T> for Faces
impl<T: AsVertexSlice> FromIterator<T> for Faces
source§impl<V: Copy> Invertible for Faces<V>
impl<V: Copy> Invertible for Faces<V>
impl<V: Eq> Eq for Faces<V>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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