pub struct Vector3<T> {
    pub x: T,
    pub y: T,
    pub z: T,
}
Expand description

A Vector for holding three dimensional-values.

Example

use fixed_vectors::Vector3;
 
let vec3 = Vector3::new(1, 2, 3);
assert_eq!(vec3.x, 1);
assert_eq!(vec3.y, 2);
assert_eq!(vec3.z, 3);

Fields

x: T

Field holding the first dimensional-value.

y: T

Field holding the second dimensional-value.

z: T

Field holding the third dimensional-value.

Implementations

Constructs a new Vector with the specified values for each field.

Example
use fixed_vectors::Vector2;
 
let vec = Vector2::new(1, 2);
assert_eq!(vec.x, 1);
assert_eq!(vec.y, 2);

Returns the number of fields within the Vector as a usize.

Example
use fixed_vectors::Vector2;
 
let size = Vector2::new(1, 2).size();
assert_eq!(size, 2);

Connsumes the given Vector transforming it into an array.

Example
use fixed_vectors::Vector2;
 
let arr = Vector2::new(1, 2).to_array();
assert_eq!(arr, [1, 2]);

Consumes the given Vector transforming it into a tuple.

Example
use fixed_vectors::Vector2;
 
let tuple = Vector2::new(1, 2).to_tuple();
assert_eq!(tuple, (1, 2));

Consumes the given Vector transforming it into a Vec.

Example
use fixed_vectors::Vector2;
 
let vec = Vector2::new(1, 2).to_vec();
assert_eq!(vec, vec![1, 2]);

Takes a closure and creates a Vector that called the given closure on each field.

Example
use fixed_vectors::Vector2;
 
let vec = Vector2::new(1, 2)
    .map(|i| i as f64);
assert_eq!(vec, Vector2::new(1.0, 2.0));

Converts all numbers within the Vector to zero.

Example
use fixed_vectors::Vector2;
 
let vector = Vector2::new(1.0, 2.0).zero();
assert_eq!(vector, Vector2::new(0.0, 0.0));

Converts all numbers within the Vector to largest integer less than or equal to the value.

Example
use fixed_vectors::Vector2;
 
let vector = Vector2::new(1.25, 5.9).floor();
assert_eq!(vector, Vector2::new(1.0, 5.0));

Converts all numbers within the Vector to largest integer greater than or equal to the value.

Example
use fixed_vectors::Vector2;
 
let vector = Vector2::new(1.25, 5.9).ceil();
assert_eq!(vector, Vector2::new(2.0, 6.0));

Converts all numbers within the Vector to the nearest integer.

Example
use fixed_vectors::Vector2;
 
let vector = Vector2::new(1.25, 5.9).round();
assert_eq!(vector, Vector2::new(1.0, 6.0));

Converts all numbers within the Vector to their absolute value.

Example
use fixed_vectors::Vector2;
 
let vector = Vector2::new(-1.0, 1.0).abs();
assert_eq!(vector, Vector2::new(1.0, 1.0));

Converts all numbers within the Vector to their integer parts.

Example
use fixed_vectors::Vector2;
 
let vector = Vector2::new(1.337, 2.5).trunc();
assert_eq!(vector, Vector2::new(1.0, 2.0));

Converts all numbers within the Vector to their fractional parts.

Example
use fixed_vectors::Vector2;
 
let vector = Vector2::new(1.337, 2.5).fract();
assert!(vector.x <= 0.337);
assert!(vector.y <= 0.5);

Converts all numbers within the Vector to their square-root.

Example
use fixed_vectors::Vector2;
 
let vector = Vector2::new(64.0, 25.0).sqrt();
assert_eq!(vector, Vector2::new(8.0, 5.0));

Raises all numbers within the Vector to an integer power.

Example
use fixed_vectors::Vector2;
 
let vector = Vector2::new(2.0, 4.0).powi(2);
assert_eq!(vector, Vector2::new(4.0, 16.0));

Raises all numbers within the Vector to a floating-point power.

Example
use fixed_vectors::Vector2;
 
let vector = Vector2::new(2.0, 4.0).powf(2.0);
assert_eq!(vector, Vector2::new(4.0, 16.0));

Linearly interpolates between two Vectors by a normalized weight.

Example
use fixed_vectors::Vector2;
 
let vector = Vector2::new(1.0, 2.0).lerp(Vector2::new(2.0, 3.0), 1.0);
assert_eq!(vector, Vector2::new(2.0, 3.0));

Normalizes the Vector.

Example
use fixed_vectors::Vector2;
 
let vector = Vector2::new(14.3, 7.9).normalized();
assert!(vector.x < 1.0);
assert!(vector.y < 1.0);

Returns the dot product of two Vectors, this can be used to compare the angle between two Vectors.

Example
use fixed_vectors::Vector2;
 
let dot = Vector2::new(1.0, 2.0).dot(Vector2::new(2.0, 4.0));
assert_eq!(dot, 16.0);

Returns the squared magnitude of the Vector. This will always run faster than [length] and should be prefered over it if applicable.

Example
use fixed_vectors::Vector3;
 
let lsq = Vector3::new(3.33, 2.04, 1.337).length_squared();
assert!(lsq >= 17.0);

Returns the magnitude of the Vector.

Example
use fixed_vectors::Vector3;
 
let len = Vector3::new(1.5, 2.0, 3.33).length();
assert!(len < 4.2);

Returns a normalized Vector pointing from it to to.

Example
use fixed_vectors::Vector2;
 
let from = Vector2::new(1.0, 2.0);
let to = Vector2::new(5.0, 6.0);
 
let dir = from.direction(to);
assert!(dir.x < 1.0);
assert!(dir.y < 1.0);

Trait Implementations

The resulting type after applying the + operator.

Performs the + operation. Read more

Performs the += operation. Read more

The resulting type after applying the & operator.

Performs the & operation. Read more

Performs the &= operation. Read more

The resulting type after applying the | operator.

Performs the | operation. Read more

Performs the |= operation. Read more

The resulting type after applying the ^ operator.

Performs the ^ operation. Read more

Performs the ^= operation. Read more

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Formats the value using the given formatter. Read more

The resulting type after applying the / operator.

Performs the / operation. Read more

Performs the /= operation. Read more

Converts to this type from the input type.

Converts to this type from the input type.

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

Which kind of iterator are we turning this into?

The type of the elements being iterated over.

Creates an iterator from a value. Read more

The resulting type after applying the * operator.

Performs the * operation. Read more

Performs the *= operation. Read more

The resulting type after applying the - operator.

Performs the unary - operation. 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

The resulting type after applying the % operator.

Performs the % operation. Read more

Performs the %= operation. Read more

The resulting type after applying the - operator.

Performs the - operation. Read more

Performs the -= operation. Read more

The type returned in the event of a conversion error.

Performs the conversion.

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.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

Uses borrowed data to replace owned data, usually by cloning. Read more

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.