Struct crystal_ball::math::Vec3

source ·
pub struct Vec3 {
    pub x: f64,
    pub y: f64,
    pub z: f64,
}
Expand description

A 3-dimensional vector.

Fields§

§x: f64§y: f64§z: f64

Implementations§

source§

impl Vec3

source

pub const X: Vec3 = _

source

pub const Y: Vec3 = _

source

pub const Z: Vec3 = _

source

pub const ZERO: Vec3 = _

source

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

Create a new Vec3.

source

pub fn splat(value: f64) -> Self

Create a new Vec3 with all elements set to value.

source

pub fn random(rng: &mut TlsWyRand, min: f64, max: f64) -> Self

Generate a Vec3 where each component is a uniform random number between min and max.

source

pub fn random_unit_vector(rng: &mut TlsWyRand) -> Self

Generate a random Vec3 on the surface of the unit sphere with uniform (i.e. isotropic) distribution.

source

pub fn random_in_unit_sphere(rng: &mut TlsWyRand) -> Self

Generate a random Vec3 inside the unit sphere with uniform distribution.

source

pub fn reflect(self, normal: Vec3) -> Self

Reflect the self with respect to the given normal.

source

pub fn refract( self, normal: Vec3, n1: f64, n2: f64, rng: &mut TlsWyRand ) -> Self

Refract the self with respect to the given normal using n1 and n2 as the indices of refraction.

source

pub fn to_point3(&self) -> Point3

Convert the Vec2 to a Point2.

source

pub fn magnitude(&self) -> f64

Calculate the vector’s magnitude (length).

source

pub fn magnitude_squared(&self) -> f64

Calculate the square of the vector’s magnitude (length).

source

pub fn abs(&self) -> f64

Return the absolute value (synonym magnitude).

source

pub fn normalize(&self) -> Self

Return the unit vector parallel to self.

§Panics

Panics if self cannot be normalized.

source

pub fn dot(vec_a: Vec3, vec_b: Vec3) -> f64

Calculate the dot product between two Vec3s.

source

pub fn cross(vec_a: Vec3, vec_b: Vec3) -> Self

Calculate the cross product between two Vec3s.

source

pub fn extend(&self, w: f64) -> Vec4

Create a new Vec4 using the x, y and z values of self and the given w value.

source

pub fn xyz(&self) -> Vec2

Create a new Vec2 discarding the z value.

Trait Implementations§

source§

impl Add<Vec3> for Point3

§

type Output = Point3

The resulting type after applying the + operator.
source§

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

Performs the + operation. Read more
source§

impl Add for Vec3

§

type Output = Vec3

The resulting type after applying the + operator.
source§

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

Performs the + operation. Read more
source§

impl AddAssign<Vec3> for Point3

source§

fn add_assign(&mut self, rhs: Vec3)

Performs the += operation. Read more
source§

impl AddAssign for Vec3

source§

fn add_assign(&mut self, rhs: Vec3)

Performs the += operation. Read more
source§

impl Clone for Vec3

source§

fn clone(&self) -> Vec3

Returns a copy 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() -> Vec3

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

impl Div<f64> for Vec3

§

type Output = Vec3

The resulting type after applying the / operator.
source§

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

Performs the / operation. Read more
source§

impl DivAssign<f64> for Vec3

source§

fn div_assign(&mut self, rhs: f64)

Performs the /= operation. Read more
source§

impl From<[f64; 3]> for Vec3

source§

fn from(s: [f64; 3]) -> Self

Converts to this type from the input type.
source§

impl From<(f64, f64, f64)> for Vec3

source§

fn from(t: (f64, f64, f64)) -> Self

Converts to this type from the input type.
source§

impl From<Color> for Vec3

source§

fn from(c: Color) -> Self

Converts to this type from the input type.
source§

impl From<Point3> for Vec3

source§

fn from(p: Point3) -> Self

Converts to this type from the input type.
source§

impl From<Vec3> for Color

source§

fn from(v: Vec3) -> Self

Converts to this type from the input type.
source§

impl From<Vec3> for Point3

source§

fn from(v: Vec3) -> Self

Converts to this type from the input type.
source§

impl Index<usize> for Vec3

§

type Output = f64

The returned type after indexing.
source§

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

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

impl IndexMut<usize> for Vec3

source§

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

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

impl Mul<Vec3> for Mat4

§

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 f64

§

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<f64> for Vec3

§

type Output = Vec3

The resulting type after applying the * operator.
source§

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

Performs the * operation. Read more
source§

impl MulAssign<f64> for Vec3

source§

fn mul_assign(&mut self, rhs: f64)

Performs the *= operation. Read more
source§

impl Neg for Vec3

§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Sub<Vec3> for Point3

§

type Output = Point3

The resulting type after applying the - operator.
source§

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

Performs the - operation. Read more
source§

impl Sub for Vec3

§

type Output = Vec3

The resulting type after applying the - operator.
source§

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

Performs the - operation. Read more
source§

impl SubAssign<Vec3> for Point3

source§

fn sub_assign(&mut self, rhs: Vec3)

Performs the -= operation. Read more
source§

impl SubAssign for Vec3

source§

fn sub_assign(&mut self, rhs: Vec3)

Performs the -= operation. Read more
source§

impl TryFrom<&[f64]> for Vec3

§

type Error = &'static str

The type returned in the event of a conversion error.
source§

fn try_from(s: &[f64]) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<Vec<f64>> for Vec3

§

type Error = &'static str

The type returned in the event of a conversion error.
source§

fn try_from(v: Vec<f64>) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl Copy for Vec3

source§

impl StructuralPartialEq for Vec3

Auto Trait Implementations§

§

impl RefUnwindSafe for Vec3

§

impl Send for Vec3

§

impl Sync for Vec3

§

impl Unpin 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> 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.

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<R, P> ReadPrimitive<R> for P
where R: Read + ReadEndian<P>, P: Default,

source§

fn read_from_little_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_little_endian().
source§

fn read_from_big_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_big_endian().
source§

fn read_from_native_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_native_endian().
source§

impl<T> ToOwned for T
where T: Clone,

§

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, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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.