alloy::math::vec

Struct Vec3i

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

A 3-component non-owning view of an integral Euclidean vector.

§Guarantees

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

§Relation to Vector3i

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

Implementations§

source§

impl Vec3i

source

pub const fn from_array(array: &[i32; 3]) -> &Self

Forms a reference to a Vec3i from a 3-component i32 array.

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

§Parameters
  • array - an array containing 3 i32 values.
§Examples

Basic use:

let array: [i32; 3] = [1, 42, 314];

let vec = Vec3i::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]);
source

pub fn from_mut_array(array: &mut [i32; 3]) -> &mut Self

Forms a mutable reference to a Vec3i from a 3-component i32 array.

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

§Parameters
  • array - an array containing 3 i32 values.
§Examples

Basic use:

let mut array: [i32; 3] = [1, 42, 314];

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

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

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

Forms a reference to a Vec3i from a slice of i32.

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

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

Basic use:

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

let vec = Vec3i::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]);

Invalid size:

let slice = &[1];

let vec = Vec3i::from_slice(slice);

assert!(vec.is_err());
source

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

Forms a mutable reference to a Vec3i from a mutable slice of i32.

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

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

Basic use:

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

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

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

Invalid size:

let slice = &mut [1];

let vec = Vec3i::from_mut_slice(slice);

assert!(vec.is_err());
source

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

Forms a reference to a Vec3i from a slice of i32 that is assumed to contain two values.

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

slice.len() must be equal to 2.

source

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

Forms a mutable reference to a Vec3i from a slice of i32 that is assumed to contain two values.

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

slice.len() must be equal to 2.

source

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

Forms a reference to a Vec3i from a pointer to a contiguous sequence of at least two i32s.

§Parameters
  • ptr - the pointer to a sequence of i32 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 i32) -> &'a mut Vec3i

Forms a mutable reference to a Vec3i from a pointer to a contiguous sequence of at least two i32s.

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

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

source

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

Returns this Vec3i as a slice of i32.

source

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

Returns this Vec3i as a mutable slice of i32.

source

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

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

source

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

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

source

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

Returns an iterator over the vector.

source

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

Returns a mutable iterator over the vector.

source

pub const fn x(&self) -> i32

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

source

pub const fn y(&self) -> i32

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

source

pub fn z(&self) -> i32

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

source

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

Returns the xy coordinates of this vector as a Vec3i.

source

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

Returns the yz coordinates of this vector as a Vec3i.

source

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

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

source

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

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

source

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

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

source

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

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

source

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

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

source

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

Sets the x-component

§Parameters
  • x - the X-component
source

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

Sets the y-component

§Parameters
  • y - the Y-component
source

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

Sets the z-component

§Parameters
  • z - the Z-component
source

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

Sets the X and Y components of this vector

§Parameters
  • xy - the X and Y components o
source

pub fn set_yz(&mut self, xy: &Vec2i)

Sets the Y and Z components of this vector

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

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

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

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

pub fn abs(&self) -> Vector3i

Computes the absolute value of self

source

pub fn min(&self, rhs: &Vec3i) -> Vector3i

Computes the minimum of each vector.

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

pub fn max(&self, rhs: &Vec3i) -> Vector3i

Computes the maximum of each vector.

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

Trait Implementations§

source§

impl Add<&Vec3i> for &Vector3i

source§

type Output = Vector3i

The resulting type after applying the + operator.
source§

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

Performs the + operation. Read more
source§

impl Add<&Vec3i> for Vector3i

source§

type Output = Vector3i

The resulting type after applying the + operator.
source§

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

Performs the + operation. Read more
source§

impl Add<&Vector3i> for &Vec3i

source§

type Output = Vector3i

The resulting type after applying the + operator.
source§

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

Performs the + operation. Read more
source§

impl Add<Vector3i> for &Vec3i

source§

type Output = Vector3i

The resulting type after applying the + operator.
source§

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

Performs the + operation. Read more
source§

impl Add for &Vec3i

source§

type Output = Vector3i

The resulting type after applying the + operator.
source§

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

Performs the + operation. Read more
source§

impl AddAssign<&Vec3i> for Vec3i

source§

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

Performs the += operation. Read more
source§

impl AddAssign<&Vec3i> for Vector3i

source§

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

Performs the += operation. Read more
source§

impl AsMut<[i32]> for Vec3i

source§

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

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

impl AsMut<Vec3i> for Vector3i

source§

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

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

impl AsRef<[i32]> for Vec3i

source§

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

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

impl AsRef<Vec3i> for Vector3i

source§

fn as_ref(&self) -> &Vec3i

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

impl Borrow<[i32]> for Vec3i

source§

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

Immutably borrows from an owned value. Read more
source§

impl Borrow<Vec3i> for Vector3i

source§

fn borrow(&self) -> &Vec3i

Immutably borrows from an owned value. Read more
source§

impl BorrowMut<[i32]> for Vec3i

source§

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

Mutably borrows from an owned value. Read more
source§

impl BorrowMut<Vec3i> for Vector3i

source§

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

Mutably borrows from an owned value. Read more
source§

impl Debug for Vec3i

source§

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

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

impl Display for Vec3i

source§

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

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

impl Div<i32> for &Vec3i

source§

type Output = Vector3i

The resulting type after applying the / operator.
source§

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

Performs the / operation. Read more
source§

impl DivAssign<i32> for Vec3i

source§

fn div_assign(&mut self, rhs: i32)

Performs the /= operation. Read more
source§

impl From<&Vec3i> for Vector3

source§

fn from(value: &Vec3i) -> Self

Converts to this type from the input type.
source§

impl From<&Vec3i> for Vector3i

source§

fn from(value: &Vec3i) -> Self

Converts to this type from the input type.
source§

impl<I> Index<I> for Vec3i
where I: SliceIndex<[i32]>,

source§

type Output = <I as SliceIndex<[i32]>>::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 Vec3i
where I: SliceIndex<[i32]>,

source§

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

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

impl Mul<&Vec3i> for i32

source§

type Output = Vector3i

The resulting type after applying the * operator.
source§

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

Performs the * operation. Read more
source§

impl Mul<i32> for &Vec3i

source§

type Output = Vector3i

The resulting type after applying the * operator.
source§

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

Performs the * operation. Read more
source§

impl MulAssign<i32> for Vec3i

source§

fn mul_assign(&mut self, rhs: i32)

Performs the *= operation. Read more
source§

impl Neg for &Vec3i

source§

type Output = Vector3i

The resulting type after applying the - operator.
source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
source§

impl Ord for Vec3i

source§

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

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

impl PartialEq for Vec3i

source§

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

source§

fn partial_cmp(&self, other: &Vec3i) -> 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<i32> for &Vec3i

source§

type Output = Vector3i

The resulting type after applying the % operator.
source§

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

Performs the % operation. Read more
source§

impl RemAssign<i32> for Vec3i

source§

fn rem_assign(&mut self, rhs: i32)

Performs the %= operation. Read more
source§

impl Sub<&Vec3i> for &Vector3i

source§

type Output = Vector3i

The resulting type after applying the - operator.
source§

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

Performs the - operation. Read more
source§

impl Sub<&Vec3i> for Vector3i

source§

type Output = Vector3i

The resulting type after applying the - operator.
source§

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

Performs the - operation. Read more
source§

impl Sub<&Vector3i> for &Vec3i

source§

type Output = Vector3i

The resulting type after applying the - operator.
source§

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

Performs the - operation. Read more
source§

impl Sub<Vector3i> for &Vec3i

source§

type Output = Vector3i

The resulting type after applying the - operator.
source§

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

Performs the - operation. Read more
source§

impl Sub for &Vec3i

source§

type Output = Vector3i

The resulting type after applying the - operator.
source§

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

Performs the - operation. Read more
source§

impl SubAssign<&Vec3i> for Vec3i

source§

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

Performs the -= operation. Read more
source§

impl SubAssign<&Vec3i> for Vector3i

source§

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

Performs the -= operation. Read more
source§

impl ToOwned for Vec3i

source§

type Owned = Vector3i

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 Vec3i

source§

impl StructuralPartialEq for Vec3i

Auto Trait Implementations§

§

impl Freeze for Vec3i

§

impl RefUnwindSafe for Vec3i

§

impl Send for Vec3i

§

impl !Sized for Vec3i

§

impl Sync for Vec3i

§

impl Unpin for Vec3i

§

impl UnwindSafe for Vec3i

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