Struct nannou::geom::tri::Tri

source ·
pub struct Tri<V = Vec3>(pub [V; 3]);
Expand description

A triangle as three vertices.

Tuple Fields§

§0: [V; 3]

Implementations§

source§

impl<V> Tri<V>

source

pub fn from_index_tri(vertices: &[V], indices: &[usize; 3]) -> Tri<V>
where V: Clone,

Create a Tri by indexing into the given buffer.

Panics if any of the given indices are out of range of the given vertices slice.

source

pub fn from_vertices<I>(vertices: I) -> Option<Tri<V>>
where I: IntoIterator<Item = V>,

Create a Tri from the next three vertices yielded by the given vertices iterator.

Returns None if there were not at least 3 vertices in the given iterator.

source

pub fn vertices(self) -> Vertices<V>

Produce an iterator yielding each of the vertices of the triangle.

source

pub fn centroid(self) -> V
where V: Average,

Produce the centroid of the triangle aka the “mean”/“average” of all the points.

source

pub fn map_vertices<F, V2>(self, map: F) -> Tri<V2>
where F: FnMut(V) -> V2,

Maps the underlying vertices to a new type and returns the resulting Tri.

source

pub fn contains(&self, v: &V) -> bool
where V: Vertex2d,

Returns true if the given 2D vertex is contained within the 2D Tri.

Example
let a = [-0.5, 0.0];
let b = [0.0, 1.0];
let c = [0.5, -0.75];
let tri = Tri([a, b, c]);
assert!(tri.contains(&[0.0, 0.0]));
assert!(!tri.contains(&[3.0, 3.0]));
source

pub fn bounding_rect(self) -> Rect<<V as Vertex>::Scalar>
where V: Vertex2d,

The bounding Rect of the triangle.

source

pub fn bounding_cuboid(self) -> Cuboid<<V as Vertex>::Scalar>
where V: Vertex3d,

The bounding Rect of the triangle.

Methods from Deref<Target = [V; 3]>§

source

pub fn as_ascii(&self) -> Option<&[AsciiChar; N]>

🔬This is a nightly-only experimental API. (ascii_char)

Converts this array of bytes into a array of ASCII characters, or returns None if any of the characters is non-ASCII.

Examples
#![feature(ascii_char)]
#![feature(const_option)]

const HEX_DIGITS: [std::ascii::Char; 16] =
    *b"0123456789abcdef".as_ascii().unwrap();

assert_eq!(HEX_DIGITS[1].as_str(), "1");
assert_eq!(HEX_DIGITS[10].as_str(), "a");
source

pub unsafe fn as_ascii_unchecked(&self) -> &[AsciiChar; N]

🔬This is a nightly-only experimental API. (ascii_char)

Converts this array of bytes into a array of ASCII characters, without checking whether they’re valid.

Safety

Every byte in the array must be in 0..=127, or else this is UB.

1.57.0 · source

pub fn as_slice(&self) -> &[T]

Returns a slice containing the entire array. Equivalent to &s[..].

source

pub fn each_ref(&self) -> [&T; N]

🔬This is a nightly-only experimental API. (array_methods)

Borrows each element and returns an array of references with the same size as self.

Example
#![feature(array_methods)]

let floats = [3.1, 2.7, -1.0];
let float_refs: [&f64; 3] = floats.each_ref();
assert_eq!(float_refs, [&3.1, &2.7, &-1.0]);

This method is particularly useful if combined with other methods, like map. This way, you can avoid moving the original array if its elements are not Copy.

#![feature(array_methods)]

let strings = ["Ferris".to_string(), "♥".to_string(), "Rust".to_string()];
let is_ascii = strings.each_ref().map(|s| s.is_ascii());
assert_eq!(is_ascii, [true, false, true]);

// We can still access the original array: it has not been moved.
assert_eq!(strings.len(), 3);
source

pub fn split_array_ref<const M: usize>(&self) -> (&[T; M], &[T])

🔬This is a nightly-only experimental API. (split_array)

Divides one array reference into two at an index.

The first will contain all indices from [0, M) (excluding the index M itself) and the second will contain all indices from [M, N) (excluding the index N itself).

Panics

Panics if M > N.

Examples
#![feature(split_array)]

let v = [1, 2, 3, 4, 5, 6];

{
   let (left, right) = v.split_array_ref::<0>();
   assert_eq!(left, &[]);
   assert_eq!(right, &[1, 2, 3, 4, 5, 6]);
}

{
    let (left, right) = v.split_array_ref::<2>();
    assert_eq!(left, &[1, 2]);
    assert_eq!(right, &[3, 4, 5, 6]);
}

{
    let (left, right) = v.split_array_ref::<6>();
    assert_eq!(left, &[1, 2, 3, 4, 5, 6]);
    assert_eq!(right, &[]);
}
source

pub fn rsplit_array_ref<const M: usize>(&self) -> (&[T], &[T; M])

🔬This is a nightly-only experimental API. (split_array)

Divides one array reference into two at an index from the end.

The first will contain all indices from [0, N - M) (excluding the index N - M itself) and the second will contain all indices from [N - M, N) (excluding the index N itself).

Panics

Panics if M > N.

Examples
#![feature(split_array)]

let v = [1, 2, 3, 4, 5, 6];

{
   let (left, right) = v.rsplit_array_ref::<0>();
   assert_eq!(left, &[1, 2, 3, 4, 5, 6]);
   assert_eq!(right, &[]);
}

{
    let (left, right) = v.rsplit_array_ref::<2>();
    assert_eq!(left, &[1, 2, 3, 4]);
    assert_eq!(right, &[5, 6]);
}

{
    let (left, right) = v.rsplit_array_ref::<6>();
    assert_eq!(left, &[]);
    assert_eq!(right, &[1, 2, 3, 4, 5, 6]);
}

Trait Implementations§

source§

impl<V> AsRef<[V; 3]> for Tri<V>

source§

fn as_ref(&self) -> &[V; 3]

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl<V> AsRef<Tri<V>> for Tri<V>

source§

fn as_ref(&self) -> &Tri<V>

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl<V> Clone for Tri<V>
where V: Clone,

source§

fn clone(&self) -> Tri<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 for Tri<V>
where V: Debug,

source§

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

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

impl<V> Deref for Tri<V>

§

type Target = [V; 3]

The resulting type after dereferencing.
source§

fn deref(&self) -> &<Tri<V> as Deref>::Target

Dereferences the value.
source§

impl<V> From<[V; 3]> for Tri<V>

source§

fn from(points: [V; 3]) -> Tri<V>

Converts to this type from the input type.
source§

impl<V> From<(V, V, V)> for Tri<V>

source§

fn from(_: (V, V, V)) -> Tri<V>

Converts to this type from the input type.
source§

impl From<Tri<Vec2>> for Tri

source§

fn from(tri: Tri<Point2>) -> Self

Converts to this type from the input type.
source§

impl<V> Hash for Tri<V>
where V: Hash,

source§

fn hash<__H>(&self, state: &mut __H)
where __H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<V> Into<[V; 3]> for Tri<V>

source§

fn into(self) -> [V; 3]

Converts this type into the (usually inferred) input type.
source§

impl<V> Into<(V, V, V)> for Tri<V>

source§

fn into(self) -> (V, V, V)

Converts this type into the (usually inferred) input type.
source§

impl<V> PartialEq for Tri<V>
where V: PartialEq,

source§

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

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

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

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

impl<V> Copy for Tri<V>
where V: Copy,

source§

impl<V> Eq for Tri<V>
where V: Eq,

source§

impl<V> StructuralEq for Tri<V>

source§

impl<V> StructuralPartialEq for Tri<V>

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

Blanket Implementations§

source§

impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for S
where T: Component + Float, Swp: WhitePoint, Dwp: WhitePoint, D: AdaptFrom<S, Swp, Dwp, T>,

source§

fn adapt_into_using<M>(self, method: M) -> D
where M: TransformMatrix<Swp, Dwp, T>,

Convert the source color to the destination color using the specified method
source§

fn adapt_into(self) -> D

Convert the source color to the destination color using the bradford method by default
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, U> ConvertInto<U> for T
where U: ConvertFrom<T>,

source§

fn convert_into(self) -> U

Convert into T with values clamped to the color defined bounds Read more
source§

fn convert_unclamped_into(self) -> U

Convert into T. The resulting color might be invalid in its color space Read more
source§

fn try_convert_into(self) -> Result<U, OutOfBounds<U>>

Convert into T, returning ok if the color is inside of its defined range, otherwise an OutOfBounds error is returned which contains the unclamped color. Read more
§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. 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.

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

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

§

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>,

§

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>,

§

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

impl<T> Upcast<T> for T

§

fn upcast(&self) -> Option<&T>

§

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

§

fn vzip(self) -> V

§

impl<T> WasmNotSend for T
where T: Send,

§

impl<T> WasmNotSync for T
where T: Sync,