[][src]Trait cgmath::VectorSpace

pub trait VectorSpace: Copy + Clone where
    Self: Zero,
    Self: Add<Self, Output = Self>,
    Self: Sub<Self, Output = Self>,
    Self: Sum<Self>,
    Self: Mul<Self::Scalar, Output = Self>,
    Self: Div<Self::Scalar, Output = Self>,
    Self: Rem<Self::Scalar, Output = Self>, 
{ type Scalar: BaseNum; fn lerp(self, other: Self, amount: Self::Scalar) -> Self { ... } }

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:

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:

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...

Provided methods

fn lerp(self, other: Self, amount: Self::Scalar) -> Self

Returns the result of linearly interpolating the vector towards other by the specified amount.

Loading content...

Implementors

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

type Scalar = S

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

type Scalar = S

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

type Scalar = S

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

type Scalar = S

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

type Scalar = S

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

type Scalar = S

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

type Scalar = S

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

type Scalar = S

Loading content...