Trait Vector

Source
pub trait Vector {
    type VectorType;

    // Required methods
    fn zeros() -> Self::VectorType;
    fn ones() -> Self::VectorType;
    fn mul(&self, rhs: &[f32]) -> Self::VectorType;
    fn add(&self, rhs: &[f32]) -> Self::VectorType;
    fn sub(&self, rhs: &[f32]) -> Self::VectorType;
    fn scale(&self, factor: f32) -> Self::VectorType;
    fn mag(&self) -> f32;
    fn mag2(&self) -> f32;
    fn dot(&self, rhs: &[f32]) -> f32;
}
Expand description

The base Vector trait

Note that vector operations are permitted on slices. This is useful for WebGl vertex storages, where many vectors are stored in a single array. The caveat obviously is the potential for errors. Sadly there is no secure alternative for handling this use-case.

Required Associated Types§

Required Methods§

Source

fn zeros() -> Self::VectorType

Create a vector filled with zeros

Source

fn ones() -> Self::VectorType

Create a vector filled with ones

Source

fn mul(&self, rhs: &[f32]) -> Self::VectorType

Perform element-wise multiplication with the given right-hand-side operand

Source

fn add(&self, rhs: &[f32]) -> Self::VectorType

Perform element-wise addition with the given right-hand-side operand

Source

fn sub(&self, rhs: &[f32]) -> Self::VectorType

Perform element-wise substraction with the given right-hand-side operand

Source

fn scale(&self, factor: f32) -> Self::VectorType

Scale the vector elment-wise by the given constant

Source

fn mag(&self) -> f32

Calculate the magnitude of this vector

Source

fn mag2(&self) -> f32

Calculate the squared magnitude of this vector

Source

fn dot(&self, rhs: &[f32]) -> f32

Calculate the dot product of this vector and the given right-hand-side operand

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§