pub trait Vector<F: Float, const D: usize>: Clone + Copy + Debug + Display + Default + AsRef<[F; D]> + AsMut<[F; D]> + AsRef<[F]> + AsMut<[F]> + Index<usize, Output = F> + IndexMut<usize> + Neg<Output = Self> + Add<Self, Output = Self> + Add<F, Output = Self> + AddAssign<Self> + AddAssign<F> + Sub<Self, Output = Self> + Sub<F, Output = Self> + SubAssign<Self> + SubAssign<F> + Mul<Self, Output = Self> + Mul<F, Output = Self> + MulAssign<Self> + MulAssign<F> + Div<Self, Output = Self> + Div<F, Output = Self> + DivAssign<Self> + DivAssign<F> {
Show 14 methods
// Required methods
fn from_array(data: [F; D]) -> Self;
fn zero() -> Self;
fn into_array(self) -> [F; D];
fn is_zero(&self) -> bool;
fn set_zero(&mut self);
fn reduce_sum(&self) -> F;
fn mix(self, other: &Self, t: F) -> Self;
fn dot(&self, other: &Self) -> F;
// Provided methods
fn length_sq(&self) -> F { ... }
fn length(&self) -> F { ... }
fn distance_sq(&self, other: &Self) -> F { ... }
fn distance(&self, other: &Self) -> F { ... }
fn normalize(self) -> Self { ... }
fn rotate_around(self, pivot: &Self, angle: F, c0: usize, c1: usize) -> Self { ... }
}
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.
Required Methods§
sourcefn from_array(data: [F; D]) -> Self
fn from_array(data: [F; D]) -> Self
Create a vector from an array of Float
sourcefn into_array(self) -> [F; D]
fn into_array(self) -> [F; D]
Create a vector from an array of Float
sourcefn reduce_sum(&self) -> F
fn reduce_sum(&self) -> F
Sum all of the components of the vector
Provided Methods§
sourcefn distance_sq(&self, other: &Self) -> F
fn distance_sq(&self, other: &Self) -> 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.