pub trait Vector<F: Float, const D: usize>:
ArrayBasic
+ ArrayRef<F, D>
+ ArrayIndex<F>
+ ArrayConvert<F, D>
+ ArrayAddSubNeg<F, D>
+ ArrayScale<F> {
Show 19 methods
// Provided methods
fn set_zero(&mut self) { ... }
fn is_zero(&self) -> bool { ... }
fn dot<A: AsRef<[F; D]>>(&self, other: A) -> F { ... }
fn dot_arr(&self, other: &[F; D]) -> F { ... }
fn reduce_sum(&self) -> F { ... }
fn length_sq(&self) -> F { ... }
fn length(&self) -> F { ... }
fn normalize(self) -> Self { ... }
fn distance_sq<A: AsRef<[F; D]>>(&self, other: A) -> F { ... }
fn distance_sq_arr(&self, other: &[F; D]) -> F { ... }
fn distance<A: AsRef<[F; D]>>(&self, other: A) -> F { ... }
fn distance_arr(&self, other: &[F; D]) -> F { ... }
fn mix<A>(self, other: A, t: F) -> Self
where A: Deref<Target = [F; D]> { ... }
fn sum_scaled<A>(v: &[A], scales: &[F]) -> Self
where A: Deref<Target = [F; D]> { ... }
fn rotate_around(self, pivot: &Self, angle: F, c0: usize, c1: usize) -> Self { ... }
fn cross_product<A: AsRef<[F; 3]>>(&self, other: A) -> Self
where Self: From<[F; 3]> + AsRef<[F; 3]> { ... }
fn cross_product_arr(&self, other: &[F; 3]) -> Self
where Self: From<[F; 3]> + AsRef<[F; 3]> { ... }
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 reduce_sum(&self) -> F
fn reduce_sum(&self) -> F
Return the sum of the components
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 distance_sq<A: AsRef<[F; D]>>(&self, other: A) -> F
fn distance_sq<A: AsRef<[F; D]>>(&self, other: A) -> F
Return the square of the distance between this vector and another
Sourcefn distance_sq_arr(&self, other: &[F; D]) -> F
fn distance_sq_arr(&self, other: &[F; D]) -> F
Return the square of the distance between this vector and another array
Sourcefn distance<A: AsRef<[F; D]>>(&self, other: A) -> F
fn distance<A: AsRef<[F; D]>>(&self, other: A) -> F
Return the distance between this vector and another
Sourcefn distance_arr(&self, other: &[F; D]) -> F
fn distance_arr(&self, other: &[F; D]) -> F
Return the distance between this vector and another array
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 sum_scaled<A>(v: &[A], scales: &[F]) -> Self
fn sum_scaled<A>(v: &[A], scales: &[F]) -> Self
Create a linear combination of a number of vectors given a scale for each
If the lengths of the slices provided differ, then the entries in the longer slice (without pairs to go with) are ignored
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<A: AsRef<[F; 3]>>(&self, other: A) -> Self
fn cross_product<A: AsRef<[F; 3]>>(&self, other: A) -> Self
Cross product of two 3-element vectors
Sourcefn cross_product_arr(&self, other: &[F; 3]) -> Self
fn cross_product_arr(&self, other: &[F; 3]) -> Self
Cross product of two 3-element vectors, one as an array reference
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".