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
impliesv == 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§
Provided Methods§
sourcefn norm_squared(self) -> f32
fn norm_squared(self) -> f32
The squared norm of this element. Computing this is often faster than computing
NormedVectorSpace::norm
.
sourcefn distance(self, rhs: Self) -> f32
fn distance(self, rhs: Self) -> f32
The distance between this element and another, as determined by the norm.
sourcefn distance_squared(self, rhs: Self) -> f32
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.