alloy::math::vec

Struct Vec4u

source
pub struct Vec4u(/* private fields */);
Expand description

A 4-component non-owning view of an unsigned Euclidean vector.

§Guarantees

This type has the strict requirement that it can only reference a 4-component slice of u32 values. It is guaranteed to never refer to more or less than 4 entries.

§Relation to Vector4u

Vec4u is a non-owning equivalent of Vector4u. This enables non-vector types to either Deref or provide conversion-related utilities into Vec4u types to be able to access and benefit from vector operations.

Implementations§

source§

impl Vec4u

source

pub const fn from_array(array: &[u32; 4]) -> &Self

Forms a reference to a Vec4u from a 4-component u32 array.

This function is identical to from_slice_unchecked, except it is not marked unsafe.

§Parameters
  • array - an array containing 4 u32 values.
§Examples

Basic use:

let array: [u32; 4] = [1, 42, 314, 9];

let vec = Vec4u::from_array(&array);

assert_eq!(vec.as_ptr(), array.as_ptr());
assert_eq!(vec.x(), array[0]);
assert_eq!(vec.y(), array[1]);
assert_eq!(vec.z(), array[2]);
assert_eq!(vec.w(), array[3]);
source

pub fn from_mut_array(array: &mut [u32; 4]) -> &mut Self

Forms a mutable reference to a Vec4u from a 4-component u32 array.

This function is identical to from_mut_slice_unchecked, except it is not marked unsafe.

§Parameters
  • array - an array containing 4 u32 values.
§Examples

Basic use:

let mut array: [u32; 4] = [1, 420, 314, 9];

let vec = Vec4u::from_mut_array(&mut array);

assert_eq!(vec.as_ptr(), array.as_ptr());
source

pub const fn from_slice(slice: &[u32]) -> Result<&Self, VecError>

Forms a reference to a Vec4u from a slice of u32.

This requires that slice.len() == 4, otherwise this returns VecError.

§Parameters
  • slice - the slice of u32s.
§Examples

Basic use:

let slice = &[1, 42, 314, 9];

let vec = Vec4u::from_slice(slice).unwrap();

assert_eq!(vec.as_ptr(), slice.as_ptr());
assert_eq!(vec.x(), slice[0]);
assert_eq!(vec.y(), slice[1]);
assert_eq!(vec.z(), slice[2]);
assert_eq!(vec.w(), slice[3]);

Invalid size:

let slice = &[1];

let vec = Vec4u::from_slice(slice);

assert!(vec.is_err());
source

pub fn from_mut_slice(slice: &mut [u32]) -> Result<&mut Self, VecError>

Forms a mutable reference to a Vec4u from a mutable slice of u32.

This requires that slice.len() == 4, otherwise this returns VecError.

§Parameters
  • slice - the mutable slice of u32s.
§Examples

Basic use:

let slice = &mut [1, 42, 314, 9];

let vec = Vec4u::from_mut_slice(slice).unwrap();

assert_eq!(vec.as_ptr(), slice.as_ptr());

Invalid size:

let slice = &mut [1];

let vec = Vec4u::from_mut_slice(slice);

assert!(vec.is_err());
source

pub const unsafe fn from_slice_unchecked(slice: &[u32]) -> &Self

Forms a reference to a Vec4u from a slice of u32 that is assumed to contain two values.

§Parameters
  • slice - the slice of u32s.
§Safety

slice.len() must be equal to 2.

source

pub unsafe fn from_mut_slice_unchecked(slice: &mut [u32]) -> &mut Self

Forms a mutable reference to a Vec4u from a slice of u32 that is assumed to contain two values.

§Parameters
  • slice - the mutable slice of u32s.
§Safety

slice.len() must be equal to 2.

source

pub const unsafe fn from_ptr_unchecked<'a>(ptr: *const u32) -> &'a Vec4u

Forms a reference to a Vec2u from a pointer to a contiguous sequence of at least two u32s.

§Parameters
  • ptr - the pointer to a sequence of u32 values
§Safety

ptr must point to an allocated object that references at least two entries

source

pub unsafe fn from_mut_ptr_unchecked<'a>(ptr: *mut u32) -> &'a mut Vec4u

Forms a mutable reference to a Vec3u from a pointer to a contiguous sequence of at least two u32s.

§Parameters
  • ptr - the pointer to a sequence of u32 values
§Safety

ptr must point to an allocated object that references at least two entries

source

pub const fn as_slice(&self) -> &[u32]

Returns this Vec4u as a slice of u32.

source

pub fn as_mut_slice(&mut self) -> &mut [u32]

Returns this Vec4u as a mutable slice of u32.

source

pub const fn as_ptr(&self) -> *const u32

Returns a raw pointer to u32 of the vector’s buffer.

source

pub fn as_mut_ptr(&mut self) -> *mut u32

Returns a mutable raw pointer to u32 of the vector’s buffer.

source

pub fn iter(&self) -> impl Iterator<Item = &u32>

Returns an iterator over the vector.

source

pub fn iter_mut(&mut self) -> impl Iterator<Item = &mut u32>

Returns a mutable iterator over the vector.

source

pub fn x(&self) -> u32

Returns the X-coordinate of this 4-component vector.

source

pub fn y(&self) -> u32

Returns the Y-coordinate of this 4-component vector.

source

pub fn z(&self) -> u32

Returns the Z-coordinate of this 4-component vector.

source

pub fn w(&self) -> u32

Returns the W-coordinate of this 4-component vector.

source

pub const fn xy(&self) -> &Vec2u

Returns the xy coordinates of this vector as a Vec2u.

source

pub const fn yz(&self) -> &Vec2u

Returns the yz coordinates of this vector as a Vec2u.

source

pub const fn zw(&self) -> &Vec2u

Returns the zw coordinates of this vector as a Vec2u.

source

pub const fn xyz(&self) -> &Vec3u

Returns the xyz coordinates of this vector as a Vec2u.

source

pub const fn yzw(&self) -> &Vec3u

Returns the yz coordinates of this vector as a Vec2u.

source

pub fn x_mut(&mut self) -> &mut u32

Returns a mutable reference to the X-coordinate of this 3-component vector.

source

pub fn y_mut(&mut self) -> &mut u32

Returns a mutable reference to the Y-coordinate of this 3-component vector.

source

pub fn z_mut(&mut self) -> &mut u32

Returns a mutable reference to the Z-coordinate of this 3-component vector.

source

pub fn w_mut(&mut self) -> &mut u32

Returns a mutable reference to the W-coordinate of this 3-component vector.

source

pub fn xy_mut(&mut self) -> &mut Vec2u

Returns a mutable reference to the xy coordinates of this vector.

source

pub fn yz_mut(&mut self) -> &mut Vec2u

Returns a mutable reference to the yz coordinates of this vector.

source

pub fn zw_mut(&mut self) -> &mut Vec2u

Returns a mutable reference to the zw coordinates of this vector.

source

pub fn xyz_mut(&mut self) -> &mut Vec3u

Returns a mutable reference to the yz coordinates of this vector.

source

pub fn yzw_mut(&mut self) -> &mut Vec3u

Returns a mutable reference to the zw coordinates of this vector.

source

pub fn set_x(&mut self, x: u32)

Sets the x-component

§Parameters
  • x - the X-component
source

pub fn set_y(&mut self, y: u32)

Sets the y-component

§Parameters
  • y - the Y-component
source

pub fn set_z(&mut self, z: u32)

Sets the z-component

§Parameters
  • z - theZ-component
source

pub fn set_w(&mut self, w: u32)

Sets the w-component

§Parameters
  • w - the W-component
source

pub fn set_xy(&mut self, xy: &Vec2u)

Sets the X and Y components of this vector

§Parameters
  • xy - the X and Y components of the Vec4u
source

pub fn set_yz(&mut self, yz: &Vec2u)

Sets the Y and Z components of this vector

§Parameters
  • yz - the Y and Z components of the Vec4u
source

pub fn set_zw(&mut self, zw: &Vec2u)

Sets the Z and W components of this vector

§Parameters
  • zw - the Z and W components of the Vec4u
source

pub fn set_xyz(&mut self, xyz: &Vec3u)

Sets the X, Y, and Z components of this vector

§Parameters
  • xyz - the X, Y, and Z components of the Vec4u`
source

pub fn set_yzw(&mut self, yzw: &Vec3u)

Sets the Y, Z and W components of this vector

§Parameters
  • yzw - the Y, Z, and W components of the Vec4u
source

pub fn set(&mut self, other: &Vec4u)

Sets all the components of this vector the values from other.

§Parameters
  • other - the other Vec3u to set.
source

pub fn min(&self, rhs: &Vec4u) -> Vector4u

Computes the minimum of each vector.

§Parameters
  • lhs - the left vector
  • rhs - the right vector
source

pub fn max(&self, rhs: &Vec4u) -> Vector4u

Computes the maximum of each vector.

§Parameters
  • lhs - the left vector
  • rhs - the right vector

Trait Implementations§

source§

impl Add<&Vec4u> for &Vector4u

source§

type Output = Vector4u

The resulting type after applying the + operator.
source§

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

Performs the + operation. Read more
source§

impl Add<&Vec4u> for Vector4u

source§

type Output = Vector4u

The resulting type after applying the + operator.
source§

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

Performs the + operation. Read more
source§

impl Add<&Vector4u> for &Vec4u

source§

type Output = Vector4u

The resulting type after applying the + operator.
source§

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

Performs the + operation. Read more
source§

impl Add<Vector4u> for &Vec4u

source§

type Output = Vector4u

The resulting type after applying the + operator.
source§

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

Performs the + operation. Read more
source§

impl Add for &Vec4u

source§

type Output = Vector4u

The resulting type after applying the + operator.
source§

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

Performs the + operation. Read more
source§

impl AddAssign<&Vec4u> for Vec4u

source§

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

Performs the += operation. Read more
source§

impl AddAssign<&Vec4u> for Vector4u

source§

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

Performs the += operation. Read more
source§

impl AsMut<[u32]> for Vec4u

source§

fn as_mut(&mut self) -> &mut [u32]

Converts this type into a mutable reference of the (usually inferred) input type.
source§

impl AsMut<Vec4u> for Vector4u

source§

fn as_mut(&mut self) -> &mut Vec4u

Converts this type into a mutable reference of the (usually inferred) input type.
source§

impl AsRef<[u32]> for Vec4u

source§

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

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

impl AsRef<Vec4u> for Vector4u

source§

fn as_ref(&self) -> &Vec4u

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

impl Borrow<[u32]> for Vec4u

source§

fn borrow(&self) -> &[u32]

Immutably borrows from an owned value. Read more
source§

impl Borrow<Vec4u> for Vector4u

source§

fn borrow(&self) -> &Vec4u

Immutably borrows from an owned value. Read more
source§

impl BorrowMut<[u32]> for Vec4u

source§

fn borrow_mut(&mut self) -> &mut [u32]

Mutably borrows from an owned value. Read more
source§

impl BorrowMut<Vec4u> for Vector4u

source§

fn borrow_mut(&mut self) -> &mut Vec4u

Mutably borrows from an owned value. Read more
source§

impl Debug for Vec4u

source§

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

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

impl Display for Vec4u

source§

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

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

impl Div<u32> for &Vec4u

source§

type Output = Vector4u

The resulting type after applying the / operator.
source§

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

Performs the / operation. Read more
source§

impl DivAssign<u32> for Vec4u

source§

fn div_assign(&mut self, rhs: u32)

Performs the /= operation. Read more
source§

impl From<&Vec4u> for Vector4

source§

fn from(value: &Vec4u) -> Self

Converts to this type from the input type.
source§

impl From<&Vec4u> for Vector4u

source§

fn from(value: &Vec4u) -> Self

Converts to this type from the input type.
source§

impl<I> Index<I> for Vec4u
where I: SliceIndex<[u32]>,

source§

type Output = <I as SliceIndex<[u32]>>::Output

The returned type after indexing.
source§

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

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

impl<I> IndexMut<I> for Vec4u
where I: SliceIndex<[u32]>,

source§

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

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

impl Mul<&Vec4u> for u32

source§

type Output = Vector4u

The resulting type after applying the * operator.
source§

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

Performs the * operation. Read more
source§

impl Mul<u32> for &Vec4u

source§

type Output = Vector4u

The resulting type after applying the * operator.
source§

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

Performs the * operation. Read more
source§

impl MulAssign<u32> for Vec4u

source§

fn mul_assign(&mut self, rhs: u32)

Performs the *= operation. Read more
source§

impl Ord for Vec4u

source§

fn cmp(&self, other: &Vec4u) -> Ordering

This method returns an Ordering between self and other. Read more
source§

impl PartialEq for Vec4u

source§

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

source§

fn partial_cmp(&self, other: &Vec4u) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Rem<u32> for &Vec4u

source§

type Output = Vector4u

The resulting type after applying the % operator.
source§

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

Performs the % operation. Read more
source§

impl RemAssign<u32> for Vec4u

source§

fn rem_assign(&mut self, rhs: u32)

Performs the %= operation. Read more
source§

impl Sub<&Vec4u> for &Vector4u

source§

type Output = Vector4u

The resulting type after applying the - operator.
source§

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

Performs the - operation. Read more
source§

impl Sub<&Vec4u> for Vector4u

source§

type Output = Vector4u

The resulting type after applying the - operator.
source§

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

Performs the - operation. Read more
source§

impl Sub<&Vector4u> for &Vec4u

source§

type Output = Vector4u

The resulting type after applying the - operator.
source§

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

Performs the - operation. Read more
source§

impl Sub<Vector4u> for &Vec4u

source§

type Output = Vector4u

The resulting type after applying the - operator.
source§

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

Performs the - operation. Read more
source§

impl Sub for &Vec4u

source§

type Output = Vector4u

The resulting type after applying the - operator.
source§

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

Performs the - operation. Read more
source§

impl SubAssign<&Vec4u> for Vec4u

source§

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

Performs the -= operation. Read more
source§

impl SubAssign<&Vec4u> for Vector4u

source§

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

Performs the -= operation. Read more
source§

impl ToOwned for Vec4u

source§

type Owned = Vector4u

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> Self::Owned

Creates owned data from borrowed data, usually by cloning. Read more
1.63.0 · source§

fn clone_into(&self, target: &mut Self::Owned)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl Eq for Vec4u

source§

impl StructuralPartialEq for Vec4u

Auto Trait Implementations§

§

impl Freeze for Vec4u

§

impl RefUnwindSafe for Vec4u

§

impl Send for Vec4u

§

impl !Sized for Vec4u

§

impl Sync for Vec4u

§

impl Unpin for Vec4u

§

impl UnwindSafe for Vec4u

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

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more