Triangulation

Struct Triangulation 

Source
pub struct Triangulation<'a, V: IndexType> { /* private fields */ }
Expand description

A triangulation of a polygon. Will borrow the index buffer and append new triangles to it. Most methods will only look at the indices that are added after the borrow startet. It’s fine to add triangles to the index buffer directly while it is borrowed.

Implementations§

Source§

impl<'a, V: IndexType> Triangulation<'a, V>

Source

pub fn new(indices: &'a mut Vec<V>) -> Self

Create a new triangulation

Source

pub fn insert_triangle(&mut self, a: V, b: V, c: V)

Insert a triangle into the triangulation using global indices

Source

pub fn get_index(&self, i: usize) -> V

Get the ith index that was added to the triangulation

Source

pub fn get_triangle(&self, i: usize) -> (V, V, V)

Get a triangle from the triangulation using the number of the triangle in the triangulation

Source

pub fn get_triangle_area<Vec2: Vector2D>( &self, i: usize, vec_hm: &HashMap<V, Vec2>, ) -> Vec2::S

Get the area of a triangle in the triangulation

Source

pub fn insert_triangle_local<Vec2: Vector2D>( &mut self, a: usize, b: usize, c: usize, vec2s: &Vec<IndexedVertex2D<V, Vec2>>, )

Insert a triangle into the triangulation using local indices

Source

pub fn map_indices(&mut self, id_map: &HashMap<V, V>)

Map the indices in the triangulation using a hashmap

Source

pub fn len(&self) -> usize

Get the number of triangles inserted into the index buffer since the triangulation was created

Source

pub fn next_pos(&self) -> usize

Get the next index that will be added to the index buffer

Source

pub fn flip_edge( &mut self, a: V, b: V, triangle_ab: usize, triangle_ba: usize, ) -> Result<(), ()>

Flip the edge of the two triangles

Source

pub fn verify_non_degenerate_triangle<Vec2: Vector2D>( &self, vec_hm: &HashMap<V, Vec2>, )

Check for non-degenerate triangles (no zero-area triangles)

Source

pub fn verify_indices<Vec2: Vector2D>(&self, vec_hm: &HashMap<V, Vec2>)

Check for valid indices (i.e., they should be within the bounds of the vertices)

Source

pub fn verify_no_intersections<Vec2: Vector2D>(&self, vec_hm: &HashMap<V, Vec2>)

Check that no two triangles have intersecting edges

Source

pub fn get_area<Vec2: Vector2D>(&self, vec_hm: &HashMap<V, Vec2>) -> Vec2::S

Sum the area of all triangles added to the index buffer since the triangulation was created

Source

pub fn total_edge_weight<Vec2: Vector2D>( &self, vec_hm: &HashMap<V, Vec2>, ) -> Vec2::S

Calculate the total edge weight of the triangulation

Source

pub fn verify_area<Vec2: Vector2D, Poly: Polygon<Vec2>>( &self, vec2s: &Vec<IndexedVertex2D<V, Vec2>>, vec_hm: &HashMap<V, Vec2>, )

Calculate the area of the polygon and check if it is the same as the sum of the areas of the triangles

Source

pub fn verify_all_indices_used<Vec2: Vector2D>( &self, vec2s: &Vec<IndexedVertex2D<V, Vec2>>, )

Check that the set of used indices exactly matches the set of indices in the triangulation

Source

pub fn verify_full<Vec2: Vector2D, Poly: Polygon<Vec2>>( &self, vec2s: &Vec<IndexedVertex2D<V, Vec2>>, )

Runs a large number of tests on the triangulation to verify that it is well-formed

Trait Implementations§

Source§

impl<V: IndexType> Debug for Triangulation<'_, V>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a, V> Freeze for Triangulation<'a, V>

§

impl<'a, V> RefUnwindSafe for Triangulation<'a, V>
where V: RefUnwindSafe,

§

impl<'a, V> Send for Triangulation<'a, V>
where V: Send,

§

impl<'a, V> Sync for Triangulation<'a, V>
where V: Sync,

§

impl<'a, V> Unpin for Triangulation<'a, V>

§

impl<'a, V> !UnwindSafe for Triangulation<'a, V>

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> 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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
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