Struct Vec2
Source #[repr(C)]
pub struct Vec2 {
pub x: f32,
pub y: f32,
}
Expand description
A 2-dimensional vector with f32
components.
The x component of the vector.
The y component of the vector.
A vector with all components set to 0.0
.
A vector with all components set to 1.0
.
The unit vector pointing along the positive X-axis.
The unit vector pointing along the positive Y-axis.
Creates a new Vec2
with the specified components.
Returns a new vector with the absolute value of each component.
Calculates the squared length (magnitude) of the vector.
This is faster than length()
as it avoids a square root.
Calculates the length (magnitude) of the vector.
Returns a normalized version of the vector with a length of 1.
If the vector’s length is near zero, it returns Vec2::ZERO
.
Calculates the dot product of this vector and another.
Performs a linear interpolation between two vectors.
The interpolation factor t
is clamped to the [0.0, 1.0]
range.
Adds two vectors component-wise.
The resulting type after applying the +
operator.
Performs copy-assignment from
source
.
Read more
Formats the value using the given formatter.
Read more
Returns the “default value” for a type.
Read more
Divides the vector by a scalar.
The resulting type after applying the /
operator.
Allows accessing a vector component by index (v[0]
, v[1]
).
§Panics
Panics if index
is not 0 or 1.
The returned type after indexing.
Allows mutably accessing a vector component by index (v[0] = ...
).
§Panics
Panics if index
is not 0 or 1.
Multiplies a scalar by a vector.
The resulting type after applying the *
operator.
Multiplies the vector by a scalar.
The resulting type after applying the *
operator.
Multiplies two vectors component-wise.
The resulting type after applying the *
operator.
The resulting type after applying the -
operator.
Tests for self
and other
values to be equal, and is used by ==
.
Tests for !=
. The default implementation is almost always sufficient,
and should not be overridden without very good reason.
Subtracts two vectors component-wise.
The resulting type after applying the -
operator.
Immutably borrows from an owned value.
Read more
Mutably borrows from an owned value.
Read more
🔬This is a nightly-only experimental API. (clone_to_uninit
)
Performs copy-assignment from
self
to
dest
.
Read more
Returns the argument unchanged.
Calls U::from(self)
.
That is, this conversion is whatever the implementation of
From<T> for U
chooses to do.
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning.
Read more
Uses borrowed data to replace owned data, usually by cloning.
Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.