Struct fixed_vectors::Vector3
source · [−]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
sourceimpl<T> Vector3<T>
impl<T> Vector3<T>
sourcepub const fn new(x: T, y: T, z: T) -> Self
pub const fn new(x: T, y: T, z: T) -> Self
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);
sourcepub fn to_array(self) -> [T; 3]
pub fn to_array(self) -> [T; 3]
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]);
sourcepub fn to_tuple(self) -> (T, T, T)
pub fn to_tuple(self) -> (T, T, T)
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));
sourceimpl<T: Float> Vector3<T>
impl<T: Float> Vector3<T>
sourcepub fn zero(self) -> Self
pub fn zero(self) -> Self
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));
sourcepub fn floor(self) -> Self
pub fn floor(self) -> Self
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));
sourcepub fn ceil(self) -> Self
pub fn ceil(self) -> Self
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));
sourcepub fn round(self) -> Self
pub fn round(self) -> Self
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));
sourcepub fn abs(self) -> Self
pub fn abs(self) -> Self
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));
sourcepub fn trunc(self) -> Self
pub fn trunc(self) -> Self
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));
sourcepub fn fract(self) -> Self
pub fn fract(self) -> Self
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);
sourcepub fn sqrt(self) -> Self
pub fn sqrt(self) -> Self
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));
sourcepub fn powi(self, n: i32) -> Self
pub fn powi(self, n: i32) -> Self
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));
sourcepub fn powf(self, n: T) -> Self
pub fn powf(self, n: T) -> Self
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));
sourcepub fn lerp(self, to: Self, weight: T) -> Self
pub fn lerp(self, to: Self, weight: T) -> Self
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));
sourcepub fn normalized(self) -> Self
pub fn normalized(self) -> Self
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);
sourcepub fn dot(self, b: Self) -> T
pub fn dot(self, b: Self) -> T
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);
sourcepub fn length_squared(self) -> T
pub fn length_squared(self) -> T
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);
Trait Implementations
sourceimpl<T: Add<Output = T> + Copy> AddAssign<Vector3<T>> for Vector3<T>
impl<T: Add<Output = T> + Copy> AddAssign<Vector3<T>> for Vector3<T>
sourcefn add_assign(&mut self, other: Self)
fn add_assign(&mut self, other: Self)
Performs the +=
operation. Read more
sourceimpl<T: BitAnd<Output = T> + Copy> BitAndAssign<Vector3<T>> for Vector3<T>
impl<T: BitAnd<Output = T> + Copy> BitAndAssign<Vector3<T>> for Vector3<T>
sourcefn bitand_assign(&mut self, other: Self)
fn bitand_assign(&mut self, other: Self)
Performs the &=
operation. Read more
sourceimpl<T: BitOr<Output = T> + Copy> BitOrAssign<Vector3<T>> for Vector3<T>
impl<T: BitOr<Output = T> + Copy> BitOrAssign<Vector3<T>> for Vector3<T>
sourcefn bitor_assign(&mut self, other: Self)
fn bitor_assign(&mut self, other: Self)
Performs the |=
operation. Read more
sourceimpl<T: BitXor<Output = T> + Copy> BitXorAssign<Vector3<T>> for Vector3<T>
impl<T: BitXor<Output = T> + Copy> BitXorAssign<Vector3<T>> for Vector3<T>
sourcefn bitxor_assign(&mut self, other: Self)
fn bitxor_assign(&mut self, other: Self)
Performs the ^=
operation. Read more
sourceimpl<T: Div<Output = T> + Copy> DivAssign<Vector3<T>> for Vector3<T>
impl<T: Div<Output = T> + Copy> DivAssign<Vector3<T>> for Vector3<T>
sourcefn div_assign(&mut self, other: Self)
fn div_assign(&mut self, other: Self)
Performs the /=
operation. Read more
sourceimpl<T> IntoIterator for Vector3<T>
impl<T> IntoIterator for Vector3<T>
sourceimpl<T: Mul<Output = T> + Copy> MulAssign<Vector3<T>> for Vector3<T>
impl<T: Mul<Output = T> + Copy> MulAssign<Vector3<T>> for Vector3<T>
sourcefn mul_assign(&mut self, other: Self)
fn mul_assign(&mut self, other: Self)
Performs the *=
operation. Read more
sourceimpl<T: PartialEq> PartialEq<Vector3<T>> for Vector3<T>
impl<T: PartialEq> PartialEq<Vector3<T>> for Vector3<T>
sourceimpl<T: Rem<Output = T> + Copy> RemAssign<Vector3<T>> for Vector3<T>
impl<T: Rem<Output = T> + Copy> RemAssign<Vector3<T>> for Vector3<T>
sourcefn rem_assign(&mut self, other: Self)
fn rem_assign(&mut self, other: Self)
Performs the %=
operation. Read more
sourceimpl<T: Sub<Output = T> + Copy> SubAssign<Vector3<T>> for Vector3<T>
impl<T: Sub<Output = T> + Copy> SubAssign<Vector3<T>> for Vector3<T>
sourcefn sub_assign(&mut self, other: Self)
fn sub_assign(&mut self, other: Self)
Performs the -=
operation. Read more
impl<T: Eq> Eq for Vector3<T>
Auto Trait Implementations
impl<T> RefUnwindSafe for Vector3<T> where
T: RefUnwindSafe,
impl<T> Send for Vector3<T> where
T: Send,
impl<T> Sync for Vector3<T> where
T: Sync,
impl<T> Unpin for Vector3<T> where
T: Unpin,
impl<T> UnwindSafe for Vector3<T> where
T: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more