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, at every finite size: a vector whose squares overflow or underflow is measured at a power of two of its size. It is infinite only for a length past the largest float.

Source

pub fn largest_component(self) -> f64

The largest of the absolute values of the components; not a number if a component is not.

Source

pub fn at_unit_size(self) -> Self

The vector scaled by unit_scale of its largest component: the same direction, with no product of two components out of range. Two vectors so scaled give the sign of their dot or cross product, and the angle between them, as they are.

Source

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

Return a unit-length vector in the same direction. A vector of any finite, non-zero size has one: one whose squares overflow or underflow is scaled by a power of two first.

§Errors

Returns MathError::ZeroVector if the vector is zero or a component is not 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.

Source

pub fn square_part(self, axis: Self) -> Result<Self, MathError>

The direction of the part of the vector square to the unit vector axis.

The vector is taken at a unit size first, so that neither the projection nor the tests below overflow or lose digits at either end of the range. A part of half the vector or more is taken as it is. A shorter part is projected again, and is taken only where it is longer than the most that rounding alone could leave square to the axis; its direction is projected once more, so that it is square to the axis to a few units of rounding.

§Errors

Returns MathError::ZeroVector if the vector is zero or not finite, or its part square to axis could be rounding alone, as for a vector along axis.

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) -> Self

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: &Self) -> 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> Forget for Vector<N>

§

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

§

impl<const N: usize> Move 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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 = !

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

fn try_from(value: U) -> Result<T, !>

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.