Skip to main content

vec3

Struct vec3 

Source
#[repr(C)]
pub struct vec3<T>(pub T, pub T, pub T);
Expand description

3 dimensional vector.

Tuple Fields§

§0: T§1: T§2: T

Implementations§

Source§

impl<T> vec3<T>

Source

pub fn xy(self) -> vec2<T>

Get the first two components as a vec2

Source

pub fn extend(self, w: T) -> vec4<T>

Extend with another component and get a vec4

Source

pub fn map<U, F: Fn(T) -> U>(self, f: F) -> vec3<U>

Map every component (coordinate)

Source

pub fn zip<U>(self, v: vec3<U>) -> vec3<(T, U)>

Zip two vectors together

Source§

impl<T: Clone> vec3<T>

Source

pub fn splat(value: T) -> Self

Construct a vector with all components set to specified value

Source§

impl<T: UNum> vec3<T>

Source

pub const ZERO: Self

A zero 3-d vector

Source

pub const UNIT_X: Self

A unit X

Source

pub const UNIT_Y: Self

A unit Y

Source

pub const UNIT_Z: Self

A unit Z

Source§

impl<T: Copy + Num> vec3<T>

Source

pub fn dot(a: Self, b: Self) -> T

Calculate dot product of two vectors.

§Examples
assert_eq!(vec3::dot(vec3(1, 2, 3), vec3(3, 4, 5)), 26);
Source

pub fn cross(a: Self, b: Self) -> Self

Calculate cross product of two vectors.

§Examples
assert_eq!(vec3::cross(vec3(1, 2, 3), vec3(3, 4, 5)), vec3(-2, 4, -2));
Source§

impl<T: Float> vec3<T>

Source

pub fn normalize(self) -> Self

Normalize a vector.

§Examples
let v: vec3<f64> = vec3(1.0, 2.0, 3.0);
assert!((v.normalize().len() - 1.0).abs() < 1e-5);
Source

pub fn normalize_or_zero(self) -> Self

Normalizes a vector unless its length is approximately 0. Can be used to avoid division by 0.

Uses Approx::approx_eq to determine equality to zero

§Examples
let v = vec3(1.0, 2.0, 3.0);
assert_eq!(v.normalize_or_zero(), v.normalize());
let v = vec3(1e-10, 1e-10, 1e-10);
assert_eq!(v.normalize_or_zero(), vec3::ZERO);
Source

pub fn len(self) -> T

Calculate length of a vector.

Source

pub fn len_sqr(self) -> T

Calculate squared length of this vector

Source

pub fn into_2d(self) -> vec2<T>

Convert a homogenous 3d vector into 2d

Same as self.xy() / self.z

Source

pub fn clamp_len(self, len_range: impl FixedRangeBounds<T>) -> Self

Clamp vector’s length. Note that the range must be inclusive.

§Examples
let v = vec3(1.0, 2.0, 3.0);
assert_eq!(v.clamp_len(..=1.0), v.normalize());
Source

pub fn clamp_coordinates( self, x_range: impl FixedRangeBounds<T>, y_range: impl FixedRangeBounds<T>, z_range: impl FixedRangeBounds<T>, ) -> Self

Clamp vector in range. Note the range must be inclusive.

§Examples
let v = vec3(1.0, 2.0, 3.0);
assert_eq!(v.clamp_coordinates(.., 0.0..=1.0, 5.0..), vec3(1.0, 1.0, 5.0));
Source

pub fn transform(self, transform: mat4<T>) -> Self

Apply transformation matrix

Trait Implementations§

Source§

impl<T: Add<Output = T>> Add for vec3<T>

Source§

type Output = vec3<T>

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl<T: AddAssign> AddAssign for vec3<T>

Source§

fn add_assign(&mut self, rhs: Self)

Performs the += operation. Read more
Source§

impl<T: Clone> Clone for vec3<T>

Source§

fn clone(&self) -> vec3<T>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Copy> Copy for vec3<T>

Source§

impl<T: Debug> Debug for vec3<T>

Source§

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

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

impl<T> Deref for vec3<T>

Source§

type Target = XYZ<T>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &XYZ<T>

Dereferences the value.
Source§

impl<T> DerefMut for vec3<T>

Source§

fn deref_mut(&mut self) -> &mut XYZ<T>

Mutably dereferences the value.
Source§

impl<'de, T> Deserialize<'de> for vec3<T>
where T: Deserialize<'de>,

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<T: Display> Display for vec3<T>

Source§

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

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

impl<T: Div<Output = T>> Div for vec3<T>

Source§

type Output = vec3<T>

The resulting type after applying the / operator.
Source§

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

Performs the / operation. Read more
Source§

impl<T: Copy + Div<Output = T>> Div<T> for vec3<T>

Source§

type Output = vec3<T>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: T) -> Self

Performs the / operation. Read more
Source§

impl<T: DivAssign> DivAssign for vec3<T>

Source§

fn div_assign(&mut self, rhs: Self)

Performs the /= operation. Read more
Source§

impl<T: Copy + DivAssign> DivAssign<T> for vec3<T>

Source§

fn div_assign(&mut self, rhs: T)

Performs the /= operation. Read more
Source§

impl<T: Eq> Eq for vec3<T>

Source§

impl<T> From<[T; 3]> for vec3<T>

Source§

fn from(v: [T; 3]) -> vec3<T>

Converts to this type from the input type.
Source§

impl<T: Hash> Hash for vec3<T>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<T: Mul<Output = T>> Mul for vec3<T>

Source§

type Output = vec3<T>

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl<T: Copy + Mul<Output = T>> Mul<T> for vec3<T>

Source§

type Output = vec3<T>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: T) -> Self

Performs the * operation. Read more
Source§

impl<T: Num + Copy> Mul<vec3<T>> for mat3<T>

Source§

type Output = vec3<T>

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl Mul<vec3<f32>> for f32

Source§

type Output = vec3<f32>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: vec3<f32>) -> vec3<f32>

Performs the * operation. Read more
Source§

impl Mul<vec3<f64>> for f64

Source§

type Output = vec3<f64>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: vec3<f64>) -> vec3<f64>

Performs the * operation. Read more
Source§

impl Mul<vec3<i8>> for i8

Source§

type Output = vec3<i8>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: vec3<i8>) -> vec3<i8>

Performs the * operation. Read more
Source§

impl Mul<vec3<i16>> for i16

Source§

type Output = vec3<i16>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: vec3<i16>) -> vec3<i16>

Performs the * operation. Read more
Source§

impl Mul<vec3<i32>> for i32

Source§

type Output = vec3<i32>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: vec3<i32>) -> vec3<i32>

Performs the * operation. Read more
Source§

impl Mul<vec3<i64>> for i64

Source§

type Output = vec3<i64>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: vec3<i64>) -> vec3<i64>

Performs the * operation. Read more
Source§

impl Mul<vec3<isize>> for isize

Source§

type Output = vec3<isize>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: vec3<isize>) -> vec3<isize>

Performs the * operation. Read more
Source§

impl Mul<vec3<u8>> for u8

Source§

type Output = vec3<u8>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: vec3<u8>) -> vec3<u8>

Performs the * operation. Read more
Source§

impl Mul<vec3<u16>> for u16

Source§

type Output = vec3<u16>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: vec3<u16>) -> vec3<u16>

Performs the * operation. Read more
Source§

impl Mul<vec3<u32>> for u32

Source§

type Output = vec3<u32>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: vec3<u32>) -> vec3<u32>

Performs the * operation. Read more
Source§

impl Mul<vec3<u64>> for u64

Source§

type Output = vec3<u64>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: vec3<u64>) -> vec3<u64>

Performs the * operation. Read more
Source§

impl Mul<vec3<usize>> for usize

Source§

type Output = vec3<usize>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: vec3<usize>) -> vec3<usize>

Performs the * operation. Read more
Source§

impl<T: MulAssign> MulAssign for vec3<T>

Source§

fn mul_assign(&mut self, rhs: Self)

Performs the *= operation. Read more
Source§

impl<T: Copy + MulAssign> MulAssign<T> for vec3<T>

Source§

fn mul_assign(&mut self, rhs: T)

Performs the *= operation. Read more
Source§

impl<T: Neg<Output = T>> Neg for vec3<T>

Source§

type Output = vec3<T>

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self

Performs the unary - operation. Read more
Source§

impl<T: PartialEq> PartialEq for vec3<T>

Source§

fn eq(&self, other: &vec3<T>) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl<T> Serialize for vec3<T>
where T: Serialize,

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<T: PartialEq> StructuralPartialEq for vec3<T>

Source§

impl<T: Sub<Output = T>> Sub for vec3<T>

Source§

type Output = vec3<T>

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

impl<T: SubAssign> SubAssign for vec3<T>

Source§

fn sub_assign(&mut self, rhs: Self)

Performs the -= operation. Read more

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

impl<T> UnsafeUnpin for vec3<T>
where T: UnsafeUnpin,

§

impl<T> UnwindSafe for vec3<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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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.
Source§

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

Source§

fn vzip(self) -> V