Module eschers::vector [] [src]

2D vectors and associated functions

Vectors are used to represent locations in the two dimensional plane.

Vectors can be added.

let u = Vector::new(1f64, 0f64);
let v = Vector::new(0f64, 1f64);

let w = u.add(&v);

assert_eq!(w, Vector::new(1f64, 1f64));

You can negate a vector.


let w = u.neg();

assert_eq!(w, Vector::new(-1f64, 0f64));

Subtraction of two vectors is also an option.


let w = u.sub(&v);

assert_eq!(w, Vector::new(1f64, -1f64));

Just as scaling a vector.


let w = u.scale(&2f64);

assert_eq!(w, Vector::new(2f64, 0f64));

Finally with a Vector<f64> you can determine their length.

let t = Vector::new(3f64, 4f64);

assert_eq!(5f64, t.length());

Note that all the methods that return a Vector, do so by returning a new structure.

Structs

Vector

Representation of two dimensional vector