pub trait GenericVector2:
HasXY
+ 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 Vector3: GenericVector3<Scalar = Self::Scalar, Vector2 = Self>;
// Required methods
fn to_3d(self, z: Self::Scalar) -> Self::Vector3;
fn magnitude(self) -> Self::Scalar;
fn magnitude_sq(self) -> Self::Scalar;
fn dot(self, other: Self) -> Self::Scalar;
fn perp_dot(self, rhs: Self) -> Self::Scalar;
fn distance(self, rhs: Self) -> Self::Scalar;
fn distance_sq(self, rhs: Self) -> Self::Scalar;
fn normalize(self) -> Self;
fn safe_normalize(self) -> Option<Self>;
}Expand description
A generic two-dimensional vector trait, designed for flexibility in precision.
The GenericVector2 trait abstracts over two-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 2D 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 Vector3 is the corresponding three-dimensional vector type.
Note: The actual trait functionality might vary based on the concrete implementations.
Required Associated Types§
type Vector3: GenericVector3<Scalar = Self::Scalar, Vector2 = Self>
Required Methods§
fn to_3d(self, z: Self::Scalar) -> Self::Vector3
fn magnitude(self) -> Self::Scalar
fn magnitude_sq(self) -> Self::Scalar
fn dot(self, other: Self) -> Self::Scalar
fn perp_dot(self, rhs: Self) -> Self::Scalar
fn distance(self, rhs: Self) -> Self::Scalar
fn distance_sq(self, rhs: Self) -> Self::Scalar
fn normalize(self) -> Self
fn safe_normalize(self) -> Option<Self>
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.