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>
impl<const N: usize> Vector<N>
Sourcepub fn length_squared(self) -> f64
pub fn length_squared(self) -> f64
Squared Euclidean length (avoids a sqrt).
Sourcepub fn length(self) -> f64
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.
Sourcepub fn largest_component(self) -> f64
pub fn largest_component(self) -> f64
The largest of the absolute values of the components; not a number if a component is not.
Sourcepub fn at_unit_size(self) -> Self
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.
Sourcepub fn normalize(self) -> Result<Self, MathError>
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<3>
impl Vector<3>
Sourcepub fn square_part(self, axis: Self) -> Result<Self, MathError>
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<Vector<N>> for Position<N>
Translate a point by a vector: point + vector → point.
impl<const N: usize> Add<Vector<N>> for Position<N>
Translate a point by a vector: point + vector → point.
Source§impl<const N: usize> AddAssign for Vector<N>
impl<const N: usize> AddAssign for Vector<N>
Source§fn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
+= operation. Read moreimpl<const N: usize> Copy for Vector<N>
Source§impl<'de, const N: usize> Deserialize<'de> for Vector<N>
Available on crate feature serde only.
impl<'de, const N: usize> Deserialize<'de> for Vector<N>
serde only.Source§fn deserialize<D: Deserializer<'de>>(de: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(de: D) -> Result<Self, D::Error>
impl<const N: usize> StructuralPartialEq for Vector<N>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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