Struct Vector

Source
pub struct Vector {
    pub x: f64,
    pub y: f64,
    pub z: f64,
}
Expand description

Vector represents a point in ℝ³.

Fields§

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

Implementations§

Source§

impl Vector

Source

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

Source

pub fn approx_eq(&self, other: &Vector) -> bool

approx_eq reports whether v and ov are equal within a small epsilon.

Source

pub fn norm(&self) -> f64

norm returns the vector’s norm.

Source

pub fn norm2(&self) -> f64

norm2 returns the square of the norm.

Source

pub fn normalize(&self) -> Self

normalize returns a unit vector in the same direction as v.

Source

pub fn dot(&self, other: &Self) -> f64

dot returns the standard dot product of v and ov.

Source

pub fn is_unit(&self) -> bool

is_unit returns whether this vector is of approximately unit length.

Source

pub fn abs(&self) -> Self

abs returns the vector with nonnegative components.

Source

pub fn cross(&self, other: &Self) -> Self

cross returns the standard cross product of v and ov.

Source

pub fn distance(&self, other: &Self) -> f64

distance returns the Euclidean distance between v and ov.

Source

pub fn angle(&self, other: &Self) -> Angle

angle returns the angle between v and ov.

Source

pub fn ortho(&self) -> Self

ortho returns a unit vector that is orthogonal to v. ortho(-v) = -ortho(v) for all v.

Source

pub fn largest_component(&self) -> Axis

largest_component returns the axis that represents the largest component in this vector.

Source

pub fn smallest_component(&self) -> Axis

smallest_component returns the axis that represents the smallest component in this vector.

Trait Implementations§

Source§

impl<'a, 'b> Add<&'b Vector> for &'a Vector

Source§

fn add(self, other: &'b Vector) -> Self::Output

add returns the standard vector sum of v and ov.

Source§

type Output = Vector

The resulting type after applying the + operator.
Source§

impl Add for Vector

Source§

type Output = Vector

The resulting type after applying the + operator.
Source§

fn add(self, other: Vector) -> Self::Output

Performs the + operation. Read more
Source§

impl Clone for Vector

Source§

fn clone(&self) -> Vector

Returns a duplicate 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 Vector

Source§

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

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

impl Default for Vector

Source§

fn default() -> Vector

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

impl<'de> Deserialize<'de> for Vector

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 From<Vector> for PreciseVector

Source§

fn from(v: Vector) -> Self

Converts to this type from the input type.
Source§

impl Into<Vector> for PreciseVector

Source§

fn into(self) -> Vector

Converts this type into the (usually inferred) input type.
Source§

impl<'a, 'b> Mul<&'a Vector> for &'b Vector

Source§

type Output = Vector

The resulting type after applying the * operator.
Source§

fn mul(self, other: &'a Vector) -> Self::Output

Performs the * operation. Read more
Source§

impl<'a> Mul<f64> for &'a Vector

Source§

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

mul returns the standard scalar product of v and m.

Source§

type Output = Vector

The resulting type after applying the * operator.
Source§

impl Mul<f64> for Vector

Source§

type Output = Vector

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl Mul for Vector

Source§

type Output = Vector

The resulting type after applying the * operator.
Source§

fn mul(self, other: Vector) -> Self::Output

Performs the * operation. Read more
Source§

impl Ord for Vector

Source§

fn cmp(&self, ov: &Vector) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for Vector

Source§

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

Source§

fn partial_cmp(&self, ov: &Vector) -> 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 Serialize for Vector

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<'a, 'b> Sub<&'b Vector> for &'a Vector

Source§

type Output = Vector

The resulting type after applying the - operator.
Source§

fn sub(self, other: &'b Vector) -> Self::Output

Performs the - operation. Read more
Source§

impl Sub for Vector

Source§

fn sub(self, other: Vector) -> Self::Output

sub returns the standard vector difference of v and ov.

Source§

type Output = Vector

The resulting type after applying the - operator.
Source§

impl Copy for Vector

Source§

impl Eq for Vector

Source§

impl StructuralPartialEq for Vector

Auto Trait Implementations§

§

impl Freeze for Vector

§

impl RefUnwindSafe for Vector

§

impl Send for Vector

§

impl Sync for Vector

§

impl Unpin for Vector

§

impl UnwindSafe for Vector

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