pub type Vector2d<T> = Vector<T, 2>;
Expand description
A static 2-dimensional vector.
Aliased Type§
struct Vector2d<T> {
pub coords: [T; 2],
}
Fields§
§coords: [T; 2]
The vector coordinates in some basis.
Implementations
Source§impl<T: Clone + Mul<Output = T>, const D: usize> Vector<T, D>
impl<T: Clone + Mul<Output = T>, const D: usize> Vector<T, D>
Sourcepub fn clone_mul_scalar(&self, scalar: &T) -> Self
pub fn clone_mul_scalar(&self, scalar: &T) -> Self
Multiplies a vector by a scalar.
Source§impl<T: Clone + Div<Output = T>, const D: usize> Vector<T, D>
impl<T: Clone + Div<Output = T>, const D: usize> Vector<T, D>
Sourcepub fn clone_div_scalar(&self, scalar: &T) -> Self
pub fn clone_div_scalar(&self, scalar: &T) -> Self
Divides a vector by a scalar.
Source§impl<const D: usize> Vector<f64, D>
§Methods for vectors represented using f64
.
impl<const D: usize> Vector<f64, D>
§Methods for vectors represented using f64
.
Sourcepub const NEG_ONE: Self
Available on crate feature _float_f64
only.
pub const NEG_ONE: Self
_float_f64
only.A Vector
with all negative ones.
Sourcepub fn normalize(&self) -> Self
Available on crate feature _float_f64
only.
pub fn normalize(&self) -> Self
_float_f64
only.Returns the normalized vector, as a unit vector.
$$ \bm{n} = \widehat{\bm{a}} = \frac{1}{d}\thinspace\bm{a} = \frac{\bm{a}}{|\bm{a}|} $$
Sourcepub fn magnitude_sq(self) -> f64 ⓘ
Available on crate feature _float_f64
only.
pub fn magnitude_sq(self) -> f64 ⓘ
_float_f64
only.Calculates the squared magnitude of the vector.
This is faster than calculating the magnitude, which is useful for comparisons.
§Formula
$$ \large |\vec{V}|^2 = V_0^2 + … + V_n^2 $$
Sourcepub fn add(self, other: Self) -> Self
Available on crate feature _float_f64
only.
pub fn add(self, other: Self) -> Self
_float_f64
only.Adds two vectors together.
Sourcepub fn sub(self, other: Self) -> Self
Available on crate feature _float_f64
only.
pub fn sub(self, other: Self) -> Self
_float_f64
only.Subtracts another vector from this vector.
Sourcepub fn dot(self, other: Self) -> f64 ⓘ
Available on crate feature _float_f64
only.
pub fn dot(self, other: Self) -> f64 ⓘ
_float_f64
only.Computes the dot product of two vectors.
That is the magnitude of one vector in the direction of another.
Also known as the inner produc or the scalar product.
§Formula
$$ \large \vec{a}\cdot\vec{b} = \begin{bmatrix} a_0 \cr … \cr a_n \end{bmatrix} \cdot \begin{bmatrix} b_0 \cr … \cr b_n \end{bmatrix} = a_0 b_0 + … + a_n b_n $$
Source§impl<const D: usize> Vector<i64, D>
§Methods for vectors represented using i64
, signed.
impl<const D: usize> Vector<i64, D>
§Methods for vectors represented using i64
, signed.
Sourcepub const NEG_ONE: Self
Available on crate feature _int_i64
only.
pub const NEG_ONE: Self
_int_i64
only.A Vector
with all negative ones.
Sourcepub const fn c_magnitude_floor(self) -> i64 ⓘ
Available on crate feature _int_i64
only.
pub const fn c_magnitude_floor(self) -> i64 ⓘ
_int_i64
only.Calculates the floored magnitude of the vector.
It could underestimate the true magnitude.
§Features
This will only be const if the “_cmp_i64” feature is enabled.
Sourcepub const fn c_magnitude_ceil(self) -> i64 ⓘ
Available on crate feature _int_i64
only.
pub const fn c_magnitude_ceil(self) -> i64 ⓘ
_int_i64
only.Calculates the ceiled magnitude of the vector.
It could overestimate the true magnitude.
§Features
This will only be const if the “_cmp_i64” feature is enabled.
Sourcepub const fn c_magnitude_round(self) -> i64 ⓘ
Available on crate feature _int_i64
only.
pub const fn c_magnitude_round(self) -> i64 ⓘ
_int_i64
only.Calculates the rounded magnitude of the vector.
§Panics
Can panic if we reach a i128
value close to its maximum during operations.
Source§impl<const D: usize> Vector<i64, D>
§Methods for vectors represented using i64
.
impl<const D: usize> Vector<i64, D>
§Methods for vectors represented using i64
.
Sourcepub const fn c_normalize_with(self, magnitude: i64) -> Self
Available on crate feature _int_i64
only.
pub const fn c_normalize_with(self, magnitude: i64) -> Self
_int_i64
only.Returns the normalized vector, using the given vector magnitude
.
$$ \bm{n} = \widehat{\bm{a}} = \frac{1}{d}\thinspace\bm{a} = \frac{\bm{a}}{|\bm{a}|} $$
Sourcepub const fn c_magnitude_sq(self) -> i64 ⓘ
Available on crate feature _int_i64
only.
pub const fn c_magnitude_sq(self) -> i64 ⓘ
_int_i64
only.Calculates the magnitude of the vector (squared).
This is faster than calculating the magnitude, which is useful for comparisons.
§Formula
$$ \large |\vec{V}|^2 = V_0^2 + … + V_n^2 $$
Sourcepub const fn c_add(self, other: Self) -> Self
Available on crate feature _int_i64
only.
pub const fn c_add(self, other: Self) -> Self
_int_i64
only.Adds two vectors together, in compile-time.
Sourcepub const fn c_sub(self, other: Self) -> Self
Available on crate feature _int_i64
only.
pub const fn c_sub(self, other: Self) -> Self
_int_i64
only.Subtracts another vector from this vector, in compile-time.
Sourcepub const fn c_dot(self, other: Self) -> i64 ⓘ
Available on crate feature _int_i64
only.
pub const fn c_dot(self, other: Self) -> i64 ⓘ
_int_i64
only.Computes the dot product of two vectors, in compile-time.
Sourcepub const fn c_scalar_mul(self, scalar: i64) -> Self
Available on crate feature _int_i64
only.
pub const fn c_scalar_mul(self, scalar: i64) -> Self
_int_i64
only.Multiplies each element of the vector by a scalar, in compile-time.
Sourcepub const fn c_scalar_div(self, scalar: i64) -> Self
Available on crate feature _int_i64
only.
pub const fn c_scalar_div(self, scalar: i64) -> Self
_int_i64
only.Divides each element of the vector by a scalar, in compile-time.
Source§impl<const D: usize> Vector<u32, D>
§Methods for vectors represented using u32
, unsigned.
impl<const D: usize> Vector<u32, D>
§Methods for vectors represented using u32
, unsigned.
Sourcepub const fn c_magnitude_floor(self) -> u32 ⓘ
Available on crate feature _int_u32
only.
pub const fn c_magnitude_floor(self) -> u32 ⓘ
_int_u32
only.Calculates the floored magnitude of the vector.
It could underestimate the true magnitude.
§Features
This will only be const if the “_cmp_u32” feature is enabled.
Sourcepub const fn c_magnitude_ceil(self) -> u32 ⓘ
Available on crate feature _int_u32
only.
pub const fn c_magnitude_ceil(self) -> u32 ⓘ
_int_u32
only.Calculates the ceiled magnitude of the vector.
It could overestimate the true magnitude.
§Features
This will only be const if the “_cmp_u32” feature is enabled.
Sourcepub const fn c_magnitude_round(self) -> u32 ⓘ
Available on crate feature _int_u32
only.
pub const fn c_magnitude_round(self) -> u32 ⓘ
_int_u32
only.Calculates the rounded magnitude of the vector.
§Panics
Can panic if we reach a u128
value close to its maximum during operations.
Source§impl<const D: usize> Vector<u32, D>
§Methods for vectors represented using u32
.
impl<const D: usize> Vector<u32, D>
§Methods for vectors represented using u32
.
Sourcepub const fn c_normalize_with(self, magnitude: u32) -> Self
Available on crate feature _int_u32
only.
pub const fn c_normalize_with(self, magnitude: u32) -> Self
_int_u32
only.Returns the normalized vector, using the given vector magnitude
.
$$ \bm{n} = \widehat{\bm{a}} = \frac{1}{d}\thinspace\bm{a} = \frac{\bm{a}}{|\bm{a}|} $$
Sourcepub const fn c_magnitude_sq(self) -> u32 ⓘ
Available on crate feature _int_u32
only.
pub const fn c_magnitude_sq(self) -> u32 ⓘ
_int_u32
only.Calculates the magnitude of the vector (squared).
This is faster than calculating the magnitude, which is useful for comparisons.
§Formula
$$ \large |\vec{V}|^2 = V_0^2 + … + V_n^2 $$
Sourcepub const fn c_add(self, other: Self) -> Self
Available on crate feature _int_u32
only.
pub const fn c_add(self, other: Self) -> Self
_int_u32
only.Adds two vectors together, in compile-time.
Sourcepub const fn c_sub(self, other: Self) -> Self
Available on crate feature _int_u32
only.
pub const fn c_sub(self, other: Self) -> Self
_int_u32
only.Subtracts another vector from this vector, in compile-time.
Sourcepub const fn c_dot(self, other: Self) -> u32 ⓘ
Available on crate feature _int_u32
only.
pub const fn c_dot(self, other: Self) -> u32 ⓘ
_int_u32
only.Computes the dot product of two vectors, in compile-time.
Sourcepub const fn c_scalar_mul(self, scalar: u32) -> Self
Available on crate feature _int_u32
only.
pub const fn c_scalar_mul(self, scalar: u32) -> Self
_int_u32
only.Multiplies each element of the vector by a scalar, in compile-time.
Sourcepub const fn c_scalar_div(self, scalar: u32) -> Self
Available on crate feature _int_u32
only.
pub const fn c_scalar_div(self, scalar: u32) -> Self
_int_u32
only.Divides each element of the vector by a scalar, in compile-time.
Trait Implementations
Source§impl<T: Clone + Add<Output = T>, const D: usize> AddAssign<&Vector<T, D>> for Vector<T, D>
impl<T: Clone + Add<Output = T>, const D: usize> AddAssign<&Vector<T, D>> for Vector<T, D>
Source§fn add_assign(&mut self, other: &Self)
fn add_assign(&mut self, other: &Self)
+=
operation. Read moreSource§impl<T: ConstDefault, const D: usize> ConstDefault for Vector<T, D>
impl<T: ConstDefault, const D: usize> ConstDefault for Vector<T, D>
Source§impl<T: Clone + Div<Output = T>, const D: usize> DivAssign<&T> for Vector<T, D>
impl<T: Clone + Div<Output = T>, const D: usize> DivAssign<&T> for Vector<T, D>
Source§fn div_assign(&mut self, scalar: &T)
fn div_assign(&mut self, scalar: &T)
/=
operation. Read moreSource§impl<T: Clone + Div<Output = T>, const D: usize> DivAssign<T> for Vector<T, D>
impl<T: Clone + Div<Output = T>, const D: usize> DivAssign<T> for Vector<T, D>
Source§fn div_assign(&mut self, scalar: T)
fn div_assign(&mut self, scalar: T)
/=
operation. Read moreSource§impl<T: Clone + Mul<Output = T>, const D: usize> MulAssign<&T> for Vector<T, D>
impl<T: Clone + Mul<Output = T>, const D: usize> MulAssign<&T> for Vector<T, D>
Source§fn mul_assign(&mut self, scalar: &T)
fn mul_assign(&mut self, scalar: &T)
*=
operation. Read moreSource§impl<T: Clone + Mul<Output = T>, const D: usize> MulAssign<T> for Vector<T, D>
impl<T: Clone + Mul<Output = T>, const D: usize> MulAssign<T> for Vector<T, D>
Source§fn mul_assign(&mut self, scalar: T)
fn mul_assign(&mut self, scalar: T)
*=
operation. Read moreSource§impl<T: Num, const D: usize> Num for Vector<T, D>
impl<T: Num, const D: usize> Num for Vector<T, D>
Source§fn num_from(value: Self::Inner) -> Result<Self>where
Self: Sized,
fn num_from(value: Self::Inner) -> Result<Self>where
Self: Sized,
Self
if given a valid value
.Source§fn num_from_ref(value: &Self::Inner) -> Result<Self>where
Self: Sized,
fn num_from_ref(value: &Self::Inner) -> Result<Self>where
Self: Sized,
Self
if given a valid &value
.Source§fn num_set_ref(&mut self, value: &Self::Inner) -> Result<()>
fn num_set_ref(&mut self, value: &Self::Inner) -> Result<()>
self
to the given valid &value
.Source§fn num_is_zero(&self) -> Result<bool>
fn num_is_zero(&self) -> Result<bool>
true
if self
is zero.Source§fn num_get_zero() -> Result<Self>where
Self: Sized,
fn num_get_zero() -> Result<Self>where
Self: Sized,
Source§fn num_set_zero(&mut self) -> Result<()>
fn num_set_zero(&mut self) -> Result<()>
self
to 0
.Source§fn num_is_one(&self) -> Result<bool>
fn num_is_one(&self) -> Result<bool>
true
if self
is one.Source§fn num_get_one() -> Result<Self>where
Self: Sized,
fn num_get_one() -> Result<Self>where
Self: Sized,
Source§fn num_set_one(&mut self) -> Result<()>
fn num_set_one(&mut self) -> Result<()>
Source§fn num_add(self, rhs: Self::Rhs) -> Result<Self::Out>where
Self: Sized,
fn num_add(self, rhs: Self::Rhs) -> Result<Self::Out>where
Self: Sized,
self + rhs
(addition).Source§fn num_ref_add(&self, rhs: &Self::Rhs) -> Result<Self::Out>
fn num_ref_add(&self, rhs: &Self::Rhs) -> Result<Self::Out>
num_add
but takes the arguments by reference.Source§fn num_ref_add_assign(&mut self, rhs: &Self::Rhs) -> Result<()>
fn num_ref_add_assign(&mut self, rhs: &Self::Rhs) -> Result<()>
&mut self += rhs;
(addition).Source§fn num_sub(self, rhs: Self::Rhs) -> Result<Self::Out>where
Self: Sized,
fn num_sub(self, rhs: Self::Rhs) -> Result<Self::Out>where
Self: Sized,
self - rhs
(subtraction).Source§fn num_ref_sub(&self, rhs: &Self::Rhs) -> Result<Self::Out>
fn num_ref_sub(&self, rhs: &Self::Rhs) -> Result<Self::Out>
num_sub
but takes the arguments by reference.Source§fn num_ref_sub_assign(&mut self, rhs: &Self::Rhs) -> Result<()>
fn num_ref_sub_assign(&mut self, rhs: &Self::Rhs) -> Result<()>
&mut self -= rhs;
(subtraction).Source§fn num_mul(self, rhs: Self::Rhs) -> Result<Self::Out>where
Self: Sized,
fn num_mul(self, rhs: Self::Rhs) -> Result<Self::Out>where
Self: Sized,
self * rhs
(multiplication).Source§fn num_ref_mul(&self, rhs: &Self::Rhs) -> Result<Self::Out>
fn num_ref_mul(&self, rhs: &Self::Rhs) -> Result<Self::Out>
num_mul
but takes the arguments by reference.Source§fn num_ref_mul_assign(&mut self, rhs: &Self::Rhs) -> Result<()>
fn num_ref_mul_assign(&mut self, rhs: &Self::Rhs) -> Result<()>
&mut self *= rhs;
(multiplication).Source§fn num_div(self, rhs: Self::Rhs) -> Result<Self::Out>where
Self: Sized,
fn num_div(self, rhs: Self::Rhs) -> Result<Self::Out>where
Self: Sized,
self / rhs
(division).Source§fn num_ref_div(&self, rhs: &Self::Rhs) -> Result<Self::Out>
fn num_ref_div(&self, rhs: &Self::Rhs) -> Result<Self::Out>
num_div
but takes the arguments by reference.Source§fn num_ref_div_assign(&mut self, rhs: &Self::Rhs) -> Result<()>
fn num_ref_div_assign(&mut self, rhs: &Self::Rhs) -> Result<()>
&mut self /= rhs;
(division).Source§fn num_rem(self, rhs: Self::Rhs) -> Result<Self::Out>where
Self: Sized,
fn num_rem(self, rhs: Self::Rhs) -> Result<Self::Out>where
Self: Sized,
self % rhs
(remainder).Source§fn num_ref_rem(&self, rhs: &Self::Rhs) -> Result<Self::Out>
fn num_ref_rem(&self, rhs: &Self::Rhs) -> Result<Self::Out>
num_rem
but takes the arguments by reference.Source§impl<T: Clone + Sub<Output = T>, const D: usize> SubAssign<&Vector<T, D>> for Vector<T, D>
impl<T: Clone + Sub<Output = T>, const D: usize> SubAssign<&Vector<T, D>> for Vector<T, D>
Source§fn sub_assign(&mut self, other: &Self)
fn sub_assign(&mut self, other: &Self)
-=
operation. Read moreSource§impl<T: Num + 'static, const D: usize> TryInto<Box<dyn NumVector<Rhs = Vector<T, D>, Inner = [T; D], Out = Vector<T, D>, Scalar = T>>> for Vector<T, D>
Available on crate feature alloc
only.
impl<T: Num + 'static, const D: usize> TryInto<Box<dyn NumVector<Rhs = Vector<T, D>, Inner = [T; D], Out = Vector<T, D>, Scalar = T>>> for Vector<T, D>
alloc
only.