Struct primitives::foundation::Vector2D [−][src]
#[repr(C)]pub struct Vector2D<T> {
pub x: T,
pub y: T,
}
Expand description
A 2d Vector tagged with a unit.
Fields
x: T
The x
(traditionally, horizontal) coordinate.
y: T
The y
(traditionally, vertical) coordinate.
Implementations
Constructor setting all components to the same value.
Computes the vector with absolute values of each component.
Example
enum U {}
assert_eq!(Vector2D::new(-1, 2).abs(), Vector2D::new(1, 2));
let vec = Vector2D::new(f32::NAN, -f32::MAX).abs();
assert!(vec.x.is_nan());
assert_eq!(vec.y, f32::MAX);
Panics
The behavior for each component follows the scalar type’s implementation of
num_traits::Signed::abs
.
Returns the norm of the cross product [self.x, self.y, 0] x [other.x, other.y, 0].
Returns the component-wise multiplication of the two vectors.
Returns the component-wise division of the two vectors.
Returns the vector’s length squared.
pub fn project_onto_vector(self, onto: Self) -> Self where
T: Sub<T, Output = T> + Div<T, Output = T>,
pub fn project_onto_vector(self, onto: Self) -> Self where
T: Sub<T, Output = T> + Div<T, Output = T>,
Returns this vector projected onto another one.
Projecting onto a nil vector will cause a division by zero.
Returns the vector with length of one unit.
Unlike Vector2D::normalize
, this returns None in the case that the
length of the vector is zero.
Return the normalized vector even if the length is larger than the max value of Float.
Return this vector capped to a maximum length.
Return this vector with a minimum length applied.
Return this vector with minimum and maximum lengths applied.
Cast from one numeric representation to another, preserving the units.
When casting from floating vector to integer coordinates, the decimals are truncated
as one would expect from a simple cast, but this behavior does not always make sense
geometrically. Consider using round()
, ceil()
or floor()
before casting.
Fallible cast from one numeric representation to another, preserving the units.
When casting from floating vector to integer coordinates, the decimals are truncated
as one would expect from a simple cast, but this behavior does not always make sense
geometrically. Consider using round()
, ceil()
or floor()
before casting.
Cast into an usize
vector, truncating decimals if any.
When casting from floating vector vectors, it is worth considering whether
to round()
, ceil()
or floor()
before the cast in order to obtain
the desired conversion behavior.
Cast into an u32
vector, truncating decimals if any.
When casting from floating vector vectors, it is worth considering whether
to round()
, ceil()
or floor()
before the cast in order to obtain
the desired conversion behavior.
Cast into an i32 vector, truncating decimals if any.
When casting from floating vector vectors, it is worth considering whether
to round()
, ceil()
or floor()
before the cast in order to obtain
the desired conversion behavior.
Trait Implementations
Performs the +=
operation. Read more
Performs the /=
operation. Read more
Performs the *=
operation. Read more
Performs the -=
operation. Read more
Auto Trait Implementations
impl<T> RefUnwindSafe for Vector2D<T> where
T: RefUnwindSafe,
impl<T> UnwindSafe for Vector2D<T> where
T: UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more