[][src]Trait nannou::prelude::VectorSpace

pub trait VectorSpace: Copy + Clone + Zero<Output = Self> + Add<Self> + Sub<Self, Output = Self> + Sum<Self> + Mul<Self::Scalar, Output = Self> + Div<Self::Scalar, Output = Self> + Rem<Self::Scalar, Output = Self> {
    type Scalar: BaseNum;
}

Vectors that can be added together and multiplied by scalars.

Examples include vectors, matrices, and quaternions.

Required operators

Vector addition

Vectors can be added, subtracted, or negated via the following traits:

  • Add<Output = Self>
  • Sub<Output = Self>
  • Neg<Output = Self>
use cgmath::Vector3;

let velocity0 = Vector3::new(1, 2, 0);
let velocity1 = Vector3::new(1, 1, 0);

let total_velocity = velocity0 + velocity1;
let velocity_diff = velocity1 - velocity0;
let reversed_velocity0 = -velocity0;

Vector spaces are also required to implement the additive identity trait, Zero. Adding this to another vector should have no effect:

use cgmath::prelude::*;
use cgmath::Vector2;

let v = Vector2::new(1, 2);
assert_eq!(v + Vector2::zero(), v);

Scalar multiplication

Vectors can be multiplied or divided by their associated scalars via the following traits:

  • Mul<Self::Scalar, Output = Self>
  • Div<Self::Scalar, Output = Self>
  • Rem<Self::Scalar, Output = Self>
use cgmath::Vector2;

let translation = Vector2::new(3.0, 4.0);
let scale_factor = 2.0;

let upscaled_translation = translation * scale_factor;
let downscaled_translation = translation / scale_factor;

Associated Types

type Scalar: BaseNum

The associated scalar.

Loading content...

Implementations on Foreign Types

impl<S> VectorSpace for Vector3<S> where
    S: BaseNum
[src]

type Scalar = S

impl<S> VectorSpace for Vector2<S> where
    S: BaseNum
[src]

type Scalar = S

impl<S> VectorSpace for Vector4<S> where
    S: BaseNum
[src]

type Scalar = S

impl<S> VectorSpace for Vector1<S> where
    S: BaseNum
[src]

type Scalar = S

Loading content...

Implementors

impl<S> VectorSpace for nannou::geom::vector::Vector2<S> where
    S: BaseNum
[src]

type Scalar = S

impl<S> VectorSpace for nannou::geom::vector::Vector3<S> where
    S: BaseNum
[src]

type Scalar = S

impl<S> VectorSpace for nannou::geom::vector::Vector4<S> where
    S: BaseNum
[src]

type Scalar = S

impl<S> VectorSpace for Matrix2<S> where
    S: BaseFloat
[src]

type Scalar = S

impl<S> VectorSpace for Matrix3<S> where
    S: BaseFloat
[src]

type Scalar = S

impl<S> VectorSpace for Matrix4<S> where
    S: BaseFloat
[src]

type Scalar = S

impl<S> VectorSpace for Quaternion<S> where
    S: BaseFloat
[src]

type Scalar = S

Loading content...