Struct Vector3

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

Vector for holding three-dimensional values.

§Example

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

Fields§

§x: T§y: T§z: T

Implementations§

Source§

impl<T> Vector3<T>

Source

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 vec2 = Vector2::new(0, 0);
 
assert_eq!(vec2.x, 0);
assert_eq!(vec2.y, 0);
Source

pub fn to_array(self) -> [T; 3]

Consumes the vector and returns its values as an array.

§Example
use fixed_vectors::Vector2;
 
let vec2 = Vector2::new(0, 0);
let array = vec2.to_array();
 
assert_eq!(array, [0, 0]);
Source

pub fn to_tuple(self) -> (T, T, T)

Consumes the vector and returns its values as a tuple.

§Example
use fixed_vectors::Vector2;
 
let vec2 = Vector2::new(0, 0);
let tuple = vec2.to_tuple();
 
assert_eq!(tuple, (0, 0));
Source

pub fn map<F, U>(self, f: F) -> Vector3<U>
where F: Fn(T) -> U,

Consumes the vector and returns a new vector with the given function applied on each field.

§Example
use fixed_vectors::Vector2;
 
let vec2 = Vector2::new(1, 2)
    .map(|i| i * 2);
 
assert_eq!(vec2, Vector2::new(2, 4));
Source§

impl<T: Copy> Vector3<T>

Source

pub const fn from_value(value: T) -> Self

Constructs a vector using the given value as the value for all of its fields.

§Example
use fixed_vectors::Vector2;
 
let vec2 = Vector2::from_value(0);
 
assert_eq!(vec2, Vector2::new(0, 0));
Source§

impl<T: FloatCore> Vector3<T>

Source

pub fn dot(&self, other: &Self) -> T

Returns the dot product of two vectors.

§Example
use fixed_vectors::Vector2;
 
let a = Vector2::new(1.0, 2.0);
let b = Vector2::new(2.0, 4.0);
let dot = a.dot(&b);
 
assert_eq!(dot, 10.0);
Source

pub fn length_squared(&self) -> T

Returns the squared magnitude of vector.

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

pub fn floor(self) -> Self

Applies floor on all fields within the vector, converting each field to the largest integer less than or equal to its value.

§Example
use fixed_vectors::Vector2;
 
let vec2 = Vector2::new(1.6, 2.3).floor();
 
assert_eq!(vec2, Vector2::new(1.0, 2.0));
Source

pub fn ceil(self) -> Self

Applies ceil on all fields within the vector, converting each field to the largest integer greater than or equal to its value.

§Example
use fixed_vectors::Vector2;
 
let vec2 = Vector2::new(1.6, 2.3).ceil();
 
assert_eq!(vec2, Vector2::new(2.0, 3.0));
Source

pub fn round(self) -> Self

Applies round on all fields within the vector, converting each field’s value to its nearest integer.

§Example
use fixed_vectors::Vector2;
 
let vec2 = Vector2::new(1.6, 2.3).round();
 
assert_eq!(vec2, Vector2::new(2.0, 2.0));
Source

pub fn abs(self) -> Self

Applies abs on all fields within the vector, converting each field to their absolute value.

§Example
use fixed_vectors::Vector2;
 
let vec2 = Vector2::new(-2.6, 2.3).abs();
 
assert_eq!(vec2, Vector2::new(2.6, 2.3));
Source

pub fn trunc(self) -> Self

Applies trunc on all fields within the vector, converting each field’s value to their integer parts.

§Example
use fixed_vectors::Vector2;
 
let vec2 = Vector2::new(-2.6, 2.3).trunc();
 
assert_eq!(vec2, Vector2::new(-2.0, 2.0));
Source

pub fn fract(self) -> Self

Applies fract on all fields within the vector, converting each field’s value to their fractional parts.

§Example
use fixed_vectors::Vector2;
 
let vec2 = Vector2::new(-2.5, 2.25).fract();
 
assert_eq!(vec2, Vector2::new(-0.5, 0.25));
Source

pub fn powi(self, n: i32) -> Self

Applies powi on all fields within the vector, raising each field’s value to an integer power.

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

pub fn lerp(self, to: Self, weight: T) -> Self

Linearly interpolates between two Vectors by a normalized weight.

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

impl<T> Vector3<T>
where T: _FloatingPoint + FloatCore,

Source

pub fn sqrt(self) -> Self

Consumes the vector and returns it with all of its fields converted to their square-root.

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

pub fn length(&self) -> T

Returns the magnitude of the vector.

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

pub fn normalized(self) -> Self

Consumes the vector and returns it as normalized vector.

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

pub fn normalize(&mut self)

Normalizes the vector through mutation.

§Example
use fixed_vectors::Vector2;
 
let mut vec2 = Vector2::new(14.3, 7.9);
vec2.normalize();
 
assert!(vec2.x < 1.0);
assert!(vec2.y < 1.0);

Trait Implementations§

Source§

impl<T: Add<Output = T> + Copy> Add<T> for Vector3<T>

Source§

type Output = Vector3<T>

The resulting type after applying the + operator.
Source§

fn add(self, other: T) -> Self::Output

Performs the + operation. Read more
Source§

impl<T: Add<Output = T>> Add for Vector3<T>

Source§

type Output = Vector3<T>

The resulting type after applying the + operator.
Source§

fn add(self, other: Self) -> Self::Output

Performs the + operation. Read more
Source§

impl<T: AddAssign + Copy> AddAssign<T> for Vector3<T>

Source§

fn add_assign(&mut self, other: T)

Performs the += operation. Read more
Source§

impl<T: AddAssign> AddAssign for Vector3<T>

Source§

fn add_assign(&mut self, other: Self)

Performs the += operation. Read more
Source§

impl<T: BitAnd<Output = T> + Copy> BitAnd<T> for Vector3<T>

Source§

type Output = Vector3<T>

The resulting type after applying the & operator.
Source§

fn bitand(self, other: T) -> Self::Output

Performs the & operation. Read more
Source§

impl<T: BitAnd<Output = T>> BitAnd for Vector3<T>

Source§

type Output = Vector3<T>

The resulting type after applying the & operator.
Source§

fn bitand(self, other: Self) -> Self::Output

Performs the & operation. Read more
Source§

impl<T: BitAndAssign + Copy> BitAndAssign<T> for Vector3<T>

Source§

fn bitand_assign(&mut self, other: T)

Performs the &= operation. Read more
Source§

impl<T: BitAndAssign> BitAndAssign for Vector3<T>

Source§

fn bitand_assign(&mut self, other: Self)

Performs the &= operation. Read more
Source§

impl<T: BitOr<Output = T> + Copy> BitOr<T> for Vector3<T>

Source§

type Output = Vector3<T>

The resulting type after applying the | operator.
Source§

fn bitor(self, other: T) -> Self::Output

Performs the | operation. Read more
Source§

impl<T: BitOr<Output = T>> BitOr for Vector3<T>

Source§

type Output = Vector3<T>

The resulting type after applying the | operator.
Source§

fn bitor(self, other: Self) -> Self::Output

Performs the | operation. Read more
Source§

impl<T: BitOrAssign + Copy> BitOrAssign<T> for Vector3<T>

Source§

fn bitor_assign(&mut self, other: T)

Performs the |= operation. Read more
Source§

impl<T: BitOrAssign> BitOrAssign for Vector3<T>

Source§

fn bitor_assign(&mut self, other: Self)

Performs the |= operation. Read more
Source§

impl<T: BitXor<Output = T> + Copy> BitXor<T> for Vector3<T>

Source§

type Output = Vector3<T>

The resulting type after applying the ^ operator.
Source§

fn bitxor(self, other: T) -> Self::Output

Performs the ^ operation. Read more
Source§

impl<T: BitXor<Output = T>> BitXor for Vector3<T>

Source§

type Output = Vector3<T>

The resulting type after applying the ^ operator.
Source§

fn bitxor(self, other: Self) -> Self::Output

Performs the ^ operation. Read more
Source§

impl<T: BitXorAssign + Copy> BitXorAssign<T> for Vector3<T>

Source§

fn bitxor_assign(&mut self, other: T)

Performs the ^= operation. Read more
Source§

impl<T: BitXorAssign> BitXorAssign for Vector3<T>

Source§

fn bitxor_assign(&mut self, other: Self)

Performs the ^= operation. Read more
Source§

impl<T: Clone> Clone for Vector3<T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

const fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for Vector3<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Default> Default for Vector3<T>

Source§

fn default() -> Self

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

impl<T: Div<Output = T> + Copy> Div<T> for Vector3<T>

Source§

type Output = Vector3<T>

The resulting type after applying the / operator.
Source§

fn div(self, other: T) -> Self::Output

Performs the / operation. Read more
Source§

impl<T: Div<Output = T>> Div for Vector3<T>

Source§

type Output = Vector3<T>

The resulting type after applying the / operator.
Source§

fn div(self, other: Self) -> Self::Output

Performs the / operation. Read more
Source§

impl<T: DivAssign + Copy> DivAssign<T> for Vector3<T>

Source§

fn div_assign(&mut self, other: T)

Performs the /= operation. Read more
Source§

impl<T: DivAssign> DivAssign for Vector3<T>

Source§

fn div_assign(&mut self, other: Self)

Performs the /= operation. Read more
Source§

impl<T> From<[T; 3]> for Vector3<T>

Source§

fn from(from: [T; 3]) -> Self

Converts to this type from the input type.
Source§

impl<T> From<(T, T, T)> for Vector3<T>

Source§

fn from(from: (T, T, T)) -> Self

Converts to this type from the input type.
Source§

impl<T: Hash> Hash for Vector3<T>

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

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

impl<T: Mul<Output = T> + Copy> Mul<T> for Vector3<T>

Source§

type Output = Vector3<T>

The resulting type after applying the * operator.
Source§

fn mul(self, other: T) -> Self::Output

Performs the * operation. Read more
Source§

impl<T: Mul<Output = T>> Mul for Vector3<T>

Source§

type Output = Vector3<T>

The resulting type after applying the * operator.
Source§

fn mul(self, other: Self) -> Self::Output

Performs the * operation. Read more
Source§

impl<T: MulAssign + Copy> MulAssign<T> for Vector3<T>

Source§

fn mul_assign(&mut self, other: T)

Performs the *= operation. Read more
Source§

impl<T: MulAssign> MulAssign for Vector3<T>

Source§

fn mul_assign(&mut self, other: Self)

Performs the *= operation. Read more
Source§

impl<T: Neg<Output = T>> Neg for Vector3<T>

Source§

type Output = Vector3<T>

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
Source§

impl<T: PartialEq> PartialEq for Vector3<T>

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

const fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: Rem<Output = T> + Copy> Rem<T> for Vector3<T>

Source§

type Output = Vector3<T>

The resulting type after applying the % operator.
Source§

fn rem(self, other: T) -> Self::Output

Performs the % operation. Read more
Source§

impl<T: Rem<Output = T>> Rem for Vector3<T>

Source§

type Output = Vector3<T>

The resulting type after applying the % operator.
Source§

fn rem(self, other: Self) -> Self::Output

Performs the % operation. Read more
Source§

impl<T: RemAssign + Copy> RemAssign<T> for Vector3<T>

Source§

fn rem_assign(&mut self, other: T)

Performs the %= operation. Read more
Source§

impl<T: RemAssign> RemAssign for Vector3<T>

Source§

fn rem_assign(&mut self, other: Self)

Performs the %= operation. Read more
Source§

impl<T: Sub<Output = T> + Copy> Sub<T> for Vector3<T>

Source§

type Output = Vector3<T>

The resulting type after applying the - operator.
Source§

fn sub(self, other: T) -> Self::Output

Performs the - operation. Read more
Source§

impl<T: Sub<Output = T>> Sub for Vector3<T>

Source§

type Output = Vector3<T>

The resulting type after applying the - operator.
Source§

fn sub(self, other: Self) -> Self::Output

Performs the - operation. Read more
Source§

impl<T: SubAssign + Copy> SubAssign<T> for Vector3<T>

Source§

fn sub_assign(&mut self, other: T)

Performs the -= operation. Read more
Source§

impl<T: SubAssign> SubAssign for Vector3<T>

Source§

fn sub_assign(&mut self, other: Self)

Performs the -= operation. Read more
Source§

impl<T: Copy> Copy for Vector3<T>

Source§

impl<T: Eq> Eq for Vector3<T>

Auto Trait Implementations§

§

impl<T> Freeze for Vector3<T>
where T: Freeze,

§

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§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T, Rhs> NumAssignOps<Rhs> for T
where T: AddAssign<Rhs> + SubAssign<Rhs> + MulAssign<Rhs> + DivAssign<Rhs> + RemAssign<Rhs>,

Source§

impl<T, Rhs, Output> NumOps<Rhs, Output> for T
where T: Sub<Rhs, Output = Output> + Mul<Rhs, Output = Output> + Div<Rhs, Output = Output> + Add<Rhs, Output = Output> + Rem<Rhs, Output = Output>,