Vector2

Struct Vector2 

Source
#[repr(C)]
pub struct Vector2<T> { pub x: T, pub y: T, }
Expand description

A 2D vector with x and y components.

§Examples

use rs_math3d::vector::Vector2;
 
let v = Vector2::new(3.0, 4.0);
assert_eq!(v.x, 3.0);
assert_eq!(v.y, 4.0);

Fields§

§x: T

X component.

§y: T

Y component.

Implementations§

Source§

impl<T: Scalar> Vector2<T>

Source

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

Creates a vector from components.

Trait Implementations§

Source§

impl<T> Add for Vector2<T>
where T: Scalar,

Source§

type Output = Vector2<T>

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl<T: Clone> Clone for Vector2<T>

Source§

fn clone(&self) -> Vector2<T>

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<T: Debug> Debug for Vector2<T>

Source§

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

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

impl<T: Default> Default for Vector2<T>

Source§

fn default() -> Vector2<T>

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

impl<T> Div<T> for Vector2<T>
where T: Scalar,

Source§

type Output = Vector2<T>

The resulting type after applying the / operator.
Source§

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

Performs the / operation. Read more
Source§

impl<T> Div for Vector2<T>
where T: Scalar,

Source§

type Output = Vector2<T>

The resulting type after applying the / operator.
Source§

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

Performs the / operation. Read more
Source§

impl<T: FloatScalar> FloatVector<T> for Vector2<T>

Source§

fn length(&self) -> T

Computes the Euclidean length (magnitude) of the vector. Read more
Source§

fn normalize(&self) -> Self

Returns a unit vector in the same direction. Read more
Source§

fn distance(l: &Self, r: &Self) -> T

Computes the Euclidean distance between two vectors. Read more
Source§

fn length_squared(&self) -> T

Computes the squared length (avoids a square root). Read more
Source§

fn try_normalize(&self, epsilon: T) -> Option<Self>

Returns a normalized vector or None when the length is too small.
Source§

fn normalize_or_zero(&self, epsilon: T) -> Self

Returns a normalized vector or the zero vector when too small.
Source§

fn normalize_with_inv_len(&self, inv_len: T) -> Self

Normalizes using a precomputed inverse length (e.g., from rsqrt).
Source§

fn try_normalize_with_inv_len( &self, len_sq: T, inv_len: T, epsilon: T, ) -> Option<Self>

Normalizes with precomputed length squared and inverse length.
Source§

impl<T: Scalar> Mul<Matrix2<T>> for Vector2<T>

Source§

type Output = Vector2<T>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Matrix2<T>) -> Vector2<T>

Performs the * operation. Read more
Source§

impl<T> Mul<T> for Vector2<T>
where T: Scalar,

Source§

type Output = Vector2<T>

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl<T: Scalar> Mul<Vector2<T>> for Matrix2<T>

Source§

type Output = Vector2<T>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Vector2<T>) -> Vector2<T>

Performs the * operation. Read more
Source§

impl Mul<Vector2<f32>> for f32

Source§

type Output = Vector2<f32>

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl Mul<Vector2<f64>> for f64

Source§

type Output = Vector2<f64>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Vector2<f64>) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<Vector2<i32>> for i32

Source§

type Output = Vector2<i32>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Vector2<i32>) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<Vector2<i64>> for i64

Source§

type Output = Vector2<i64>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Vector2<i64>) -> Self::Output

Performs the * operation. Read more
Source§

impl<T> Mul for Vector2<T>
where T: Scalar,

Source§

type Output = Vector2<T>

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl<T: Scalar> Neg for Vector2<T>

Source§

type Output = Vector2<T>

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
Source§

impl<T> Rem<T> for Vector2<T>
where T: Scalar,

Source§

type Output = Vector2<T>

The resulting type after applying the % operator.
Source§

fn rem(self, rhs: T) -> Self::Output

Performs the % operation. Read more
Source§

impl<T> Rem for Vector2<T>
where T: Scalar,

Source§

type Output = Vector2<T>

The resulting type after applying the % operator.
Source§

fn rem(self, rhs: Vector2<T>) -> Self::Output

Performs the % operation. Read more
Source§

impl<T> Sub for Vector2<T>
where T: Scalar,

Source§

type Output = Vector2<T>

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

impl<T: Scalar> Swizzle2<T> for Vector2<T>

Source§

fn xx(&self) -> Vector2<T>

Returns a vector with components (x, x).
Source§

fn xy(&self) -> Vector2<T>

Returns a vector with components (x, y).
Source§

fn xz(&self) -> Vector2<T>

Returns a vector with components (x, z).
Source§

fn yx(&self) -> Vector2<T>

Returns a vector with components (y, x).
Source§

fn yy(&self) -> Vector2<T>

Returns a vector with components (y, y).
Source§

fn yz(&self) -> Vector2<T>

Returns a vector with components (y, z).
Source§

fn zx(&self) -> Vector2<T>

Returns a vector with components (z, x).
Source§

fn zy(&self) -> Vector2<T>

Returns a vector with components (z, y).
Source§

fn zz(&self) -> Vector2<T>

Returns a vector with components (z, z).
Source§

impl<T: Scalar> Vector<T> for Vector2<T>

Source§

fn zero() -> Self

Returns the zero vector (all components are zero).
Source§

fn dot(l: &Self, r: &Self) -> T

Computes the dot product of two vectors. Read more
Source§

fn add_vv(l: &Self, r: &Self) -> Self

Adds two vectors component-wise.
Source§

fn sub_vv(l: &Self, r: &Self) -> Self

Subtracts two vectors component-wise.
Source§

fn mul_vv(l: &Self, r: &Self) -> Self

Multiplies two vectors component-wise (Hadamard product).
Source§

fn div_vv(l: &Self, r: &Self) -> Self

Divides two vectors component-wise.
Source§

fn mul_vs(l: &Self, r: T) -> Self

Multiplies a vector by a scalar.
Source§

fn div_vs(l: &Self, r: T) -> Self

Divides a vector by a scalar.
Source§

fn rem_vv(l: &Self, r: &Self) -> Self

Computes the remainder of component-wise division.
Source§

fn min(l: &Self, r: &Self) -> Self

Returns a vector with the minimum components from both vectors.
Source§

fn max(l: &Self, r: &Self) -> Self

Returns a vector with the maximum components from both vectors.
Source§

impl<T: Copy> Copy for Vector2<T>

Auto Trait Implementations§

§

impl<T> Freeze for Vector2<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Vector2<T>
where T: RefUnwindSafe,

§

impl<T> Send for Vector2<T>
where T: Send,

§

impl<T> Sync for Vector2<T>
where T: Sync,

§

impl<T> Unpin for Vector2<T>
where T: Unpin,

§

impl<T> UnwindSafe for Vector2<T>
where T: UnwindSafe,

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.
Source§

impl<T, Rhs, Output> NumOps<Rhs, Output> for T
where T: Sub<Rhs, Output = Output> + Mul<Rhs, Output = Output> + Div<Rhs, Output = Output> + Add<Rhs, Output = Output> + Rem<Rhs, Output = Output>,