Vec2

Struct Vec2 

Source
pub struct Vec2 { /* private fields */ }
Expand description

A 2D vector with f32 components.

Vec2 provides convenient methods for 2D vector arithmetic, normalization, and conversion.

§Example

use vectorama::Vec2;
let v = Vec2::new(1.0, 2.0);

Implementations§

Source§

impl Vec2

Source

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

Creates a new 2D vector from x and y components.

§Parameters
  • x: The x component.
  • y: The y component.
§Returns

A new Vec2 with the specified components.

Source

pub fn zeros() -> Self

Returns a vector with both components set to zero.

§Returns

A zero vector.

Source

pub fn ones() -> Self

Returns a vector with both components set to one.

§Returns

A vector with all components equal to 1.0.

Source

pub fn xyz(&self, z: f32) -> Vec3

Creates a 3D vector from this 2D vector and a given z component.

§Parameters
  • z: The z component for the resulting Vec3.
§Returns

A Vec3 with x, y from this vector and the specified z.

Source

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

Computes the dot product with another 2D vector.

§Parameters
  • other: The other vector.
§Returns

The dot product as a f32.

Source

pub fn magnitude(&self) -> f32

Computes the magnitude (length) of the vector.

§Returns

The magnitude as a f32.

Source

pub fn normalize(&self) -> Vec2

Returns a normalized (unit length) version of this vector.

§Returns

The normalized vector.

Trait Implementations§

Source§

impl Add<&Vec2> for &Vec2

Source§

type Output = Vec2

The resulting type after applying the + operator.
Source§

fn add(self, rhs: &Vec2) -> Self::Output

Performs the + operation. Read more
Source§

impl Add<&Vec2> for Vec2

Source§

type Output = Vec2

The resulting type after applying the + operator.
Source§

fn add(self, rhs: &Vec2) -> Self::Output

Performs the + operation. Read more
Source§

impl Add<Vec2> for &Vec2

Source§

type Output = Vec2

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Vec2) -> Self::Output

Performs the + operation. Read more
Source§

impl Add for Vec2

Source§

type Output = Vec2

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Vec2) -> Self::Output

Performs the + operation. Read more
Source§

impl AddAssign<&Vec2> for Translation2

Source§

fn add_assign(&mut self, rhs: &Vec2)

Performs the += operation. Read more
Source§

impl AddAssign<&Vec2> for Vec2

Source§

fn add_assign(&mut self, rhs: &Vec2)

Performs the += operation. Read more
Source§

impl AddAssign<Vec2> for Translation2

Source§

fn add_assign(&mut self, rhs: Vec2)

Performs the += operation. Read more
Source§

impl AddAssign for Vec2

Source§

fn add_assign(&mut self, rhs: Vec2)

Performs the += operation. Read more
Source§

impl AsRef<[f32]> for Vec2

Source§

fn as_ref(&self) -> &[f32]

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Clone for Vec2

Source§

fn clone(&self) -> Vec2

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Vec2

Source§

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

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

impl Default for Vec2

Source§

fn default() -> Vec2

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

impl Deref for Vec2

Source§

type Target = Vector2

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl DerefMut for Vec2

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

impl Div<f32> for &Vec2

Source§

type Output = Vec2

The resulting type after applying the / operator.
Source§

fn div(self, rhs: f32) -> Self::Output

Performs the / operation. Read more
Source§

impl Div<f32> for Vec2

Source§

type Output = Vec2

The resulting type after applying the / operator.
Source§

fn div(self, rhs: f32) -> Self::Output

Performs the / operation. Read more
Source§

impl DivAssign<f32> for Vec2

Source§

fn div_assign(&mut self, rhs: f32)

Performs the /= operation. Read more
Source§

impl From<[f32; 2]> for Vec2

Source§

fn from(value: [f32; 2]) -> Self

Converts to this type from the input type.
Source§

impl From<Matrix<2, 1>> for Vec2

Source§

fn from(value: Vector<2>) -> Self

Converts to this type from the input type.
Source§

impl From<Translation2> for Vec2

Source§

fn from(translation: Translation2) -> Self

Converts to this type from the input type.
Source§

impl From<Vec2> for Vector<2>

Source§

fn from(value: Vec2) -> Self

Converts to this type from the input type.
Source§

impl From<Vec2> for Scale2

Source§

fn from(vector: Vec2) -> Self

Converts to this type from the input type.
Source§

impl From<Vec2> for Translation2

Source§

fn from(vector: Vec2) -> Self

Converts to this type from the input type.
Source§

impl Mul<&Vec2> for &Matrix<2, 2>

Source§

type Output = Vec2

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: &Vec2) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<&Vec2> for &Scale2

Source§

type Output = Vec2

The resulting type after applying the * operator.
Source§

fn mul(self, vector: &Vec2) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<&Vec2> for &Translation2

Source§

type Output = Vec2

The resulting type after applying the * operator.
Source§

fn mul(self, vector: &Vec2) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<&Vec2> for Matrix<2, 2>

Source§

type Output = Vec2

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: &Vec2) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<&Vec2> for Scale2

Source§

type Output = Vec2

The resulting type after applying the * operator.
Source§

fn mul(self, vector: &Vec2) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<&Vec2> for Translation2

Source§

type Output = Vec2

The resulting type after applying the * operator.
Source§

fn mul(self, vector: &Vec2) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<&Vec2> for f32

Source§

type Output = Vec2

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: &Vec2) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<Vec2> for &Matrix<2, 2>

Source§

type Output = Vec2

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Vec2) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<Vec2> for &Scale2

Source§

type Output = Vec2

The resulting type after applying the * operator.
Source§

fn mul(self, vector: Vec2) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<Vec2> for &Translation2

Source§

type Output = Vec2

The resulting type after applying the * operator.
Source§

fn mul(self, vector: Vec2) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<Vec2> for Matrix<2, 2>

Source§

type Output = Vec2

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Vec2) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<Vec2> for Scale2

Source§

type Output = Vec2

The resulting type after applying the * operator.
Source§

fn mul(self, vector: Vec2) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<Vec2> for Translation2

Source§

type Output = Vec2

The resulting type after applying the * operator.
Source§

fn mul(self, vector: Vec2) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<Vec2> for f32

Source§

type Output = Vec2

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Vec2) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<f32> for &Vec2

Source§

type Output = Vec2

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: f32) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<f32> for Vec2

Source§

type Output = Vec2

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: f32) -> Self::Output

Performs the * operation. Read more
Source§

impl MulAssign<f32> for Vec2

Source§

fn mul_assign(&mut self, rhs: f32)

Performs the *= operation. Read more
Source§

impl Neg for Vec2

Source§

type Output = Vec2

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
Source§

impl Sub<&Vec2> for &Vec2

Source§

type Output = Vec2

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: &Vec2) -> Self::Output

Performs the - operation. Read more
Source§

impl Sub<&Vec2> for Vec2

Source§

type Output = Vec2

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: &Vec2) -> Self::Output

Performs the - operation. Read more
Source§

impl Sub<Vec2> for &Vec2

Source§

type Output = Vec2

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Vec2) -> Self::Output

Performs the - operation. Read more
Source§

impl Sub for Vec2

Source§

type Output = Vec2

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Vec2) -> Self::Output

Performs the - operation. Read more
Source§

impl SubAssign<&Vec2> for Translation2

Source§

fn sub_assign(&mut self, rhs: &Vec2)

Performs the -= operation. Read more
Source§

impl SubAssign<&Vec2> for Vec2

Source§

fn sub_assign(&mut self, rhs: &Vec2)

Performs the -= operation. Read more
Source§

impl SubAssign<Vec2> for Translation2

Source§

fn sub_assign(&mut self, rhs: Vec2)

Performs the -= operation. Read more
Source§

impl SubAssign for Vec2

Source§

fn sub_assign(&mut self, rhs: Vec2)

Performs the -= operation. Read more
Source§

impl Copy for Vec2

Auto Trait Implementations§

§

impl Freeze for Vec2

§

impl RefUnwindSafe for Vec2

§

impl Send for Vec2

§

impl Sync for Vec2

§

impl Unpin for Vec2

§

impl UnwindSafe for Vec2

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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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, 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.