pub struct Vector3<T> {
pub x: T,
pub y: T,
pub z: T,
}Expand description
A vector of three components x, y, and z.
Fields§
§x: TThe first component.
y: TThe second component.
z: TThe third component.
Implementations§
Source§impl<T> Vector3<T>
impl<T> Vector3<T>
Source§impl<T: Add<Output = T>> Vector3<T>
impl<T: Add<Output = T>> Vector3<T>
Sourcepub fn element_sum(self) -> T
pub fn element_sum(self) -> T
Returns the sum of the three components, x + y + z.
Source§impl<V: Scalar> Vector3<V>
impl<V: Scalar> Vector3<V>
Sourcepub fn norm_squared(self) -> V
pub fn norm_squared(self) -> V
Returns the squared Euclidean norm self · self.
Cheaper than norm and sufficient whenever only relative
magnitudes are compared.
Sourcepub fn normalize(self) -> Self
pub fn normalize(self) -> Self
Returns self rescaled to unit length.
Yields a non-finite vector when the norm is zero or non-finite; use
try_normalize or
normalize_or_zero to handle those cases.
Sourcepub fn try_normalize(self) -> Option<Self>
pub fn try_normalize(self) -> Option<Self>
Returns self rescaled to unit length, or None if the result would
not be finite (e.g. for the zero vector).
Sourcepub fn normalize_or_zero(self) -> Self
pub fn normalize_or_zero(self) -> Self
Returns self rescaled to unit length, or the zero vector if the
result would not be finite.
Sourcepub fn is_normalized(self) -> bool
pub fn is_normalized(self) -> bool
Returns true if the vector is of unit length within a small
tolerance (2.0e-4).
Sourcepub fn angle_between(self, rhs: Self) -> V
pub fn angle_between(self, rhs: Self) -> V
Returns the unsigned angle between self and rhs, in radians within
[0, π].
The computation is numerically stable across the whole range, including near-parallel and near-antiparallel inputs.
Sourcepub fn project_onto(self, onto: Self) -> Self
pub fn project_onto(self, onto: Self) -> Self
Returns the vector projection of self onto onto.
Sourcepub fn reject_from(self, from: Self) -> Self
pub fn reject_from(self, from: Self) -> Self
Returns the component of self orthogonal to from.
Sourcepub fn reflect(self, normal: Self) -> Self
pub fn reflect(self, normal: Self) -> Self
Reflects self across the plane through the origin with unit normal
normal.
Sourcepub fn element_product(self) -> V
pub fn element_product(self) -> V
Returns the product of the three components, x * y * z.
Sourcepub fn clamp(self, min: Self, max: Self) -> Self
pub fn clamp(self, min: Self, max: Self) -> Self
Restricts every component to the interval [min, max].
§Panics
Panics if any component of min exceeds the corresponding component of
max.
Sourcepub fn min_element(self) -> V
pub fn min_element(self) -> V
Returns the smallest of the three components.
Sourcepub fn max_element(self) -> V
pub fn max_element(self) -> V
Returns the largest of the three components.
Sourcepub fn round(self) -> Self
pub fn round(self) -> Self
Returns the component-wise nearest integer, rounding halves away from zero.
Sourcepub fn round_ties_even(self) -> Self
pub fn round_ties_even(self) -> Self
Returns the component-wise nearest integer, rounding halves to even.
Sourcepub fn copysign(self, sign: Self) -> Self
pub fn copysign(self, sign: Self) -> Self
Returns a vector with the magnitudes of self and the component-wise
signs of sign.
Sourcepub fn rem_euclid(self, rhs: Self) -> Self
pub fn rem_euclid(self, rhs: Self) -> Self
Returns the component-wise least nonnegative remainder against rhs.
Sourcepub fn is_infinite(self) -> bool
pub fn is_infinite(self) -> bool
Returns true if any component is positive or negative infinity.
Trait Implementations§
Source§impl<T: AddAssign> AddAssign for Vector3<T>
impl<T: AddAssign> AddAssign for Vector3<T>
Source§fn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
+= operation. Read moreSource§impl<T: AddAssign> AddAssign<Vector3<T>> for Point3<T>
impl<T: AddAssign> AddAssign<Vector3<T>> for Point3<T>
Source§fn add_assign(&mut self, rhs: Vector3<T>)
fn add_assign(&mut self, rhs: Vector3<T>)
+= operation. Read moreimpl<T: Copy> Copy for Vector3<T>
Source§impl<T, S: Scalar> DivAssign<S> for Vector3<T>where
T: DivAssign<S>,
impl<T, S: Scalar> DivAssign<S> for Vector3<T>where
T: DivAssign<S>,
Source§fn div_assign(&mut self, rhs: S)
fn div_assign(&mut self, rhs: S)
/= operation. Read moreSource§impl<T, S: Scalar> MulAssign<S> for Vector3<T>where
T: MulAssign<S>,
impl<T, S: Scalar> MulAssign<S> for Vector3<T>where
T: MulAssign<S>,
Source§fn mul_assign(&mut self, rhs: S)
fn mul_assign(&mut self, rhs: S)
*= operation. Read moreSource§impl<T: SubAssign> SubAssign for Vector3<T>
impl<T: SubAssign> SubAssign for Vector3<T>
Source§fn sub_assign(&mut self, rhs: Self)
fn sub_assign(&mut self, rhs: Self)
-= operation. Read moreSource§impl<T: SubAssign> SubAssign<Vector3<T>> for Point3<T>
impl<T: SubAssign> SubAssign<Vector3<T>> for Point3<T>
Source§fn sub_assign(&mut self, rhs: Vector3<T>)
fn sub_assign(&mut self, rhs: Vector3<T>)
-= operation. Read more