[−][src]Trait gramit::fp::ApproxEq
Trait for types that can be compared for approximate equality.
Round-off error is a pervasive problem for floating-point arithemtic. Limited precision means
that many expressions that are mathematically equal evaluate as unqual when computed using
floating-point. A simple workaround is to, instead of comparing for exact equality, test
whether values are within some small absolute difference of each other. The ApproxEq
trait is
intended to make this pattern a little more ergonomic by supplying a default difference
threshold and encapsulating the comparison in a single method.
gramit
implements ApproxEq
for f32
and all of the gramit
mathematical objects (vectors,
matrices, etc). All of these implementations use the default threshold EQ_THRESHOLD_F32
.
There are also assertion macros assert_approx_eq
and assert_within_threshold
corresponding to ApproxEq
's trait methods.
Required methods
fn approx_eq(self, rhs: T) -> bool
Compare two values for approximate equality, using a default difference treshold.
fn within_threshold(self, rhs: T, threshold: T) -> bool
Compare two values for approximate equality, using a user-defined difference threshold.
Implementations on Foreign Types
impl ApproxEq<f32> for f32
[src]
fn approx_eq(self, rhs: f32) -> bool
[src]
fn within_threshold(self, rhs: f32, threshold: f32) -> bool
[src]
Implementors
impl ApproxEq<Angle> for Angle
[src]
fn approx_eq(self, rhs: Angle) -> bool
[src]
fn within_threshold(self, rhs: Angle, threshold: Angle) -> bool
[src]
impl ApproxEq<Fraction> for Fraction
[src]
fn approx_eq(self, rhs: Self) -> bool
[src]
fn within_threshold(self, rhs: Self, threshold: Self) -> bool
[src]
impl ApproxEq<Mat2> for Mat2
[src]
fn approx_eq(self, rhs: Mat2) -> bool
[src]
fn within_threshold(self, rhs: Mat2, threshold: Mat2) -> bool
[src]
Compare two matrices for approximate equality, using a third matrix for component-wise thresholds.
impl ApproxEq<Mat3> for Mat3
[src]
fn approx_eq(self, rhs: Mat3) -> bool
[src]
fn within_threshold(self, rhs: Mat3, threshold: Mat3) -> bool
[src]
Compare two matrices for approximate equality, using a third matrix for component-wise thresholds.
impl ApproxEq<Mat4> for Mat4
[src]
fn approx_eq(self, rhs: Mat4) -> bool
[src]
fn within_threshold(self, rhs: Mat4, threshold: Mat4) -> bool
[src]
Compare two matrices for approximate equality, using a third matrix for component-wise thresholds.
impl ApproxEq<Quaternion> for Quaternion
[src]
fn approx_eq(self, rhs: Quaternion) -> bool
[src]
fn within_threshold(self, rhs: Quaternion, threshold: Quaternion) -> bool
[src]
Compare two Quaternion
s for approximate equality.
Uses a third Quaternion
for element-wise thresholds.
impl ApproxEq<Vec2> for Vec2
[src]
fn approx_eq(self, rhs: Vec2) -> bool
[src]
fn within_threshold(self, rhs: Vec2, threshold: Vec2) -> bool
[src]
Compare two vectors for approximate equality.
Uses a third vector for component-wise thresholds.
impl ApproxEq<Vec3> for Vec3
[src]
fn approx_eq(self, rhs: Vec3) -> bool
[src]
fn within_threshold(self, rhs: Vec3, threshold: Vec3) -> bool
[src]
Compare two vectors for approximate equality.
Uses a third vector for component-wise thresholds.