Skip to main content

Vec3

Struct Vec3 

Source
pub struct Vec3 {
    pub x: f32,
    pub y: f32,
    pub z: f32,
}
Expand description

A len-3 column vector.

Fields§

§x: f32§y: f32§z: f32

Implementations§

Source§

impl Vec3

Source

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

Source

pub const fn new_zero() -> Self

Source

pub const fn x() -> Self

Source

pub const fn y() -> Self

Source

pub const fn z() -> Self

Source

pub fn from_slice(slice: &[f32]) -> Result<Self, BufError>

Construct from the first 3 values in a slice: &[x, y, z].

Source

pub fn to_arr(&self) -> [f32; 3]

Convert to a len-3 array: [x, y, z].

Source

pub fn splat(val: f32) -> Self

Source

pub fn truncate_n(&self, n: usize) -> Vec2

Returns this vector with the nth element removed (0-based). For example: truncate_n(0) => drops .x, returns Vec2(y, z) truncate_n(1) => drops .y, returns Vec2(x, z) truncate_n(2) => drops .z, returns Vec2(x, y)

Source

pub fn sum(&self) -> f32

Returns a sum of all elements

Source

pub fn any_perpendicular(&self) -> Self

Returns an arbitrary unit vector perpendicular to it.

Source

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

Source

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

Source§

impl Vec3

Source

pub fn hadamard_product(self, rhs: Self) -> Self

Calculates the Hadamard product (element-wise multiplication).

Source

pub fn magnitude_squared(self) -> f32

Returns the vector magnitude squared

Source

pub fn magnitude(&self) -> f32

Returns the vector magnitude

Source

pub fn normalize(&mut self)

Normalize, modifying in place.

Source

pub fn to_normalized(self) -> Self

Returns the normalized version of the vector.

Source

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

Returns the dot product with another vector.

Source

pub fn cross(&self, rhs: Self) -> Self

Calculate the cross product.

Source

pub fn project_to_plane(self, plane_norm: Self) -> Self

Project a vector onto a plane defined by its normal vector. Assumes self and plane_norm are unit vectors.

Source

pub fn project_to_vec(self, other: Self) -> Self

Projects this vector onto another vector.

Source§

impl Vec3

Source

pub fn to_bytes_uniform(&self) -> [u8; 16]

Convert to a byte array, e.g. for sending to a GPU. Note that this function pads with an extra 4 bytes, IOC with the hardware 16-byte alignment requirement. This assumes we’re using this in a uniform; Vertexes don’t use padding.

Source

pub fn to_bytes(&self) -> [u8; 12]

Convert to a native-endian byte array, e.g. for sending to a GPU.

Source

pub fn to_le_bytes(&self) -> [u8; 12]

Source

pub fn from_le_bytes(v: &[u8]) -> Self

Trait Implementations§

Source§

impl Add<f32> for Vec3

Source§

type Output = Vec3

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl Add for Vec3

Source§

type Output = Vec3

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl AddAssign<f32> for Vec3

Source§

fn add_assign(&mut self, rhs: f32)

Performs the += operation. Read more
Source§

impl AddAssign for Vec3

Source§

fn add_assign(&mut self, rhs: Self)

Performs the += operation. Read more
Source§

impl Clone for Vec3

Source§

fn clone(&self) -> Vec3

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 Vec3

Source§

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

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

impl Default for Vec3

Source§

fn default() -> Self

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

impl Display for Vec3

Available on crate feature std only.
Source§

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

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

impl Div<f32> for Vec3

Source§

type Output = Vec3

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 Vec3

Source§

fn div_assign(&mut self, rhs: f32)

Performs the /= operation. Read more
Source§

impl From<[f32; 3]> for Vec3

Source§

fn from(v: [f32; 3]) -> Self

Converts to this type from the input type.
Source§

impl From<Vec3> for Vec3

Source§

fn from(other: Vec3) -> Self

Converts to this type from the input type.
Source§

impl From<Vec3> for Vec3

Source§

fn from(other: Vec3) -> Self

Converts to this type from the input type.
Source§

impl Mul<Vec3> for Mat3

Source§

type Output = Vec3

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl Mul<Vec3> for Quaternion

Source§

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

Returns the multiplication of a Quaternion with a vector. This is a normal Quaternion multiplication where the vector is treated as a Quaternion with a W element value of zero. The Quaternion is post- multiplied by the vector.

Source§

type Output = Quaternion

The resulting type after applying the * operator.
Source§

impl Mul<f32> for Vec3

Source§

type Output = Vec3

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 Vec3

Source§

fn mul_assign(&mut self, rhs: f32)

Performs the *= operation. Read more
Source§

impl Neg for Vec3

Source§

type Output = Vec3

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
Source§

impl PartialEq for Vec3

Source§

fn eq(&self, other: &Vec3) -> 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<f32> for Vec3

Source§

type Output = Vec3

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

impl Sub for Vec3

Source§

type Output = Vec3

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

impl SubAssign<f32> for Vec3

Source§

fn sub_assign(&mut self, rhs: f32)

Performs the -= operation. Read more
Source§

impl SubAssign for Vec3

Source§

fn sub_assign(&mut self, rhs: Self)

Performs the -= operation. Read more
Source§

impl Sum for Vec3

Source§

fn sum<I: Iterator<Item = Vec3>>(iter: I) -> Vec3

Takes an iterator and generates Self from the elements by “summing up” the items.
Source§

impl Copy for Vec3

Source§

impl StructuralPartialEq for Vec3

Auto Trait Implementations§

§

impl Freeze for Vec3

§

impl RefUnwindSafe for Vec3

§

impl Send for Vec3

§

impl Sync for Vec3

§

impl Unpin for Vec3

§

impl UnsafeUnpin for Vec3

§

impl UnwindSafe for Vec3

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.