bevy_math

Trait NormedVectorSpace

Source
pub trait NormedVectorSpace: VectorSpace {
    // Required method
    fn norm(self) -> f32;

    // Provided methods
    fn norm_squared(self) -> f32 { ... }
    fn distance(self, rhs: Self) -> f32 { ... }
    fn distance_squared(self, rhs: Self) -> f32 { ... }
}
Expand description

A type that supports the operations of a normed vector space; i.e. a norm operation in addition to those of VectorSpace. Specifically, the implementor must guarantee that the following relationships hold, within the limitations of floating point arithmetic:

  • (Nonnegativity) For all v: Self, v.norm() >= 0.0.
  • (Positive definiteness) For all v: Self, v.norm() == 0.0 implies v == Self::ZERO.
  • (Absolute homogeneity) For all c: f32, v: Self, (v * c).norm() == v.norm() * c.abs().
  • (Triangle inequality) For all v, w: Self, (v + w).norm() <= v.norm() + w.norm().

Note that, because implementing types use floating point arithmetic, they are not required to actually implement PartialEq or Eq.

Required Methods§

Source

fn norm(self) -> f32

The size of this element. The return value should always be nonnegative.

Provided Methods§

Source

fn norm_squared(self) -> f32

The squared norm of this element. Computing this is often faster than computing NormedVectorSpace::norm.

Source

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

The distance between this element and another, as determined by the norm.

Source

fn distance_squared(self, rhs: Self) -> f32

The squared distance between this element and another, as determined by the norm. Note that this is often faster to compute in practice than NormedVectorSpace::distance.

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.

Implementations on Foreign Types§

Source§

impl NormedVectorSpace for f32

Source§

fn norm(self) -> f32

Source§

fn norm_squared(self) -> f32

Implementors§