pub struct Vector3D {
    pub x: Fraction,
    pub y: Fraction,
    pub z: Fraction,
}

Fields§

§x: Fraction§y: Fraction§z: Fraction

Implementations§

Generates a new Vector3D

extern crate oxygen_quark as quark;
use quark::vector::vector3d::*;
use quark::fraction::Fraction;
 
let x = Fraction::new(3, 1);
let y = Fraction::new(6, 1);
let z = Fraction::new(2, 1);
let vector = Vector3D::new(x, y, z);
 
 
// Prints out "(x: 3, y: 6, z: 2)"
println!("{}", vector);

Adds two Vector3Ds and returns their sum.

let vector1 = Vector3D::new(x1, y1, z1);
let vector2 = Vector3D { x: x2, y: y2, z: z2 };
 
let result_vector = vector1.add(&vector2);
 
 
// Prints out "(x: 5, y: 11, z: (7/2))"
println!("{}", result_vector);

Subtracts two Vector3Ds and returns their difference.

let vector1 = Vector3D::new(x1, y1, z1);
let vector2 = Vector3D { x: x2, y: y2, z: z2 };
 
let result_vector = vector1.subtract(&vector2);
 
 
// Prints out "(x: 1, y: 1, z: (1/2))"
println!("{}", result_vector);

Returns a new Vector3D containing the product of every component in a Vector3D with the corresponding component in another one.

let vector1 = Vector3D::new(x1, y1, z1);
let vector2 = Vector3D::new(x2, y2, z2);
 
let result_vector = vector1.component_product(&vector2);
 
 
// Prints out "(x: 6, y: 30, 3)"
println!("{}", result_vector);

Returns a Fraction that is the result of the dot-product between two Vector3Ds.

use quark::fraction::Fraction;
 
let vector1 = Vector3D::new(x1, y1, z1);
let vector2 = Vector3D::new(x2, y2, z2);
 
let result = vector1.dot_product(&vector2);
 
 
// Prints out "39"
println!("{}", result);

Returns a Vector3D that is the cross-product between two other Vector3Ds.

let vector1 = Vector3D::new(x1, y1, z1);
let vector2 = Vector3D::new(x2, y2, z2);
 
let result_vector = vector1.cross_product(&vector2);
 
 
// Prints out "(x: -1, y: (-1/2), z: 3)"
println!("{}", result_vector);

Returns a scaled Vector3D.

let vector = Vector3D::new(x, y, z);
let scale = Fraction::new(5, 1);
 
 
// Prints out "(x: 25, y: 15, z: 30)"
println!("{}", vector.scale(scale));  

Returns a Fraction, the norm of the vector.

use quark::fraction::Fraction;
 
let vector = Vector3D::new(x, y, z);

 
// Prints out "7"
println!("{}", vector.norm());

Returns a normalised version of the Vector3D that was fed in.

let vector = Vector3D::new(x, y, z);
 
 
// Prints out "(x: (3/7), y: (6/7), z: (2/7))"
println!("{}", vector.normalise());

Trait Implementations§

Formats the value using the given formatter. Read more
Formats the value using the given formatter. Read more
This method returns an Ordering between self and other. Read more
Compares and returns the maximum of two values. Read more
Compares and returns the minimum of two values. Read more
Restrict a value to a certain interval. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
This method returns an ordering between self and other values if one exists. Read more
This method tests less than (for self and other) and is used by the < operator. Read more
This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
This method tests greater than (for self and other) and is used by the > operator. Read more
This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Converts the given value to a String. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.