Trait geo_nd::Vector

source ·
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§

source

fn from_array(data: [F; D]) -> Self

Create a vector from an array of Float

source

fn zero() -> Self

Create a vector whose elements are all zero

source

fn into_array(self) -> [F; D]

Create a vector from an array of Float

source

fn is_zero(&self) -> bool

Return true if the vector is all zeros

source

fn set_zero(&mut self)

Set the vector to be all zeros

source

fn reduce_sum(&self) -> F

Sum all of the components of the vector

source

fn mix(self, other: &Self, t: F) -> Self

Create a linear combination of this Vector and another using parameter t from zero to one

source

fn dot(&self, other: &Self) -> F

Return the dot product of two vectors

Provided Methods§

source

fn length_sq(&self) -> F

Return the square of the length of the vector

source

fn length(&self) -> F

Return the length of the vector

source

fn distance_sq(&self, other: &Self) -> F

Return the square of the distance between this vector and another

source

fn distance(&self, other: &Self) -> F

Return the distance between this vector and another

source

fn normalize(self) -> Self

Normalize the vector; if its length is close to zero, then set it to be zero

source

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.

Implementors§

source§

impl<F: Float, const D: usize> Vector<F, D> for FArray<F, D>