pub struct Quad<V = Vec3>(pub [V; 4]);
Expand description
A quad represented by its four vertices.
Tuple Fields§
§0: [V; 4]
Implementations§
source§impl<V> Quad<V>where
V: Vertex,
impl<V> Quad<V>where
V: Vertex,
sourcepub fn centroid(&self) -> Vwhere
V: Average,
pub fn centroid(&self) -> Vwhere
V: Average,
Produce the centroid of the quad, aka the “mean”/“average” vertex.
sourcepub fn triangles(&self) -> (Tri<V>, Tri<V>)
pub fn triangles(&self) -> (Tri<V>, Tri<V>)
Triangulates the given quad, represented by four points that describe its edges in either clockwise or anti-clockwise order.
Example
The following rectangle
a b
--------
| |
| |
| |
--------
d c
given as
triangles([a, b, c, d])
returns
(Tri([a, b, c]), Tri([a, c, d]))
Here’s a basic code example:
use nannou::geom::{self, pt2, Quad, Tri};
fn main() {
let a = pt2(0.0, 1.0);
let b = pt2(1.0, 1.0);
let c = pt2(1.0, 0.0);
let d = pt2(0.0, 0.0);
let quad = Quad([a, b, c, d]);
let triangles = geom::quad::triangles(&quad);
assert_eq!(triangles, (Tri([a, b, c]), Tri([a, c, d])));
}
sourcepub fn triangles_iter(&self) -> Triangles<V> ⓘ
pub fn triangles_iter(&self) -> Triangles<V> ⓘ
The same as triangles
but provided as an Iterator.
sourcepub fn bounding_rect(self) -> Rect<<V as Vertex>::Scalar>where
V: Vertex2d,
pub fn bounding_rect(self) -> Rect<<V as Vertex>::Scalar>where
V: Vertex2d,
The bounding Rect
of the quad.
sourcepub fn bounding_cuboid(self) -> Cuboid<<V as Vertex>::Scalar>where
V: Vertex3d,
pub fn bounding_cuboid(self) -> Cuboid<<V as Vertex>::Scalar>where
V: Vertex3d,
The bounding Rect
of the triangle.
sourcepub fn map_vertices<F, V2>(self, map: F) -> Quad<V2>where
F: FnMut(V) -> V2,
pub fn map_vertices<F, V2>(self, map: F) -> Quad<V2>where
F: FnMut(V) -> V2,
Map the Quad’s vertices to a new type.
Methods from Deref<Target = [V; 4]>§
1.57.0 · sourcepub fn as_slice(&self) -> &[T]
pub fn as_slice(&self) -> &[T]
Returns a slice containing the entire array. Equivalent to &s[..]
.
sourcepub fn each_ref(&self) -> [&T; N]
🔬This is a nightly-only experimental API. (array_methods
)
pub fn each_ref(&self) -> [&T; N]
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);
sourcepub fn split_array_ref<const M: usize>(&self) -> (&[T; M], &[T])
🔬This is a nightly-only experimental API. (split_array
)
pub fn split_array_ref<const M: usize>(&self) -> (&[T; M], &[T])
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, &[]);
}
sourcepub fn rsplit_array_ref<const M: usize>(&self) -> (&[T], &[T; M])
🔬This is a nightly-only experimental API. (split_array
)
pub fn rsplit_array_ref<const M: usize>(&self) -> (&[T], &[T; M])
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]);
}
sourcepub fn as_ascii(&self) -> Option<&[AsciiChar; N]>
🔬This is a nightly-only experimental API. (ascii_char
)
pub fn as_ascii(&self) -> Option<&[AsciiChar; N]>
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");
sourcepub unsafe fn as_ascii_unchecked(&self) -> &[AsciiChar; N]
🔬This is a nightly-only experimental API. (ascii_char
)
pub unsafe fn as_ascii_unchecked(&self) -> &[AsciiChar; N]
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.
Trait Implementations§
source§impl<V> From<(V, V, V, V)> for Quad<V>where
V: Vertex,
impl<V> From<(V, V, V, V)> for Quad<V>where
V: Vertex,
source§fn from(_: (V, V, V, V)) -> Quad<V>
fn from(_: (V, V, V, V)) -> Quad<V>
source§impl<V> Into<(V, V, V, V)> for Quad<V>where
V: Vertex,
impl<V> Into<(V, V, V, V)> for Quad<V>where
V: Vertex,
source§fn into(self) -> (V, V, V, V)
fn into(self) -> (V, V, V, V)
source§impl<V> PartialEq for Quad<V>where
V: PartialEq,
impl<V> PartialEq for Quad<V>where
V: PartialEq,
impl<V> Copy for Quad<V>where
V: Copy,
impl<V> Eq for Quad<V>where
V: Eq,
impl<V> StructuralEq for Quad<V>
impl<V> StructuralPartialEq for Quad<V>
Auto Trait Implementations§
impl<V> RefUnwindSafe for Quad<V>where
V: RefUnwindSafe,
impl<V> Send for Quad<V>where
V: Send,
impl<V> Sync for Quad<V>where
V: Sync,
impl<V> Unpin for Quad<V>where
V: Unpin,
impl<V> UnwindSafe for Quad<V>where
V: UnwindSafe,
Blanket Implementations§
source§impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for S
impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for S
source§fn adapt_into_using<M>(self, method: M) -> Dwhere
M: TransformMatrix<Swp, Dwp, T>,
fn adapt_into_using<M>(self, method: M) -> Dwhere
M: TransformMatrix<Swp, Dwp, T>,
source§fn adapt_into(self) -> D
fn adapt_into(self) -> D
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, U> ConvertInto<U> for Twhere
U: ConvertFrom<T>,
impl<T, U> ConvertInto<U> for Twhere
U: ConvertFrom<T>,
source§fn convert_into(self) -> U
fn convert_into(self) -> U
source§fn convert_unclamped_into(self) -> U
fn convert_unclamped_into(self) -> U
source§fn try_convert_into(self) -> Result<U, OutOfBounds<U>>
fn try_convert_into(self) -> Result<U, OutOfBounds<U>>
OutOfBounds
error is returned which contains the unclamped color. Read moresource§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.