Struct godot::prelude::Vector2

#[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

pub const ZERO: Vector2 = _

Vector with all components set to 0.0.

pub const ONE: Vector2 = _

Vector with all components set to 1.0.

pub const INF: Vector2 = _

Vector with all components set to real::INFINITY.

pub const LEFT: Vector2 = _

Unit vector in -X direction (right in 2D coordinate system).

pub const RIGHT: Vector2 = _

Unit vector in +X direction (right in 2D coordinate system).

pub const UP: Vector2 = _

Unit vector in -Y direction (up in 2D coordinate system).

pub const DOWN: Vector2 = _

Unit vector in +Y direction (down in 2D coordinate system).

pub const fn new(x: f32, y: f32) -> Vector2

Constructs a new Vector2 from the given x and y.

pub const fn splat(v: f32) -> Vector2

Constructs a new Vector2 with both components set to v.

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

Returns the result of rotating this vector by angle (in radians).

pub fn coords(&self) -> (f32, f32)

§

impl Vector2

pub fn abs(self) -> Vector2

Returns a new vector with all components in absolute values (i.e. positive or zero).

pub fn coord_min(self, other: Vector2) -> Vector2

Returns a new vector containing the minimum of the two vectors, component-wise.

pub fn coord_max(self, other: Vector2) -> Vector2

Returns a new vector containing the maximum of the two vectors, component-wise.

§

impl Vector2

pub fn length(self) -> f32

Returns the length (magnitude) of this vector.

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

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 Add for Vector2

§

type Output = Vector2

The resulting type after applying the + operator.
§

fn add(self, rhs: Vector2) -> <Vector2 as Add>::Output

Performs the + operation. Read more
§

impl AddAssign for Vector2

§

fn add_assign(&mut self, rhs: Vector2)

Performs the += operation. Read more
§

impl ApproxEq for Vector2

§

fn approx_eq(&self, other: &Vector2) -> bool

§

impl Clone for Vector2

§

fn clone(&self) -> Vector2

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl Debug for Vector2

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
§

impl Default for Vector2

§

fn default() -> Vector2

Returns the “default value” for a type. Read more
§

impl Display for Vector2

Formats the vector like Godot: (x, y).

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
§

impl Div<f32> for Vector2

§

type Output = Vector2

The resulting type after applying the / operator.
§

fn div(self, rhs: f32) -> <Vector2 as Div<f32>>::Output

Performs the / operation. Read more
§

impl Div for Vector2

§

type Output = Vector2

The resulting type after applying the / operator.
§

fn div(self, rhs: Vector2) -> <Vector2 as Div>::Output

Performs the / operation. Read more
§

impl DivAssign<f32> for Vector2

§

fn div_assign(&mut self, rhs: f32)

Performs the /= operation. Read more
§

impl DivAssign for Vector2

§

fn div_assign(&mut self, rhs: Vector2)

Performs the /= operation. Read more
§

impl Export for Vector2

§

fn default_export_info() -> PropertyHintInfo

The export info to use for an exported field of this type, if no other export info is specified.
§

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>,

Extends a collection with the contents of an iterator. Read more
source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
§

impl FromGodot for Vector2

§

fn try_from_godot( via: <Vector2 as GodotConvert>::Via ) -> Result<Vector2, ConvertError>

Performs the conversion.
§

fn from_godot(via: Self::Via) -> Self

⚠️ Performs the conversion. Read more
§

fn try_from_variant(variant: &Variant) -> Result<Self, ConvertError>

Performs the conversion from a Variant.
§

fn from_variant(variant: &Variant) -> Self

⚠️ Performs the conversion from a Variant. Read more
§

impl FromIterator<Vector2> for PackedVector2Array

Creates a PackedVector2Array from an iterator.

§

fn from_iter<I>(iter: I) -> PackedVector2Array
where I: IntoIterator<Item = Vector2>,

Creates a value from an iterator. Read more
§

impl GodotConvert for Vector2

§

type Via = Vector2

The type through which Self is represented in Godot.
§

impl Index<Vector2Axis> for Vector2

§

type Output = f32

The returned type after indexing.
§

fn index(&self, axis: Vector2Axis) -> &f32

Performs the indexing (container[index]) operation. Read more
§

impl IndexMut<Vector2Axis> for Vector2

§

fn index_mut(&mut self, axis: Vector2Axis) -> &mut f32

Performs the mutable indexing (container[index]) operation. Read more
§

impl Mul<Vector2> for Transform2D

§

type Output = Vector2

The resulting type after applying the * operator.
§

fn mul(self, rhs: Vector2) -> <Transform2D as Mul<Vector2>>::Output

Performs the * operation. Read more
§

impl Mul<f32> for Vector2

§

type Output = Vector2

The resulting type after applying the * operator.
§

fn mul(self, rhs: f32) -> <Vector2 as Mul<f32>>::Output

Performs the * operation. Read more
§

impl Mul for Vector2

§

type Output = Vector2

The resulting type after applying the * operator.
§

fn mul(self, rhs: Vector2) -> <Vector2 as Mul>::Output

Performs the * operation. Read more
§

impl MulAssign<f32> for Vector2

§

fn mul_assign(&mut self, rhs: f32)

Performs the *= operation. Read more
§

impl MulAssign for Vector2

§

fn mul_assign(&mut self, rhs: Vector2)

Performs the *= operation. Read more
§

impl Neg for Vector2

§

type Output = Vector2

The resulting type after applying the - operator.
§

fn neg(self) -> <Vector2 as Neg>::Output

Performs the unary - operation. Read more
§

impl PartialEq for Vector2

§

fn eq(&self, other: &Vector2) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
§

impl<'a> Product<&'a Vector2> for Vector2

§

fn product<I>(iter: I) -> Vector2
where I: Iterator<Item = &'a Vector2>,

Element-wise product of all vectors in the iterator.

§

impl Product for Vector2

§

fn product<I>(iter: I) -> Vector2
where I: Iterator<Item = Vector2>,

Element-wise product of all vectors in the iterator.

§

impl Sub for Vector2

§

type Output = Vector2

The resulting type after applying the - operator.
§

fn sub(self, rhs: Vector2) -> <Vector2 as Sub>::Output

Performs the - operation. Read more
§

impl SubAssign for Vector2

§

fn sub_assign(&mut self, rhs: Vector2)

Performs the -= operation. Read more
§

impl<'a> Sum<&'a Vector2> for Vector2

§

fn sum<I>(iter: I) -> Vector2
where I: Iterator<Item = &'a Vector2>,

Element-wise sum of all vectors in the iterator.

§

impl Sum for Vector2

§

fn sum<I>(iter: I) -> Vector2
where I: Iterator<Item = Vector2>,

Element-wise sum of all vectors in the iterator.

§

impl ToGodot for Vector2

§

fn to_godot(&self) -> <Vector2 as GodotConvert>::Via

Converts this type to the Godot type by reference, usually by cloning.
§

fn into_godot(self) -> <Vector2 as GodotConvert>::Via

Converts this type to the Godot type. Read more
§

fn to_variant(&self) -> Variant

Converts this type to a Variant.
§

impl TypeStringHint for Vector2

§

fn type_string() -> String

Returns the representation of this type as a type string. Read more
§

impl Var for Vector2

§

impl ArrayElement for Vector2

§

impl Copy for Vector2

§

impl GodotType for Vector2

§

impl StructuralPartialEq for Vector2

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.