#[repr(C)]pub struct Vector2 {
pub x: f32,
pub y: f32,
}
Expand description
Vector used for 2D math using floating point coordinates.
2-element structure that can be used to represent positions in 2D space or any other pair of numeric values.
It uses floating-point coordinates of 32-bit precision, unlike the engine’s float
type which
is always 64-bit. The engine can be compiled with the option precision=double
to use 64-bit
vectors; use the gdext library with the double-precision
feature in that case.
See Vector2i
for its integer counterpart.
Fields§
§x: f32
The vector’s X component.
y: f32
The vector’s Y component.
Implementations§
§impl Vector2
impl Vector2
pub const fn from_vector2i(v: Vector2i) -> Vector2
pub const fn from_vector2i(v: Vector2i) -> Vector2
Constructs a new Vector2
from a Vector2i
.
pub fn angle(self) -> f32
pub fn angle_to(self, to: Vector2) -> f32
pub fn angle_to_point(self, to: Vector2) -> f32
pub fn aspect(self) -> f32
pub fn bounce(self, normal: Vector2) -> Vector2
pub fn ceil(self) -> Vector2
pub fn clamp(self, min: Vector2, max: Vector2) -> Vector2
pub fn cross(self, with: Vector2) -> f32
pub fn direction_to(self, to: Vector2) -> Vector2
pub fn distance_squared_to(self, to: Vector2) -> f32
pub fn distance_to(self, to: Vector2) -> f32
pub fn dot(self, other: Vector2) -> f32
pub fn floor(self) -> Vector2
pub fn from_angle(angle: f32) -> Vector2
pub fn is_finite(self) -> bool
pub fn is_normalized(self) -> bool
pub fn length_squared(self) -> f32
pub fn limit_length(self, length: Option<f32>) -> Vector2
pub fn max_axis_index(self) -> Vector2Axis
pub fn min_axis_index(self) -> Vector2Axis
pub fn move_toward(self, to: Vector2, delta: f32) -> Vector2
pub fn orthogonal(self) -> Vector2
pub fn project(self, b: Vector2) -> Vector2
pub fn reflect(self, normal: Vector2) -> Vector2
pub fn round(self) -> Vector2
pub fn slerp(self, to: Vector2, weight: f32) -> Vector2
pub fn slide(self, normal: Vector2) -> Vector2
pub fn rotated(self, angle: f32) -> Vector2
pub fn rotated(self, angle: f32) -> Vector2
Returns the result of rotating this vector by angle
(in radians).
pub fn coords(&self) -> (f32, f32)
§impl Vector2
impl Vector2
§impl Vector2
impl Vector2
pub fn normalized(self) -> Vector2
pub fn normalized(self) -> Vector2
Returns the vector scaled to unit length. Equivalent to self / self.length()
. See
also is_normalized()
.
If the vector is zero, the result is also zero.
§impl Vector2
impl Vector2
pub fn lerp(self, other: Vector2, weight: f32) -> Vector2
pub fn bezier_derivative( self, control_1: Vector2, control_2: Vector2, end: Vector2, t: f32 ) -> Vector2
pub fn bezier_interpolate( self, control_1: Vector2, control_2: Vector2, end: Vector2, t: f32 ) -> Vector2
pub fn cubic_interpolate( self, b: Vector2, pre_a: Vector2, post_b: Vector2, weight: f32 ) -> Vector2
pub fn cubic_interpolate_in_time( self, b: Vector2, pre_a: Vector2, post_b: Vector2, weight: f32, b_t: f32, pre_a_t: f32, post_b_t: f32 ) -> Vector2
pub fn is_zero_approx(self) -> bool
pub fn posmod(self, pmod: f32) -> Vector2
pub fn posmodv(self, modv: Vector2) -> Vector2
pub fn sign(self) -> Vector2
pub fn snapped(self, step: Vector2) -> Vector2
Trait Implementations§
§impl AddAssign for Vector2
impl AddAssign for Vector2
§fn add_assign(&mut self, rhs: Vector2)
fn add_assign(&mut self, rhs: Vector2)
+=
operation. Read more§impl DivAssign<f32> for Vector2
impl DivAssign<f32> for Vector2
§fn div_assign(&mut self, rhs: f32)
fn div_assign(&mut self, rhs: f32)
/=
operation. Read more§impl DivAssign for Vector2
impl DivAssign for Vector2
§fn div_assign(&mut self, rhs: Vector2)
fn div_assign(&mut self, rhs: Vector2)
/=
operation. Read more§impl Export for Vector2
impl Export for Vector2
§fn default_export_info() -> PropertyHintInfo
fn default_export_info() -> PropertyHintInfo
§impl Extend<Vector2> for PackedVector2Array
impl Extend<Vector2> for PackedVector2Array
Extends aPackedVector2Array
with the contents of an iterator
§fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = Vector2>,
fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = Vector2>,
source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)§impl FromGodot for Vector2
impl FromGodot for Vector2
§fn try_from_godot(
via: <Vector2 as GodotConvert>::Via
) -> Result<Vector2, ConvertError>
fn try_from_godot( via: <Vector2 as GodotConvert>::Via ) -> Result<Vector2, ConvertError>
§fn from_godot(via: Self::Via) -> Self
fn from_godot(via: Self::Via) -> Self
§fn try_from_variant(variant: &Variant) -> Result<Self, ConvertError>
fn try_from_variant(variant: &Variant) -> Result<Self, ConvertError>
Variant
.§fn from_variant(variant: &Variant) -> Self
fn from_variant(variant: &Variant) -> Self
§impl FromIterator<Vector2> for PackedVector2Array
impl FromIterator<Vector2> for PackedVector2Array
Creates a PackedVector2Array
from an iterator.
§fn from_iter<I>(iter: I) -> PackedVector2Arraywhere
I: IntoIterator<Item = Vector2>,
fn from_iter<I>(iter: I) -> PackedVector2Arraywhere
I: IntoIterator<Item = Vector2>,
§impl GodotConvert for Vector2
impl GodotConvert for Vector2
§impl Index<Vector2Axis> for Vector2
impl Index<Vector2Axis> for Vector2
§impl IndexMut<Vector2Axis> for Vector2
impl IndexMut<Vector2Axis> for Vector2
§fn index_mut(&mut self, axis: Vector2Axis) -> &mut f32
fn index_mut(&mut self, axis: Vector2Axis) -> &mut f32
container[index]
) operation. Read more§impl Mul<Vector2> for Transform2D
impl Mul<Vector2> for Transform2D
§impl MulAssign<f32> for Vector2
impl MulAssign<f32> for Vector2
§fn mul_assign(&mut self, rhs: f32)
fn mul_assign(&mut self, rhs: f32)
*=
operation. Read more§impl MulAssign for Vector2
impl MulAssign for Vector2
§fn mul_assign(&mut self, rhs: Vector2)
fn mul_assign(&mut self, rhs: Vector2)
*=
operation. Read more§impl SubAssign for Vector2
impl SubAssign for Vector2
§fn sub_assign(&mut self, rhs: Vector2)
fn sub_assign(&mut self, rhs: Vector2)
-=
operation. Read more