Vector4

Struct Vector4 

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

A 4D vector with x, y, z, and w components.

Often used for homogeneous coordinates in 3D graphics.

§Examples

use rs_math3d::vector::Vector4;
 
let v = Vector4::new(1.0, 2.0, 3.0, 1.0);
// w=1 for positions, w=0 for directions

Fields§

§x: T

X component.

§y: T

Y component.

§z: T

Z component.

§w: T

W component.

Implementations§

Source§

impl<T: Scalar> Vector4<T>

Source

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

Creates a vector from components.

Trait Implementations§

Source§

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

Source§

type Output = Vector4<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 Vector4<T>

Source§

fn clone(&self) -> Vector4<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 Vector4<T>

Source§

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

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

impl<T: Default> Default for Vector4<T>

Source§

fn default() -> Vector4<T>

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

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

Source§

type Output = Vector4<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 Vector4<T>
where T: Scalar,

Source§

type Output = Vector4<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 Vector4<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<Matrix4<T>> for Vector4<T>

Source§

type Output = Vector4<T>

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

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

Source§

type Output = Vector4<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<Vector4<T>> for Matrix4<T>

Source§

type Output = Vector4<T>

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl Mul<Vector4<f32>> for f32

Source§

type Output = Vector4<f32>

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl Mul<Vector4<f64>> for f64

Source§

type Output = Vector4<f64>

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl Mul<Vector4<i32>> for i32

Source§

type Output = Vector4<i32>

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl Mul<Vector4<i64>> for i64

Source§

type Output = Vector4<i64>

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

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

Source§

type Output = Vector4<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 Vector4<T>

Source§

type Output = Vector4<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 Vector4<T>
where T: Scalar,

Source§

type Output = Vector4<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 Vector4<T>
where T: Scalar,

Source§

type Output = Vector4<T>

The resulting type after applying the % operator.
Source§

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

Performs the % operation. Read more
Source§

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

Source§

type Output = Vector4<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 Vector4<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> Swizzle3<T> for Vector4<T>

Source§

fn xxx(&self) -> Vector3<T>

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

fn xxy(&self) -> Vector3<T>

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

fn xxz(&self) -> Vector3<T>

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

fn xyx(&self) -> Vector3<T>

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

fn xyy(&self) -> Vector3<T>

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

fn xyz(&self) -> Vector3<T>

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

fn xzx(&self) -> Vector3<T>

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

fn xzy(&self) -> Vector3<T>

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

fn xzz(&self) -> Vector3<T>

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

fn yxx(&self) -> Vector3<T>

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

fn yxy(&self) -> Vector3<T>

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

fn yxz(&self) -> Vector3<T>

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

fn yyx(&self) -> Vector3<T>

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

fn yyy(&self) -> Vector3<T>

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

fn yyz(&self) -> Vector3<T>

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

fn yzx(&self) -> Vector3<T>

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

fn yzy(&self) -> Vector3<T>

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

fn yzz(&self) -> Vector3<T>

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

fn zxx(&self) -> Vector3<T>

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

fn zxy(&self) -> Vector3<T>

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

fn zxz(&self) -> Vector3<T>

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

fn zyx(&self) -> Vector3<T>

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

fn zyy(&self) -> Vector3<T>

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

fn zyz(&self) -> Vector3<T>

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

fn zzx(&self) -> Vector3<T>

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

fn zzy(&self) -> Vector3<T>

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

fn zzz(&self) -> Vector3<T>

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

impl<T: Scalar> Vector<T> for Vector4<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 Vector4<T>

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

impl<T> UnwindSafe for Vector4<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>,