Skip to main content

Vector

Trait Vector 

Source
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§

Source

fn is_zero(&self) -> bool

Return true if the vector is all zeros

Source

fn mix<A>(self, other: A, t: F) -> Self
where A: Deref<Target = [F; D]>,

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

Source

fn dot(&self, other: &[F; D]) -> F

Return the dot product of two vectors

Source

fn reduce_sum(&self) -> F

Return the dot product of two vectors

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: &[F; D]) -> F

Return the square of the distance between this vector and another

Source

fn distance(&self, other: &[F; D]) -> 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.

Source

fn cross_product(&self, other: &[F; 3]) -> Self
where Self: From<[F; 3]> + AsRef<[F; 3]>,

Cross product of two 3-element vectors

Source

fn apply_q3<Q>(&self, q: &Q) -> Self
where Q: Quaternion<F>, Self: From<[F; 3]> + AsRef<[F; 3]>,

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

Source

fn apply_q4<Q>(&self, q: &Q) -> Self
where Q: Quaternion<F>, Self: From<[F; 4]> + AsRef<[F; 4]>,

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

Source

fn transformed_by_m<const D2: usize>(&mut self, m: &[F; D2]) -> &mut Self
where [(); D]: IsSquared<D, D2>,

Multiply the vector by the matrix to transform it

Source

fn uniform_dist_sphere3(x: [F; 2], map: bool) -> Self
where Self: From<[F; 3]>,

Get a point on a sphere uniformly distributed for a point where x in [0,1) and y in [0,1)

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.

Implementors§

Source§

impl Vector<f32, 2> for FArray<f32, 2>

Source§

impl Vector<f32, 3> for FArray<f32, 3>

Source§

impl Vector<f32, 4> for FArray<f32, 4>

Source§

impl Vector<f32, 5> for FArray<f32, 5>

Source§

impl Vector<f32, 6> for FArray<f32, 6>

Source§

impl Vector<f32, 7> for FArray<f32, 7>

Source§

impl Vector<f32, 8> for FArray<f32, 8>

Source§

impl Vector<f32, 9> for FArray<f32, 9>

Source§

impl Vector<f32, 10> for FArray<f32, 10>

Source§

impl Vector<f32, 11> for FArray<f32, 11>

Source§

impl Vector<f32, 12> for FArray<f32, 12>

Source§

impl Vector<f32, 13> for FArray<f32, 13>

Source§

impl Vector<f32, 14> for FArray<f32, 14>

Source§

impl Vector<f32, 15> for FArray<f32, 15>

Source§

impl Vector<f32, 16> for FArray<f32, 16>

Source§

impl Vector<f64, 2> for FArray<f64, 2>

Source§

impl Vector<f64, 3> for FArray<f64, 3>

Source§

impl Vector<f64, 4> for FArray<f64, 4>

Source§

impl Vector<f64, 5> for FArray<f64, 5>

Source§

impl Vector<f64, 6> for FArray<f64, 6>

Source§

impl Vector<f64, 7> for FArray<f64, 7>

Source§

impl Vector<f64, 8> for FArray<f64, 8>

Source§

impl Vector<f64, 9> for FArray<f64, 9>

Source§

impl Vector<f64, 10> for FArray<f64, 10>

Source§

impl Vector<f64, 11> for FArray<f64, 11>

Source§

impl Vector<f64, 12> for FArray<f64, 12>

Source§

impl Vector<f64, 13> for FArray<f64, 13>

Source§

impl Vector<f64, 14> for FArray<f64, 14>

Source§

impl Vector<f64, 15> for FArray<f64, 15>

Source§

impl Vector<f64, 16> for FArray<f64, 16>