[][src]Trait gramit::fp::ApproxEq

pub trait ApproxEq<T = Self> {
    fn approx_eq(self, rhs: T) -> bool;
fn within_threshold(self, rhs: T, threshold: T) -> bool; }

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.

Loading content...

Implementations on Foreign Types

impl ApproxEq<f32> for f32[src]

Loading content...

Implementors

impl ApproxEq<Angle> for Angle[src]

impl ApproxEq<Fraction> for Fraction[src]

impl ApproxEq<Mat2> for Mat2[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 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 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 within_threshold(self, rhs: Quaternion, threshold: Quaternion) -> bool[src]

Compare two Quaternions for approximate equality.

Uses a third Quaternion for element-wise thresholds.

impl ApproxEq<Vec2> for Vec2[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 within_threshold(self, rhs: Vec3, threshold: Vec3) -> bool[src]

Compare two vectors for approximate equality.

Uses a third vector for component-wise thresholds.

impl ApproxEq<Vec4> for Vec4[src]

fn within_threshold(self, rhs: Vec4, threshold: Vec4) -> bool[src]

Compare two vectors for approximate equality.

Uses a third vector for component-wise thresholds.

Loading content...