Trait bevy_math::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.

Object Safety§

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§