PointOpsExt

Trait PointOpsExt 

Source
pub trait PointOpsExt<F: Float>: PointLike<F> {
Show 23 methods // Provided methods fn splat(value: F) -> Self { ... } fn add_f(self, scalar: F) -> Self { ... } fn sub_f(self, scalar: F) -> Self { ... } fn mul_f(self, scalar: F) -> Self { ... } fn mul_add(self, a: Self, b: Self) -> Self { ... } fn abs(self) -> Self { ... } fn approx_eq(self, rhs: Self, epsilon: F) -> bool { ... } fn approx_eq_f(self, scalar: F, epsilon: F) -> bool { ... } fn round(self, n: usize) -> Self { ... } fn max(self, other: Self) -> Self { ... } fn min(self, other: Self) -> Self { ... } fn cross(self, rhs: Self) -> F { ... } fn dot(self, rhs: Self) -> F { ... } fn length(self) -> F { ... } fn length_squared(self) -> F { ... } fn distance(self, rhs: Self) -> F { ... } fn partial_cmp(&self, other: &F) -> Option<Ordering> { ... } fn lt(&self, other: &F) -> bool { ... } fn gt(self, other: &F) -> bool { ... } fn le(self, other: &F) -> bool { ... } fn ge(self, other: &F) -> bool { ... } fn eq(self, other: &F) -> bool { ... } fn ne(self, other: &F) -> bool { ... }
}

Provided Methods§

Source

fn splat(value: F) -> Self

Construct a new point using the same value for both components of self.

Source

fn add_f(self, scalar: F) -> Self

Add a scalar to both components of a point.

Source

fn sub_f(self, scalar: F) -> Self

Subtract a scalar from both components of a point.

Source

fn mul_f(self, scalar: F) -> Self

Multiply a point by a scalar.

Source

fn mul_add(self, a: Self, b: Self) -> Self

Fused multiply-add. Computes (self * a) + b with only one rounding error, yielding a more accurate result than an unfused multiply-add.

Using mul_add can be more performant than an unfused multiply-add if the target architecture has a dedicated fma CPU instruction.

Source

fn abs(self) -> Self

Construct a point from the absolute components of self.

Source

fn approx_eq(self, rhs: Self, epsilon: F) -> bool

Compare all components in self with rhs for approximate equality.

Source

fn approx_eq_f(self, scalar: F, epsilon: F) -> bool

Compare all components in a point with a scalar for approximate equality.

Source

fn round(self, n: usize) -> Self

Round the components of a point to N decimal places.

Source

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

Returns a point-like containing the maximum values for each element of self and rhs.

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

Source

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

Returns a point-like containing the minimum values for each element of self and rhs.

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

Source

fn cross(self, rhs: Self) -> F

Compute the cross product of two points.

Source

fn dot(self, rhs: Self) -> F

Computes the dot of self and rhs.

a · b = (x₁ · x₂) + (y₁ · y₂)
Source

fn length(self) -> F

Computes the length of self.

c = √(a² + b²)
Source

fn length_squared(self) -> F

Computes the squared length of self. This is generally faster than length as it avoids the square root.

Source

fn distance(self, rhs: Self) -> F

Computes the Euclidean distance between two points in space.

This works by relocating one point to the origin, then computing the length of the resulting vector.

c = √((x₂ - x₁)² + (y₂ - y₁)²)
Source

fn partial_cmp(&self, other: &F) -> Option<Ordering>

Source

fn lt(&self, other: &F) -> bool

Source

fn gt(self, other: &F) -> bool

Source

fn le(self, other: &F) -> bool

Source

fn ge(self, other: &F) -> bool

Source

fn eq(self, other: &F) -> bool

Source

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

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<F: Float, P: PointLike<F>> PointOpsExt<F> for P