pub trait Vector<F: Float, const D: usize>:
ArrayBasic
+ ArrayRef<F, D>
+ ArrayIndex<F>
+ ArrayConvert<F, D>
+ ArrayAddSubNeg<F, D>
+ ArrayScale<F> {
Show 15 methods
// Provided methods
fn is_zero(&self) -> bool { ... }
fn mix<A>(self, other: A, t: F) -> Self
where A: Deref<Target = [F; D]> { ... }
fn dot(&self, other: &[F; D]) -> F { ... }
fn reduce_sum(&self) -> F { ... }
fn length_sq(&self) -> F { ... }
fn length(&self) -> F { ... }
fn distance_sq(&self, other: &[F; D]) -> F { ... }
fn distance(&self, other: &[F; D]) -> F { ... }
fn normalize(self) -> Self { ... }
fn rotate_around(self, pivot: &Self, angle: F, c0: usize, c1: usize) -> Self { ... }
fn cross_product(&self, other: &[F; 3]) -> Self
where Self: From<[F; 3]> + AsRef<[F; 3]> { ... }
fn apply_q3<Q>(&self, q: &Q) -> Self
where Q: Quaternion<F>,
Self: From<[F; 3]> + AsRef<[F; 3]> { ... }
fn apply_q4<Q>(&self, q: &Q) -> Self
where Q: Quaternion<F>,
Self: From<[F; 4]> + AsRef<[F; 4]> { ... }
fn transformed_by_m<const D2: usize>(&mut self, m: &[F; D2]) -> &mut Self
where [(); D]: IsSquared<D, D2> { ... }
fn uniform_dist_sphere3(x: [F; 2], map: bool) -> Self
where Self: From<[F; 3]> { ... }
}Expand description
The Vector trait describes an N-dimensional vector of Float type.
Such Vectors support basic vector arithmetic using addition and subtraction, and they provide component-wise multiplication and division, using the standard operators on two Vectors.
They also support basic arithmetic to all components of the
Vector for addition, subtraction, multiplication and division by
a scalar Float value type that they are comprised of. Hence a
v:Vector<F> may be scaled by a s:F using v * s.
The Vector can be indexed only by a usize; that is individual
components of the vector can be accessed, but ranges may not.
Provided Methods§
Sourcefn mix<A>(self, other: A, t: F) -> Self
fn mix<A>(self, other: A, t: F) -> Self
Create a linear combination of this Vector and another using parameter t from zero to one
Sourcefn reduce_sum(&self) -> F
fn reduce_sum(&self) -> F
Return the dot product of two vectors
Sourcefn distance_sq(&self, other: &[F; D]) -> F
fn distance_sq(&self, other: &[F; D]) -> F
Return the square of the distance between this vector and another
Sourcefn normalize(self) -> Self
fn normalize(self) -> Self
Normalize the vector; if its length is close to zero, then set it to be zero
Sourcefn rotate_around(self, pivot: &Self, angle: F, c0: usize, c1: usize) -> Self
fn rotate_around(self, pivot: &Self, angle: F, c0: usize, c1: usize) -> Self
Rotate a vector within a plane around a pivot point by the specified angle
The plane of rotation is specified by providing two vector indices for the elements to adjust. For a 2D rotation then the values of c0 and c1 should be 0 and 1.
For a 3D rotation about the Z axis, they should be 0 and 1; for rotation about the Y axis they should be 2 and 0; and for rotation about the X axis they should be 1 and 2.
Sourcefn cross_product(&self, other: &[F; 3]) -> Self
fn cross_product(&self, other: &[F; 3]) -> Self
Cross product of two 3-element vectors
Sourcefn apply_q3<Q>(&self, q: &Q) -> Self
fn apply_q3<Q>(&self, q: &Q) -> Self
Apply a quaternion to a V3
This can either take other as &[F;3] and produce [F; 3], or &D where D:Deref<Target = [F; 3]> and D:From<[F; 3]
If it takes the former then it can operate on [F;3] and anything that is Deref<Target = [F;3]>, but it needs its result cast into the correct vector
If it tkes the latter then it cannot operate on [F;3], but its result need not be cast
Sourcefn apply_q4<Q>(&self, q: &Q) -> Self
fn apply_q4<Q>(&self, q: &Q) -> Self
Apply a quaternion to a V4
This can either take other as &[F;3] and produce [F; 3], or &D where D:Deref<Target =[F; 3]> and D:From<[F; 3]
If it takes the former then it can operate on [F;3] and anything that is Deref<Target = [F;3]>, but it needs its result cast into the correct vector
If it tkes the latter then it cannot operate on [F;3], but its result need not be cast
Sourcefn transformed_by_m<const D2: usize>(&mut self, m: &[F; D2]) -> &mut Self
fn transformed_by_m<const D2: usize>(&mut self, m: &[F; D2]) -> &mut Self
Multiply the vector by the matrix to transform it
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.