Struct batbox::Vec3[][src]

#[repr(C)]pub struct Vec3<T> {
    pub x: T,
    pub y: T,
    pub z: T,
}

3 dimensional vector.

Fields

x: T

x coordinate of the vector

y: T

y coordinate of the vector

z: T

z coordinate of the vector

Implementations

impl<T> Vec3<T>[src]

pub fn xy(self) -> Vec2<T>[src]

pub fn extend(self, w: T) -> Vec4<T>[src]

pub fn map<U, F: Fn(T) -> U>(self, f: F) -> Vec3<U>[src]

impl<T: Copy + Num> Vec3<T>[src]

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

Calculate dot product of two vectors.

Examples

use batbox::*;
assert_eq!(Vec3::dot(vec3(1, 2, 3), vec3(3, 4, 5)), 26);

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

Calculate cross product of two vectors.

Examples

use batbox::*;
assert_eq!(Vec3::cross(vec3(1, 2, 3), vec3(3, 4, 5)), vec3(-2, 4, -2));

impl<T: Float> Vec3<T>[src]

pub fn normalize(self) -> Self[src]

Normalize a vector.

Examples

use batbox::*;
let v: Vec3<f64> = vec3(1.0, 2.0, 3.0);
assert!((v.normalize().len() - 1.0).abs() < 1e-5);

pub fn len(self) -> T[src]

Calculate length of a vector.

pub fn clamp(self, max_len: T) -> Self[src]

Methods from Deref<Target = [T; 3]>

pub fn as_slice(&self) -> &[T][src]

🔬 This is a nightly-only experimental API. (array_methods)

Returns a slice containing the entire array. Equivalent to &s[..].

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

🔬 This is a nightly-only experimental API. (array_methods)

Returns a mutable slice containing the entire array. Equivalent to &mut s[..].

pub fn each_ref(&self) -> [&T; N][src]

🔬 This is a nightly-only experimental API. (array_methods)

Borrows each element and returns an array of references with the same size as self.

Example

#![feature(array_methods)]

let floats = [3.1, 2.7, -1.0];
let float_refs: [&f64; 3] = floats.each_ref();
assert_eq!(float_refs, [&3.1, &2.7, &-1.0]);

This method is particularly useful if combined with other methods, like map. This way, you can avoid moving the original array if its elements are not Copy.

#![feature(array_methods, array_map)]

let strings = ["Ferris".to_string(), "♥".to_string(), "Rust".to_string()];
let is_ascii = strings.each_ref().map(|s| s.is_ascii());
assert_eq!(is_ascii, [true, false, true]);

// We can still access the original array: it has not been moved.
assert_eq!(strings.len(), 3);

pub fn each_mut(&mut self) -> [&mut T; N][src]

🔬 This is a nightly-only experimental API. (array_methods)

Borrows each element mutably and returns an array of mutable references with the same size as self.

Example

#![feature(array_methods)]

let mut floats = [3.1, 2.7, -1.0];
let float_refs: [&mut f64; 3] = floats.each_mut();
*float_refs[0] = 0.0;
assert_eq!(float_refs, [&mut 0.0, &mut 2.7, &mut -1.0]);
assert_eq!(floats, [0.0, 2.7, -1.0]);

Trait Implementations

impl<T: Add<Output = T>> Add<Vec3<T>> for Vec3<T>[src]

type Output = Self

The resulting type after applying the + operator.

impl<T: AddAssign> AddAssign<Vec3<T>> for Vec3<T>[src]

impl<T: Clone> Clone for Vec3<T>[src]

impl<T: Copy> Copy for Vec3<T>[src]

impl<T: Debug> Debug for Vec3<T>[src]

impl<T> Deref for Vec3<T>[src]

type Target = [T; 3]

The resulting type after dereferencing.

impl<T> DerefMut for Vec3<T>[src]

impl<'de, T> Deserialize<'de> for Vec3<T> where
    T: Deserialize<'de>, 
[src]

impl<T: Display> Display for Vec3<T>[src]

impl<T: Copy + Div<Output = T>> Div<T> for Vec3<T>[src]

type Output = Self

The resulting type after applying the / operator.

impl<T: Div<Output = T>> Div<Vec3<T>> for Vec3<T>[src]

type Output = Self

The resulting type after applying the / operator.

impl<T: Copy + DivAssign> DivAssign<T> for Vec3<T>[src]

impl<T: DivAssign> DivAssign<Vec3<T>> for Vec3<T>[src]

impl<T: Eq> Eq for Vec3<T>[src]

impl<T> From<[T; 3]> for Vec3<T>[src]

impl<T: Hash> Hash for Vec3<T>[src]

impl<T: Copy + Mul<Output = T>> Mul<T> for Vec3<T>[src]

type Output = Self

The resulting type after applying the * operator.

impl<T: Mul<Output = T>> Mul<Vec3<T>> for Vec3<T>[src]

type Output = Self

The resulting type after applying the * operator.

impl<T: Copy + MulAssign> MulAssign<T> for Vec3<T>[src]

impl<T: MulAssign> MulAssign<Vec3<T>> for Vec3<T>[src]

impl<T: Neg<Output = T>> Neg for Vec3<T>[src]

type Output = Self

The resulting type after applying the - operator.

impl<T: PartialEq> PartialEq<Vec3<T>> for Vec3<T>[src]

impl<T> Serialize for Vec3<T> where
    T: Serialize
[src]

impl<T> StructuralEq for Vec3<T>[src]

impl<T> StructuralPartialEq for Vec3<T>[src]

impl<T: Sub<Output = T>> Sub<Vec3<T>> for Vec3<T>[src]

type Output = Self

The resulting type after applying the - operator.

impl<T: SubAssign> SubAssign<Vec3<T>> for Vec3<T>[src]

Auto Trait Implementations

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> UnwindSafe for Vec3<T> where
    T: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> DeserializeOwned for T where
    T: for<'de> Deserialize<'de>, 
[src]

impl<T> DynClone for T where
    T: Clone
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

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