Skip to main content

Vector2

Struct Vector2 

Source
pub struct Vector2 {
    pub x: f32,
    pub y: f32,
}
Expand description

A vector with two single-precision components.

Fields§

§x: f32

The X component of the vector.

§y: f32

The Y component of the vector.

Implementations§

Source§

impl Vector2

Source

pub const ZERO: Vector2

The vector (0, 0).

Source

pub const ONE: Vector2

The vector (1, 1).

Source

pub const UNIT_X: Vector2

The vector (1, 0).

Source

pub const UNIT_Y: Vector2

The vector (0, 1).

Source

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

Creates a vector from its components.

Source

pub const fn from_value(value: f32) -> Self

Creates a vector whose components all have the same value.

Source

pub fn abs(value: Vector2) -> Vector2

Returns a vector whose elements are the absolute values of each of the specified vector’s elements.

Source

pub fn clamp(value1: Vector2, min: Vector2, max: Vector2) -> Vector2

Restricts a vector between a minimum and a maximum value (min(max(value, min), max), so max wins when the bounds are inverted).

Source

pub fn distance(value1: Vector2, value2: Vector2) -> f32

Computes the Euclidean distance between the two given points.

Source

pub fn distance_squared(value1: Vector2, value2: Vector2) -> f32

Returns the Euclidean distance squared between two specified points.

Source

pub fn dot(value1: Vector2, value2: Vector2) -> f32

Returns the dot product of two vectors.

Source

pub fn length(&self) -> f32

Returns the length of the vector.

Source

pub fn length_squared(&self) -> f32

Returns the length of the vector squared.

Source

pub fn lerp(value1: Vector2, value2: Vector2, amount: f32) -> Vector2

Performs a linear interpolation between two vectors based on the given weighting.

Source

pub fn max(value1: Vector2, value2: Vector2) -> Vector2

Returns a vector whose elements are the maximum of each of the pairs of elements in two specified vectors.

Source

pub fn min(value1: Vector2, value2: Vector2) -> Vector2

Returns a vector whose elements are the minimum of each of the pairs of elements in two specified vectors.

Source

pub fn normalize(value: Vector2) -> Vector2

Returns a vector with the same direction as the specified vector, but with a length of one (NaN components for a zero-length vector).

Source

pub fn square_root(value: Vector2) -> Vector2

Returns a vector whose elements are the square root of each of a specified vector’s elements.

Source

pub fn transform(position: Vector2, matrix: Matrix3x2) -> Vector2

Transforms a vector by a specified 3x2 matrix.

Source

pub fn transform_matrix4x4(position: Vector2, matrix: Matrix4x4) -> Vector2

Transforms a vector by a specified 4x4 matrix.

Source

pub fn transform_quaternion(value: Vector2, rotation: Quaternion) -> Vector2

Transforms a vector by the specified rotation.

Source

pub fn transform_normal(normal: Vector2, matrix: Matrix3x2) -> Vector2

Transforms a vector normal by the given 3x2 matrix.

Trait Implementations§

Source§

impl Add for Vector2

Source§

type Output = Vector2

The resulting type after applying the + operator.
Source§

fn add(self, right: Vector2) -> Vector2

Performs the + operation. Read more
Source§

impl AddAssign for Vector2

Source§

fn add_assign(&mut self, right: Vector2)

Performs the += operation. Read more
Source§

impl BatchValue for Vector2

Source§

fn write_to(&self, out: &mut Vec<u8>)

Source§

fn read_from(input: &mut BatchValueReader<'_>) -> Self

Source§

impl Clone for Vector2

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for Vector2

Source§

impl Debug for Vector2

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for Vector2

Source§

fn default() -> Self

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

impl Display for Vector2

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Div for Vector2

Source§

type Output = Vector2

The resulting type after applying the / operator.
Source§

fn div(self, right: Vector2) -> Vector2

Performs the / operation. Read more
Source§

impl Div<f32> for Vector2

Source§

type Output = Vector2

The resulting type after applying the / operator.
Source§

fn div(self, right: f32) -> Vector2

Performs the / operation. Read more
Source§

impl DivAssign for Vector2

Source§

fn div_assign(&mut self, right: Vector2)

Performs the /= operation. Read more
Source§

impl DivAssign<f32> for Vector2

Source§

fn div_assign(&mut self, right: f32)

Performs the /= operation. Read more
Source§

impl ExpressionVariantValue for Vector2

Source§

const FFI_VARIANT_TYPE: Option<VariantType>

The variant type a foreign function parameter of this type is matched against, or None when the type cannot be a foreign function parameter.
Source§

fn try_from_variant(v: &ExpressionVariant) -> Option<Self>

Source§

fn into_variant(self) -> ExpressionVariant

Source§

impl From<Vector2> for Vector

The widening conversion to the double-precision vector.

Source§

fn from(value: Vector2) -> Vector

Converts to this type from the input type.
Source§

impl From<Vector2> for ExpressionVariant

Source§

fn from(value: Vector2) -> ExpressionVariant

Converts to this type from the input type.
Source§

impl From<Vector> for Vector2

The narrowing conversion of the double-precision vector.

Source§

fn from(value: Vector) -> Vector2

Converts to this type from the input type.
Source§

impl IInterpolator<Vector2> for Vector2Interpolator

Source§

fn interpolate(&self, from: Vector2, to: Vector2, progress: f32) -> Vector2

Source§

impl Mul for Vector2

Source§

type Output = Vector2

The resulting type after applying the * operator.
Source§

fn mul(self, right: Vector2) -> Vector2

Performs the * operation. Read more
Source§

impl Mul<Vector2> for f32

Source§

type Output = Vector2

The resulting type after applying the * operator.
Source§

fn mul(self, right: Vector2) -> Vector2

Performs the * operation. Read more
Source§

impl Mul<f32> for Vector2

Source§

type Output = Vector2

The resulting type after applying the * operator.
Source§

fn mul(self, right: f32) -> Vector2

Performs the * operation. Read more
Source§

impl MulAssign for Vector2

Source§

fn mul_assign(&mut self, right: Vector2)

Performs the *= operation. Read more
Source§

impl MulAssign<f32> for Vector2

Source§

fn mul_assign(&mut self, right: f32)

Performs the *= operation. Read more
Source§

impl Neg for Vector2

Source§

type Output = Vector2

The resulting type after applying the - operator.
Source§

fn neg(self) -> Vector2

Performs the unary - operation. Read more
Source§

impl PartialEq for Vector2

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Vector2

Source§

impl Sub for Vector2

Source§

type Output = Vector2

The resulting type after applying the - operator.
Source§

fn sub(self, right: Vector2) -> Vector2

Performs the - operation. Read more
Source§

impl SubAssign for Vector2

Source§

fn sub_assign(&mut self, right: Vector2)

Performs the -= operation. Read more

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> AnyValue for T
where T: PartialEq + 'static,

Source§

fn any_value_as_any(&self) -> &(dyn Any + 'static)

Source§

fn any_value_eq(&self, other: &(dyn AnyValue + 'static)) -> bool

Source§

fn any_value_type_name(&self) -> &'static str

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> ClassDefaults for T
where T: ?Sized,

Source§

fn static_constructor()

The static constructor of a type: work done once per thread, after the properties of the type are registered and before its first instance exists (class handlers, affects_render, metadata overrides). Read more
Source§

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

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> PropertyValue for T
where T: Clone + PartialEq + 'static,

Source§

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

Source§

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§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

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

Source§

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.