#[repr(transparent)]pub struct Vector<Repr, Space = ()>(pub Repr, _);Expand description
A generic vector type. Represents an element of a vector space or a module, a generalization of a vector space where the scalars can be integers (technically, the scalar type can be any ring-like type).
§Type parameters
Repr: Representation of the scalar components of the vector, for example an array or a SIMD vector.Space: The space that the vector is an element of. A tag type used to prevent mixing up vectors of different spaces and bases.
§Examples
TODO
Tuple Fields§
§0: ReprImplementations§
Source§impl<R, Sp> Vector<R, Sp>
impl<R, Sp> Vector<R, Sp>
Sourcepub fn to<S>(self) -> Vector<R, S>
pub fn to<S>(self) -> Vector<R, S>
Returns a vector with value equal to self but in space S.
This method can be used to coerce a vector from one space to another in order to make types match. One use case is to cast a “generic” vector returned by one of the constructor functions to a more specific space.
Source§impl<Sp, const N: usize> Vector<[f32; N], Sp>
impl<Sp, const N: usize> Vector<[f32; N], Sp>
Sourcepub fn clamp(&self, min: &Self, max: &Self) -> Self
pub fn clamp(&self, min: &Self, max: &Self) -> Self
Returns self clamped component-wise to the given range.
In other words, for each component self[i], the result r has
r[i] equal to self[i].clamp(min[i], max[i]).
§Examples
let v: Vec3 = vec3(0.5, 1.5, -2.0);
// Clamp to the unit cube
let v = v.clamp(&splat(-1.0), &splat(1.0));
assert_eq!(v, vec3(0.5, 1.0, -1.0));Source§impl<Sc, Sp, const N: usize> Vector<[Sc; N], Sp>
impl<Sc, Sp, const N: usize> Vector<[Sc; N], Sp>
Sourcepub fn len_sqr(&self) -> Sc
pub fn len_sqr(&self) -> Sc
Returns the length of self, squared.
This avoids taking the square root in cases it’s not needed and works with scalars for which a square root is not defined.
Sourcepub fn scalar_project(&self, other: &Self) -> Scwhere
Sc: Div<Sc, Output = Sc>,
pub fn scalar_project(&self, other: &Self) -> Scwhere
Sc: Div<Sc, Output = Sc>,
Returns the scalar projection of self onto other
(the length of the component of self parallel to other).
Sourcepub fn vector_project(&self, other: &Self) -> Selfwhere
Sc: Div<Sc, Output = Sc>,
pub fn vector_project(&self, other: &Self) -> Selfwhere
Sc: Div<Sc, Output = Sc>,
Returns the vector projection of self onto other
(the vector component of self parallel to other).
self
^
/.
/ .
/ .
/ .
/ _.
+-------'->-----> other
resultSource§impl<R, Sc, B> Vector<R, Real<3, B>>
impl<R, Sc, B> Vector<R, Real<3, B>>
Sourcepub fn cross(&self, other: &Self) -> Self
pub fn cross(&self, other: &Self) -> Self
Returns the cross product of self with other.
The result is a vector perpendicular to both input vectors, its length proportional to the area of the parallelogram formed by the vectors. Specifically, the length is given by the identity:
|𝗮 × 𝗯| = |𝗮| |𝗯| sin 𝜽where |·| denotes the length of a vector and 𝜽 equals the angle between 𝗮 and 𝗯.
^
r |
e |
s | other
u | ^ - - - - - +
l | / /
t | / /
+-----------> selfTrait Implementations§
Source§impl<R, Sp> AddAssign<<Vector<R, Sp> as Affine>::Diff> for Vector<R, Sp>where
Self: Affine,
The vector += vector operator.
impl<R, Sp> AddAssign<<Vector<R, Sp> as Affine>::Diff> for Vector<R, Sp>where
Self: Affine,
The vector += vector operator.
Source§impl<Sc, Sp, const DIM: usize> Affine for Vector<[Sc; DIM], Sp>
impl<Sc, Sp, const DIM: usize> Affine for Vector<[Sc; DIM], Sp>
Source§impl<Sc: ApproxEq, Sp, const N: usize> ApproxEq<Vector<[Sc; N], Sp>, Sc> for Vector<[Sc; N], Sp>
impl<Sc: ApproxEq, Sp, const N: usize> ApproxEq<Vector<[Sc; N], Sp>, Sc> for Vector<[Sc; N], Sp>
Source§fn approx_eq_eps(&self, other: &Self, eps: &Sc) -> bool
fn approx_eq_eps(&self, other: &Self, eps: &Sc) -> bool
self and other are approximately equal,
using the relative epsilon rel_eps.Source§fn relative_epsilon() -> Sc
fn relative_epsilon() -> Sc
E.Source§impl<R, Sp> DivAssign<f32> for Vector<R, Sp>
impl<R, Sp> DivAssign<f32> for Vector<R, Sp>
Source§fn div_assign(&mut self, rhs: f32)
fn div_assign(&mut self, rhs: f32)
/= operation. Read moreSource§impl<R, Sp> MulAssign<<Vector<R, Sp> as Linear>::Scalar> for Vector<R, Sp>where
Self: Linear,
impl<R, Sp> MulAssign<<Vector<R, Sp> as Linear>::Scalar> for Vector<R, Sp>where
Self: Linear,
Source§impl<R, Sp> SubAssign<<Vector<R, Sp> as Affine>::Diff> for Vector<R, Sp>where
Self: Affine,
The vector -= vector operator.
impl<R, Sp> SubAssign<<Vector<R, Sp> as Affine>::Diff> for Vector<R, Sp>where
Self: Affine,
The vector -= vector operator.
impl<R: Copy, S> Copy for Vector<R, S>
impl<R: Eq, S> Eq for Vector<R, S>
Auto Trait Implementations§
impl<Repr, Space> Freeze for Vector<Repr, Space>where
Repr: Freeze,
impl<Repr, Space> RefUnwindSafe for Vector<Repr, Space>where
Repr: RefUnwindSafe,
Space: RefUnwindSafe,
impl<Repr, Space> Send for Vector<Repr, Space>
impl<Repr, Space> Sync for Vector<Repr, Space>
impl<Repr, Space> Unpin for Vector<Repr, Space>
impl<Repr, Space> UnwindSafe for Vector<Repr, Space>where
Repr: UnwindSafe,
Space: UnwindSafe,
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,
Source§impl<V> Vary for V
impl<V> Vary for V
Source§fn dv_dt(&self, other: &V, recip_dt: f32) -> <V as Vary>::Diff
fn dv_dt(&self, other: &V, recip_dt: f32) -> <V as Vary>::Diff
(other - self) / dt.