Vector4

Struct Vector4 

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

Represents a 4-dimensional vector with f32 components.

Implementations§

Source§

impl Vector4

Source

pub fn new(data: [f32; 4]) -> Self

Creates a new 4-vector from the provided array data.

§Example
let v = Vector4::new([1.0, 2.0, 3.0, 4.0]);
assert_eq!(v.get(0), 1.0);
Source

pub fn zero() -> Self

Creates a zero vector (all components are 0.0).

§Example
use crate::bb_geometry::linear_algebra::vector4::*;
let zero = Vector4::zero();
assert_eq!(zero.get(2), 0.0);
Source

pub fn get(&self, index: usize) -> f32

Gets the value at the specified index using a method call.

Prefer using the index operator vector[index] for more idiomatic access.

§Panics

Panics if index is out of bounds (>= 4).

§Example
use crate::bb_geometry::linear_algebra::vector4::*;
let v = Vector4::new([1.0, 2.0, 3.0, 4.0]);
assert_eq!(v.get(1), 2.0);
Source

pub fn set(&mut self, index: usize, value: f32)

Sets the value at the specified index using a method call.

Prefer using the mutable index operator vector[index] = value for more idiomatic modification.

§Panics

Panics if index is out of bounds (>= 4).

§Example
use crate::bb_geometry::linear_algebra::vector4::*;
let mut v = Vector4::zero();
v.set(3, 5.0);
assert_eq!(v.get(3), 5.0);
Source

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

Calculates the dot (inner) product of this vector with another vector.

result = self[0]*other[0] + self[1]*other[1] + self[2]*other[2] + self[3]*other[3]

§Example
use crate::bb_geometry::linear_algebra::vector4::*;
let v1 = Vector4::new([1.0, 2.0, 3.0, 4.0]);
let v2 = Vector4::new([5.0, 6.0, 7.0, 8.0]);
// 1*5 + 2*6 + 3*7 + 4*8 = 5 + 12 + 21 + 32 = 70
assert_eq!(v1.dot(&v2), 70.0);
Source

pub fn l2_norm(&self) -> f32

Source

pub fn l1_norm(&self) -> f32

Source

pub fn is_almost_zero(&self) -> bool

Source

pub fn wedge_product(&self, other: &Self) -> Matrix4x4

Calculates the wedge product (antisymmetric outer product) of two vectors.

Returns a 4x4 antisymmetric linear_algebra M where M[i][j] = self[i]*other[j] - self[j]*other[i]. This represents the bivector formed by the two vectors.

§Example
use crate::bb_geometry::linear_algebra::vector4::*;
use crate::bb_geometry::linear_algebra::matrix4x4::*;
let u = Vector4::new([1.0, 2.0, 0.0, 0.0]);
let v = Vector4::new([0.0, 3.0, 4.0, 0.0]);
let wedge_matrix = u.wedge_product(&v);

// M[0][1] = u[0]*v[1] - u[1]*v[0] = 1*3 - 2*0 = 3.0
assert_eq!(wedge_matrix[(0, 1)], 3.0);
// M[1][0] = u[1]*v[0] - u[0]*v[1] = 2*0 - 1*3 = -3.0
assert_eq!(wedge_matrix[(1, 0)], -3.0);
// M[0][2] = u[0]*v[2] - u[2]*v[0] = 1*4 - 0*0 = 4.0
assert_eq!(wedge_matrix[(0, 2)], 4.0);
// M[1][2] = u[1]*v[2] - u[2]*v[1] = 2*4 - 0*3 = 8.0
assert_eq!(wedge_matrix[(1, 2)], 8.0);
// M[0][0] should be 0
assert_eq!(wedge_matrix[(0, 0)], 0.0);
// M[3][x] should be 0 as u[3] and v[3] are 0
assert_eq!(wedge_matrix[(3, 0)], 0.0);
assert_eq!(wedge_matrix[(0, 3)], 0.0);

Trait Implementations§

Source§

impl Add<&Vector4> for &Vector4

Implements vector addition using the + operator (&Vector4 + &Vector4).

Source§

type Output = Vector4

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl Add<&Vector4> for Vector4

Source§

type Output = Vector4

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl Add<Vector4> for &Vector4

Source§

type Output = Vector4

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl Add for Vector4

Source§

type Output = Vector4

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl Clone for Vector4

Source§

fn clone(&self) -> Vector4

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 Vector4

Source§

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

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

impl Index<usize> for Vector4

Allows accessing vector components using index vector[index].

§Panics

Panics if index is out of bounds (>= 4).

Source§

type Output = f32

The returned type after indexing.
Source§

fn index(&self, index: usize) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl IndexMut<usize> for Vector4

Allows mutating vector components using index vector[index] = value.

§Panics

Panics if index is out of bounds (>= 4).

Source§

fn index_mut(&mut self, index: usize) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl Mul<&Vector4> for &Matrix4x4

Implements Matrix * Vector multiplication (&Matrix4x4 * &Vector4). Treats the vector as a column vector.

Source§

type Output = Vector4

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl Mul<&Vector4> for Matrix4x4

Source§

type Output = Vector4

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl Mul<&Vector4> for f32

Implements scalar multiplication (f32 * &Vector4).

Source§

type Output = Vector4

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl Mul<Vector4> for &Matrix4x4

Source§

type Output = Vector4

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl Mul<Vector4> for Matrix4x4

Source§

type Output = Vector4

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl Mul<Vector4> for f32

Source§

type Output = Vector4

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl Mul<f32> for &Vector4

Implements scalar multiplication (&Vector4 * f32).

Source§

type Output = Vector4

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 Vector4

Source§

type Output = Vector4

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl Neg for &Vector4

Source§

type Output = Vector4

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
Source§

impl Neg for Vector4

Implements vector negation using the unary - operator (-vector).

Source§

type Output = Vector4

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
Source§

impl PartialEq for Vector4

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · 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 Sub<&Vector4> for &Vector4

Implements vector subtraction using the - operator (&Vector4 - &Vector4).

Source§

type Output = Vector4

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

impl Sub<&Vector4> for Vector4

Source§

type Output = Vector4

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

impl Sub<Vector4> for &Vector4

Source§

type Output = Vector4

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

impl Sub for Vector4

Source§

type Output = Vector4

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

impl Copy for Vector4

Source§

impl StructuralPartialEq for Vector4

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

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V