Struct fixed_vectors::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>

§

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<Vector3<T>> for Vector3<T>

§

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<Vector3<T>> 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>

§

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<Vector3<T>> for Vector3<T>

§

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<Vector3<T>> 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>

§

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<Vector3<T>> for Vector3<T>

§

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<Vector3<T>> 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>

§

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<Vector3<T>> for Vector3<T>

§

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<Vector3<T>> 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 copy of the value. Read more
1.0.0 · source§

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>

§

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<Vector3<T>> for Vector3<T>

§

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<Vector3<T>> 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>

§

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<Vector3<T>> for Vector3<T>

§

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<Vector3<T>> 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>

§

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<Vector3<T>> for Vector3<T>

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method 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>

§

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<Vector3<T>> for Vector3<T>

§

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<Vector3<T>> 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>

§

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<Vector3<T>> for Vector3<T>

§

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<Vector3<T>> 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> 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 Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. 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 Twhere 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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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 Twhere T: AddAssign<Rhs> + SubAssign<Rhs> + MulAssign<Rhs> + DivAssign<Rhs> + RemAssign<Rhs>,

source§

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