Struct glam::f64::DVec2[][src]

#[repr(transparent)]pub struct DVec2(_);

A 2-dimensional vector.

Implementations

impl DVec2[src]

pub const ZERO: Self[src]

All zeroes.

pub const ONE: Self[src]

All ones.

pub const X: Self[src]

[1, 0]: a unit-length vector pointing along the positive X axis.

pub const Y: Self[src]

[0, 1]: a unit-length vector pointing along the positive Y axis.

pub const AXES: [Self; 2][src]

The unit axes.

pub fn new(x: f64, y: f64) -> DVec2[src]

Creates a new vector.

pub const fn unit_x() -> DVec2[src]

👎 Deprecated:

Use Vec2::X instead

Creates a vector with values [x: 1.0, y: 0.0].

pub const fn unit_y() -> DVec2[src]

👎 Deprecated:

Use Vec2::Y instead

Creates a vector with values [x: 0.0, y: 1.0].

pub fn extend(self, z: f64) -> DVec3[src]

Creates a 3D vector from self and the given z value.

pub const fn zero() -> Self[src]

👎 Deprecated:

use ZERO constant instead

Creates a vector with all elements set to 0.0.

pub const fn one() -> Self[src]

👎 Deprecated:

use ONE constant instead

Creates a vector with all elements set to 1.0.

pub fn splat(v: f64) -> Self[src]

Creates a vector with all elements set to v.

pub fn select(mask: BVec2, if_true: DVec2, if_false: DVec2) -> DVec2[src]

Creates a vector from the elements in if_true and if_false, selecting which to use for each element of self.

A true element in the mask uses the corresponding element from if_true, and false uses the element from if_false.

pub fn dot(self, other: Self) -> f64[src]

Computes the dot product of self and other.

pub fn min(self, other: Self) -> Self[src]

Returns a vector containing the mininum values for each element of self and other.

In other words this computes [self.x.max(other.x), self.y.max(other.y), ..].

pub fn max(self, other: Self) -> Self[src]

Returns a vector containing the maximum values for each element of self and other.

In other words this computes [self.x.max(other.x), self.y.max(other.y), ..].

pub fn clamp(self, min: Self, max: Self) -> Self[src]

Component-wise clamping of values, similar to [std::f32::clamp].

Each element in min must be less-or-equal to the corresponing element in max.

If the glam-assert feature is enabled, the function will panic if the contract is not met, otherwise the behavior is undefined.

pub fn min_element(self) -> f64[src]

Returns the horizontal minimum of self.

In other words this computes min(x, y, ..).

pub fn max_element(self) -> f64[src]

Returns the horizontal maximum of self.

In other words this computes max(x, y, ..).

pub fn cmpeq(self, other: Self) -> BVec2[src]

Returns a vector mask containing the result of a == comparison for each element of self and other.

In other words, this computes [self.x == other.x, self.y == other.y, ..] for all elements.

pub fn cmpne(self, other: Self) -> BVec2[src]

Returns a vector mask containing the result of a != comparison for each element of self and other.

In other words this computes [self.x != other.x, self.y != other.y, ..] for all elements.

pub fn cmpge(self, other: Self) -> BVec2[src]

Returns a vector mask containing the result of a >= comparison for each element of self and other.

In other words this computes [self.x >= other.x, self.y >= other.y, ..] for all elements.

pub fn cmpgt(self, other: Self) -> BVec2[src]

Returns a vector mask containing the result of a > comparison for each element of self and other.

In other words this computes [self.x > other.x, self.y > other.y, ..] for all elements.

pub fn cmple(self, other: Self) -> BVec2[src]

Returns a vector mask containing the result of a <= comparison for each element of self and other.

In other words this computes [self.x <= other.x, self.y <= other.y, ..] for all elements.

pub fn cmplt(self, other: Self) -> BVec2[src]

Returns a vector mask containing the result of a < comparison for each element of self and other.

In other words this computes [self.x < other.x, self.y < other.y, ..] for all elements.

pub fn from_slice_unaligned(slice: &[f64]) -> Self[src]

Creates a vector from the first N values in slice.

Panics

Panics if slice is less than N elements long.

pub fn write_to_slice_unaligned(self, slice: &mut [f64])[src]

Writes the elements of self to the first N elements in slice.

Panics

Panics if slice is less than N elements long.

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

Returns a vector containing the absolute value of each element of self.

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

Returns a vector with elements representing the sign of self.

  • 1.0 if the number is positive, +0.0 or INFINITY
  • -1.0 if the number is negative, -0.0 or NEG_INFINITY
  • NAN if the number is NAN

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

Returns a vector that is equal to self rotated by 90 degrees.

pub fn perp_dot(self, other: DVec2) -> f64[src]

The perpendicular dot product of self and other.

pub fn is_finite(self) -> bool[src]

Returns true if, and only if, all elements are finite. If any element is either NaN, positive or negative infinity, this will return false.

pub fn is_nan(self) -> bool[src]

Returns true if any elements are NaN.

pub fn is_nan_mask(self) -> BVec2[src]

Performs is_nan on each element of self, returning a vector mask of the results.

In other words, this computes [x.is_nan(), y.is_nan(), z.is_nan(), w.is_nan()].

pub fn length(self) -> f64[src]

Computes the length of self.

pub fn length_squared(self) -> f64[src]

Computes the squared length of self.

This is faster than length() as it avoids a square root operation.

pub fn length_recip(self) -> f64[src]

Computes 1.0 / length().

For valid results, self must not be of length zero.

pub fn distance(self, other: Self) -> f64[src]

Computes the Euclidean distance between two points in space.

pub fn distance_squared(self, other: Self) -> f64[src]

Compute the squared euclidean distance between two points in space.

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

Returns self normalized to length 1.0.

For valid results, self must not be of length zero, nor very close to zero.

See also Self::try_normalize and Self::normalize_or_zero.

pub fn try_normalize(self) -> Option<Self>[src]

Returns self normalized to length 1.0 if possible, else returns None.

In particular, if the input is zero (or very close to zero), or non-finite, the result of this operation will be None.

See also Self::normalize_or_zero.

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

Returns self normalized to length 1.0 if possible, else returns zero.

In particular, if the input is zero (or very close to zero), or non-finite, the result of this operation will be zero.

See also Self::try_normalize.

pub fn is_normalized(self) -> bool[src]

Returns whether self is length 1.0 or not.

Uses a precision threshold of 1e-6.

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

Returns a vector containing the nearest integer to a number for each element of self. Round half-way cases away from 0.0.

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

Returns a vector containing the largest integer less than or equal to a number for each element of self.

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

Returns a vector containing the smallest integer greater than or equal to a number for each element of self.

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

Returns a vector containing e^self (the exponential function) for each element of self.

pub fn powf(self, n: f64) -> Self[src]

Returns a vector containing each element of self raised to the power of n.

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

Returns a vector containing the reciprocal 1.0/n of each element of self.

pub fn lerp(self, other: Self, s: f64) -> Self[src]

Performs a linear interpolation between self and other based on the value s.

When s is 0.0, the result will be equal to self. When s is 1.0, the result will be equal to other.

pub fn abs_diff_eq(self, other: Self, max_abs_diff: f64) -> bool[src]

Returns true if the absolute difference of all elements between self and other is less than or equal to max_abs_diff.

This can be used to compare if two vectors contain similar elements. It works best when comparing with a known value. The max_abs_diff that should be used used depends on the values being compared against.

For more see comparing floating point numbers.

pub fn clamp_length(self, min: f64, max: f64) -> Self[src]

Returns a vector with a length no less than min and no more than max

pub fn clamp_length_max(self, max: f64) -> Self[src]

Returns a vector with a length no more than max

pub fn clamp_length_min(self, min: f64) -> Self[src]

Returns a vector with a length no less than min

pub fn angle_between(self, other: Self) -> f64[src]

Returns the angle (in radians) between self and other.

The input vectors do not need to be unit length however they must be non-zero.

pub fn as_f32(&self) -> Vec2[src]

Casts all elements of self to f32.

pub fn as_i32(&self) -> IVec2[src]

Casts all elements of self to i32.

pub fn as_u32(&self) -> UVec2[src]

Casts all elements of self to u32.

Trait Implementations

impl Add<DVec2> for DVec2[src]

type Output = Self

The resulting type after applying the + operator.

impl AddAssign<DVec2> for DVec2[src]

impl AsMut<[f64; 2]> for DVec2[src]

impl AsRef<[f64; 2]> for DVec2[src]

impl Clone for DVec2[src]

impl Copy for DVec2[src]

impl Debug for DVec2[src]

impl Default for DVec2[src]

impl Deref for DVec2[src]

type Target = XY<f64>

The resulting type after dereferencing.

impl DerefMut for DVec2[src]

impl Display for DVec2[src]

impl Div<DVec2> for DVec2[src]

type Output = Self

The resulting type after applying the / operator.

impl Div<f64> for DVec2[src]

type Output = Self

The resulting type after applying the / operator.

impl DivAssign<DVec2> for DVec2[src]

impl DivAssign<f64> for DVec2[src]

impl From<[f64; 2]> for DVec2[src]

impl From<(f64, f64)> for DVec2[src]

impl From<DVec3> for DVec2[src]

fn from(v: DVec3) -> Self[src]

Creates a Vec2 from the x and y elements of self, discarding z.

impl From<DVec4> for DVec2[src]

fn from(v: DVec4) -> Self[src]

Creates a 2D vector from the x and y elements of self, discarding z and w.

impl Index<usize> for DVec2[src]

type Output = f64

The returned type after indexing.

impl IndexMut<usize> for DVec2[src]

impl Mul<DVec2> for DMat2[src]

type Output = DVec2

The resulting type after applying the * operator.

impl Mul<DVec2> for DVec2[src]

type Output = Self

The resulting type after applying the * operator.

impl Mul<f64> for DVec2[src]

type Output = Self

The resulting type after applying the * operator.

impl MulAssign<DVec2> for DVec2[src]

impl MulAssign<f64> for DVec2[src]

impl Neg for DVec2[src]

type Output = Self

The resulting type after applying the - operator.

impl PartialEq<DVec2> for DVec2[src]

impl PartialOrd<DVec2> for DVec2[src]

impl<'a> Product<&'a DVec2> for DVec2[src]

impl Sub<DVec2> for DVec2[src]

type Output = Self

The resulting type after applying the - operator.

impl SubAssign<DVec2> for DVec2[src]

impl<'a> Sum<&'a DVec2> for DVec2[src]

impl Vec2Swizzles for DVec2[src]

type Vec3 = DVec3

type Vec4 = DVec4

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

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