Struct mafs::Dvec2

source ·
#[repr(C)]
pub struct Dvec2 { /* private fields */ }
Expand description

2D vector with double precision

The components are laid out in this order: [x, y]. This struct is aligned to 16 bytes.

Examples

use mafs::{Vec2, Dvec2};

// Construction
let a = Dvec2::new(2.0, 3.0);
let b = Dvec2::new(6.0, 9.0);
let c = Dvec2::splat(0.0); // Set all four components to the same value

// Arithmetics
assert_eq!(a + b, Dvec2::new(8.0, 12.0));
assert_eq!(a - b, Dvec2::new(-4.0, -6.0));
assert_eq!(a * b, Dvec2::new(12.0, 27.0));
assert_eq!(b / a, Dvec2::new(3.0, 3.0));

// Euclidian norm
assert_eq!(a.norm(), 13.0f64.sqrt());
assert_eq!(a.normalize().norm(), 1.0);

// Specialized operations
assert_eq!(a.dot(b), 39.0);
assert_eq!(b.dot(a), a.dot(b));
assert_eq!(Dvec2::new(-0.5, 0.5).floor(), Dvec2::new(-1.0, 0.0));

// Comparisons
assert_eq!(a.min_componentwise(b), Dvec2::new(2.0, 3.0));
assert_eq!(a.max_componentwise(b), Dvec2::new(6.0, 9.0));

// Reduction
assert_eq!(a.min_reduce(), 2.0);
assert_eq!(b.max_reduce(), 9.0);

Trait Implementations§

source§

impl Add<Dvec2> for Dvec2

§

type Output = Dvec2

The resulting type after applying the + operator.
source§

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

Performs the + operation. Read more
source§

impl Add<Dvec2> for f64

§

type Output = Dvec2

The resulting type after applying the + operator.
source§

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

Performs the + operation. Read more
source§

impl Add<f64> for Dvec2

§

type Output = Dvec2

The resulting type after applying the + operator.
source§

fn add(self, rhs: f64) -> Dvec2

Performs the + operation. Read more
source§

impl AddAssign<Dvec2> for Dvec2

source§

fn add_assign(&mut self, rhs: Dvec2)

Performs the += operation. Read more
source§

impl AddAssign<f64> for Dvec2

source§

fn add_assign(&mut self, rhs: f64)

Performs the += operation. Read more
source§

impl Clone for Dvec2

source§

fn clone(&self) -> Dvec2

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 Dvec2

source§

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

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

impl Default for Dvec2

source§

fn default() -> Dvec2

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

impl Div<Dvec2> for Dvec2

§

type Output = Dvec2

The resulting type after applying the / operator.
source§

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

Performs the / operation. Read more
source§

impl Div<Dvec2> for f64

§

type Output = Dvec2

The resulting type after applying the / operator.
source§

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

Performs the / operation. Read more
source§

impl Div<f64> for Dvec2

§

type Output = Dvec2

The resulting type after applying the / operator.
source§

fn div(self, rhs: f64) -> Dvec2

Performs the / operation. Read more
source§

impl DivAssign<Dvec2> for Dvec2

source§

fn div_assign(&mut self, rhs: Dvec2)

Performs the /= operation. Read more
source§

impl DivAssign<f64> for Dvec2

source§

fn div_assign(&mut self, rhs: f64)

Performs the /= operation. Read more
source§

impl Index<usize> for Dvec2

§

type Output = f64

The returned type after indexing.
source§

fn index(&self, idx: usize) -> &f64

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

impl IndexMut<usize> for Dvec2

source§

fn index_mut(&mut self, idx: usize) -> &mut f64

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

impl Mul<Dvec2> for Dvec2

§

type Output = Dvec2

The resulting type after applying the * operator.
source§

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

Performs the * operation. Read more
source§

impl Mul<Dvec2> for f64

§

type Output = Dvec2

The resulting type after applying the * operator.
source§

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

Performs the * operation. Read more
source§

impl Mul<f64> for Dvec2

§

type Output = Dvec2

The resulting type after applying the * operator.
source§

fn mul(self, rhs: f64) -> Dvec2

Performs the * operation. Read more
source§

impl MulAssign<Dvec2> for Dvec2

source§

fn mul_assign(&mut self, rhs: Dvec2)

Performs the *= operation. Read more
source§

impl MulAssign<f64> for Dvec2

source§

fn mul_assign(&mut self, rhs: f64)

Performs the *= operation. Read more
source§

impl Neg for Dvec2

§

type Output = Dvec2

The resulting type after applying the - operator.
source§

fn neg(self) -> Dvec2

Performs the unary - operation. Read more
source§

impl PartialEq<Dvec2> for Dvec2

source§

fn eq(&self, rhs: &Dvec2) -> 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<Dvec2> for Dvec2

§

type Output = Dvec2

The resulting type after applying the - operator.
source§

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

Performs the - operation. Read more
source§

impl Sub<Dvec2> for f64

§

type Output = Dvec2

The resulting type after applying the - operator.
source§

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

Performs the - operation. Read more
source§

impl Sub<f64> for Dvec2

§

type Output = Dvec2

The resulting type after applying the - operator.
source§

fn sub(self, rhs: f64) -> Dvec2

Performs the - operation. Read more
source§

impl SubAssign<Dvec2> for Dvec2

source§

fn sub_assign(&mut self, rhs: Dvec2)

Performs the -= operation. Read more
source§

impl SubAssign<f64> for Dvec2

source§

fn sub_assign(&mut self, rhs: f64)

Performs the -= operation. Read more
source§

impl Vec2<f64> for Dvec2

source§

fn new(x: f64, y: f64) -> Dvec2

Create a new two-dimensional vector.
source§

fn as_array(&self) -> &[f64; 2]

Convert to an array. Can also use the indexing operator [].
source§

fn as_mut_array(&mut self) -> &mut [f64; 2]

Convert to a mutable array. Can also use the indexing operator[].
source§

fn add_componentwise(&self, rhs: Dvec2) -> Dvec2

Add component by component. Can also use the + operator.
source§

fn sub_componentwise(&self, rhs: Dvec2) -> Dvec2

Subtract component by component. Can also use the - operator.
source§

fn mul_componentwise(&self, rhs: Dvec2) -> Dvec2

Multiply component by component. Can also use the * operator.
source§

fn div_componentwise(&self, rhs: Dvec2) -> Dvec2

Divide component by component. Can also use the / operator.
source§

fn min_componentwise(&self, rhs: Dvec2) -> Dvec2

For each lane, select the smallest component of the two.
source§

fn max_componentwise(&self, rhs: Dvec2) -> Dvec2

For each lane, select the largest component of the two.
source§

fn floor(&self) -> Dvec2

Round down all components to an integer value.
source§

fn min_reduce(&self) -> f64

Smallest of the four components.
source§

fn max_reduce(&self) -> f64

Largest of the four components.
source§

fn eq_reduce(&self, rhs: Dvec2) -> bool

Equality of a vector to another on all components.
source§

fn dot(&self, rhs: Dvec2) -> f64

Dot product.
source§

fn splat(value: S) -> Self

Create a two-dimensional vector all with equal components.
source§

fn norm(&self) -> S

Norm of this vector.
source§

fn normalize(&self) -> Self

Divide by the norm to obain a normalized vector.
source§

impl Copy for Dvec2

Auto Trait Implementations§

§

impl RefUnwindSafe for Dvec2

§

impl Send for Dvec2

§

impl Sync for Dvec2

§

impl Unpin for Dvec2

§

impl UnwindSafe for Dvec2

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere 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 Twhere 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 Twhere 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.