Skip to main content

Vector2

Struct Vector2 

Source
#[repr(C)]
pub struct Vector2 { pub x: f32, pub y: f32, }

Fields§

§x: f32§y: f32

Implementations§

Source§

impl Vector2

Source

pub const ZERO: Self

The zero vector (0, 0).

Source

pub const ONE: Self

The vector (1, 1).

Source

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

Construct a new Vector2.

Source

pub fn zero() -> Self

Zero vector. (raymath Vector2Zero)

Source

pub fn one() -> Self

Vector with both components set to 1. (raymath Vector2One)

Source

pub fn add_value(self, add: f32) -> Self

Add scalar to both components. (raymath Vector2AddValue)

Source

pub fn sub_value(self, sub: f32) -> Self

Subtract scalar from both components. (raymath Vector2SubtractValue)

Source

pub fn length(self) -> f32

Vector length. (raymath Vector2Length)

Source

pub fn length_sqr(self) -> f32

Squared vector length. (raymath Vector2LengthSqr)

Source

pub fn dot(self, other: Vector2) -> f32

Dot product. (raymath Vector2DotProduct)

Source

pub fn cross(self, other: Vector2) -> f32

Cross product (scalar). (raymath Vector2CrossProduct)

Source

pub fn distance(self, other: Vector2) -> f32

Distance between two vectors. (raymath Vector2Distance)

Source

pub fn distance_sqr(self, other: Vector2) -> f32

Squared distance between two vectors. (raymath Vector2DistanceSqr)

Source

pub fn angle(self, other: Vector2) -> f32

Angle between two vectors (radians). (raymath Vector2Angle)

Source

pub fn line_angle(start: Vector2, end: Vector2) -> f32

Angle of line defined by two points. (raymath Vector2LineAngle)

Source

pub fn scale(self, scale: f32) -> Self

Scale vector by scalar. (raymath Vector2Scale)

Source

pub fn multiply(self, other: Vector2) -> Self

Component-wise multiply. (raymath Vector2Multiply)

Source

pub fn negate(self) -> Self

Negate vector. (raymath Vector2Negate)

Source

pub fn divide(self, other: Vector2) -> Self

Component-wise divide. (raymath Vector2Divide)

Source

pub fn normalize(self) -> Self

Normalize vector. (raymath Vector2Normalize)

Source

pub fn transform(self, mat: Matrix) -> Self

Transform by matrix. (raymath Vector2Transform)

Source

pub fn lerp(self, other: Vector2, amount: f32) -> Self

Linear interpolation. (raymath Vector2Lerp)

Source

pub fn reflect(self, normal: Vector2) -> Self

Reflect vector about normal. (raymath Vector2Reflect)

Source

pub fn min(self, other: Vector2) -> Self

Component-wise minimum. (raymath Vector2Min)

Source

pub fn max(self, other: Vector2) -> Self

Component-wise maximum. (raymath Vector2Max)

Source

pub fn rotate(self, angle: f32) -> Self

Rotate by angle (radians). (raymath Vector2Rotate)

Source

pub fn move_towards(self, target: Vector2, max_distance: f32) -> Self

Move towards target by at most maxDistance. (raymath Vector2MoveTowards)

Source

pub fn invert(self) -> Self

Invert components (1/x, 1/y). (raymath Vector2Invert)

Source

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

Clamp components between min and max vectors. (raymath Vector2Clamp)

Source

pub fn clamp_value(self, min: f32, max: f32) -> Self

Clamp length between min and max scalars. (raymath Vector2ClampValue)

Source

pub fn equals(self, other: Vector2) -> bool

Approximate equality (uses raymath epsilon). (raymath Vector2Equals)

Source

pub fn refract(self, n: Vector2, r: f32) -> Self

Refract through surface with index ratio r. (raymath Vector2Refract)

Trait Implementations§

Source§

impl Add for Vector2

Source§

type Output = Vector2

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl AddAssign for Vector2

Source§

fn add_assign(&mut self, rhs: Vector2)

Performs the += operation. Read more
Source§

impl Clone for Vector2

Source§

fn clone(&self) -> Vector2

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() -> Vector2

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

impl Div for Vector2

Source§

type Output = Vector2

The resulting type after applying the / operator.
Source§

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

Performs the / operation. Read more
Source§

impl From<(f32, f32)> for Vector2

Source§

fn from((x, y): (f32, f32)) -> Self

Construct from an (x, y) tuple.

Source§

impl From<[f32; 2]> for Vector2

Source§

fn from([x, y]: [f32; 2]) -> Self

Construct from an [x, y] array.

Source§

impl Mul for Vector2

Source§

type Output = Vector2

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: 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, rhs: f32) -> Vector2

Performs the * operation. Read more
Source§

impl MulAssign<f32> for Vector2

Source§

fn mul_assign(&mut self, rhs: 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: &Vector2) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
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, rhs: Vector2) -> Vector2

Performs the - operation. Read more
Source§

impl SubAssign for Vector2

Source§

fn sub_assign(&mut self, rhs: 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> 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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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

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.