Skip to main content

Vector

Struct Vector 

Source
pub struct Vector<const N: usize>(pub [f64; N]);
Expand description

An N-dimensional vector representing a direction or displacement.

Tuple Fields§

§0: [f64; N]

Implementations§

Source§

impl<const N: usize> Vector<N>

Source

pub fn length_squared(self) -> f64

Squared Euclidean length (avoids a sqrt).

Source

pub fn length(self) -> f64

Euclidean length.

Source

pub fn normalize(self) -> Result<Self, MathError>

Return a unit-length vector in the same direction.

§Errors

Returns MathError::ZeroVector if the vector is zero, has denormalized length (< f64::MIN_POSITIVE), or has overflowed length (non-finite).

Source§

impl Vector<2>

Source

pub const fn new(x: f64, y: f64) -> Self

Create a new 2D vector.

Source

pub const fn x(self) -> f64

X component.

Source

pub const fn y(self) -> f64

Y component.

Source

pub fn dot(self, rhs: Self) -> f64

Dot product of two 2D vectors.

Source§

impl Vector<3>

Source

pub const fn new(x: f64, y: f64, z: f64) -> Self

Create a new 3D vector.

Source

pub const fn x(self) -> f64

X component.

Source

pub const fn y(self) -> f64

Y component.

Source

pub const fn z(self) -> f64

Z component.

Source

pub fn dot(self, rhs: Self) -> f64

Dot product of two 3D vectors.

Source

pub fn cross(self, rhs: Self) -> Self

Cross product of two 3D vectors.

Trait Implementations§

Source§

impl<const N: usize> Add for Vector<N>

Source§

type Output = Vector<N>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Self) -> Self

Performs the + operation. Read more
Source§

impl<const N: usize> Add<Vector<N>> for Position<N>

Translate a point by a vector: point + vector → point.

Source§

type Output = Position<N>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Vector<N>) -> Self

Performs the + operation. Read more
Source§

impl<const N: usize> AddAssign for Vector<N>

Source§

fn add_assign(&mut self, rhs: Self)

Performs the += operation. Read more
Source§

impl<const N: usize> Clone for Vector<N>

Source§

fn clone(&self) -> Vector<N>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<const N: usize> Copy for Vector<N>

Source§

impl<const N: usize> Debug for Vector<N>

Source§

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

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

impl<'de, const N: usize> Deserialize<'de> for Vector<N>

Available on crate feature serde only.
Source§

fn deserialize<D: Deserializer<'de>>(de: D) -> Result<Self, D::Error>

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<const N: usize> Mul<Vector<N>> for f64

scalar * vector

Source§

type Output = Vector<N>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Vector<N>) -> Vector<N>

Performs the * operation. Read more
Source§

impl<const N: usize> Mul<f64> for Vector<N>

vector * scalar

Source§

type Output = Vector<N>

The resulting type after applying the * operator.
Source§

fn mul(self, s: f64) -> Self

Performs the * operation. Read more
Source§

impl<const N: usize> Neg for Vector<N>

Source§

type Output = Vector<N>

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self

Performs the unary - operation. Read more
Source§

impl<const N: usize> PartialEq for Vector<N>

Source§

fn eq(&self, other: &Vector<N>) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl<const N: usize> Serialize for Vector<N>

Available on crate feature serde only.
Source§

fn serialize<S: Serializer>(&self, ser: S) -> Result<S::Ok, S::Error>

Serialize this value into the given Serde serializer. Read more
Source§

impl<const N: usize> StructuralPartialEq for Vector<N>

Source§

impl<const N: usize> Sub for Vector<N>

Source§

type Output = Vector<N>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Self) -> Self

Performs the - operation. Read more
Source§

impl<const N: usize> Sub<Vector<N>> for Position<N>

Translate a point by a negative vector: point - vector → point.

Source§

type Output = Position<N>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Vector<N>) -> Self

Performs the - operation. Read more
Source§

impl<const N: usize> SubAssign for Vector<N>

Source§

fn sub_assign(&mut self, rhs: Self)

Performs the -= operation. Read more

Auto Trait Implementations§

§

impl<const N: usize> Freeze for Vector<N>

§

impl<const N: usize> RefUnwindSafe for Vector<N>

§

impl<const N: usize> Send for Vector<N>

§

impl<const N: usize> Sync for Vector<N>

§

impl<const N: usize> Unpin for Vector<N>

§

impl<const N: usize> UnsafeUnpin for Vector<N>

§

impl<const N: usize> UnwindSafe for Vector<N>

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.