Vector

Trait Vector 

Source
pub trait Vector<T, Rhs = Self, Output = Self>:
    Add<Rhs, Output = Output>
    + Sub<Rhs, Output = Output>
    + Mul<Rhs, Output = Output, Output = Output>
    + Mul<T>
    + Div<Rhs, Output = Output, Output = Output>
    + Div<T>
    + Neg<Output = Output>
    + Clone
    + Copy
where T: Scalar,
{ // Required methods fn zero() -> Self; fn add_vv(l: &Self, r: &Self) -> Self; fn sub_vv(l: &Self, r: &Self) -> Self; fn mul_vv(l: &Self, r: &Self) -> Self; fn div_vv(l: &Self, r: &Self) -> Self; fn mul_vs(l: &Self, r: T) -> Self; fn div_vs(l: &Self, r: T) -> Self; fn rem_vv(l: &Self, r: &Self) -> Self; fn dot(l: &Self, r: &Self) -> T; fn min(l: &Self, r: &Self) -> Self; fn max(l: &Self, r: &Self) -> Self; }
Expand description

Generic vector trait defining common vector operations.

This trait provides the foundation for all vector types, defining operations like addition, subtraction, dot product, and component-wise operations.

§Mathematical Operations

For vectors v and w, and scalar s:

  • Addition: v + w = (v₁ + w₁, v₂ + w₂, …)
  • Subtraction: v - w = (v₁ - w₁, v₂ - w₂, …)
  • Scalar multiplication: sv = (sv₁, sv₂, …)
  • Dot product: v · w = v₁w₁ + v₂w₂ + …

Required Methods§

Source

fn zero() -> Self

Returns the zero vector (all components are zero).

Source

fn add_vv(l: &Self, r: &Self) -> Self

Adds two vectors component-wise.

Source

fn sub_vv(l: &Self, r: &Self) -> Self

Subtracts two vectors component-wise.

Source

fn mul_vv(l: &Self, r: &Self) -> Self

Multiplies two vectors component-wise (Hadamard product).

Source

fn div_vv(l: &Self, r: &Self) -> Self

Divides two vectors component-wise.

Source

fn mul_vs(l: &Self, r: T) -> Self

Multiplies a vector by a scalar.

Source

fn div_vs(l: &Self, r: T) -> Self

Divides a vector by a scalar.

Source

fn rem_vv(l: &Self, r: &Self) -> Self

Computes the remainder of component-wise division.

Source

fn dot(l: &Self, r: &Self) -> T

Computes the dot product of two vectors.

For vectors v and w:

v · w = Σᵢ vᵢwᵢ
Source

fn min(l: &Self, r: &Self) -> Self

Returns a vector with the minimum components from both vectors.

Source

fn max(l: &Self, r: &Self) -> Self

Returns a vector with the maximum components from both vectors.

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<T> Vector<T> for Vector2<T>
where T: Scalar,

Source§

impl<T> Vector<T> for Vector3<T>
where T: Scalar,

Source§

impl<T> Vector<T> for Vector4<T>
where T: Scalar,