Trait vector_traits::GenericVector3
source · pub trait GenericVector3: HasXYZ + Approx + PartialEq + AddAssign + Neg<Output = Self> + Sub<Self, Output = Self> + Mul<Self::Scalar, Output = Self> + Div<Self::Scalar, Output = Self> + Add<Self, Output = Self> + Index<usize, Output = Self::Scalar> {
type Vector2: GenericVector2<Scalar = Self::Scalar, Vector3 = Self>;
// Required methods
fn to_2d(&self) -> Self::Vector2;
fn magnitude(self) -> Self::Scalar;
fn magnitude_sq(self) -> Self::Scalar;
fn dot(self, other: Self) -> Self::Scalar;
fn cross(self, rhs: Self) -> Self;
fn normalize(self) -> Self;
fn safe_normalize(self) -> Option<Self>;
fn distance(self, other: Self) -> Self::Scalar;
fn distance_sq(self, rhs: Self) -> Self::Scalar;
}
Expand description
A generic three-dimensional vector trait, designed for flexibility in precision.
The GenericVector3
trait abstracts over three-dimensional vectors, allowing for easy
transition between different precisions (e.g., f32
and f64
) without necessitating
significant codebase modifications. It provides the common operations one would expect
for 3D vectors, such as dot products, cross products, and normalization.
Implementors of this trait can benefit from the ability to switch between different precision representations seamlessly, making it ideal for applications where varying precision levels might be desirable at different stages or configurations.
The associated Scalar
type represents the scalar type (e.g., f32
or f64
) used
by the vector, and Vector2
is the corresponding two-dimensional vector type.
Note: The actual trait functionality might vary based on the concrete implementations.