Struct cgmath::Relative

source ·
pub struct Relative<'a, T>where
    T: 'a + ApproxEq,{
    pub lhs: &'a T,
    pub rhs: &'a T,
    pub epsilon: <T as ApproxEq>::Epsilon,
    pub max_relative: <T as ApproxEq>::Epsilon,
}
Expand description

The requisite parameters for testing for approximate equality.

Fields§

§lhs: &'a T

The left-hand side of the approximate equality comparison.

§rhs: &'a T

The right-hand side of the approximate equality comparison.

§epsilon: <T as ApproxEq>::Epsilon

The tolerance to use when testing values that are close together.

§max_relative: <T as ApproxEq>::Epsilon

The relative tolerance for testing values that are far-apart.

Implementations§

source§

impl<'a, T> Relative<'a, T>where T: ApproxEq,

source

pub fn new(lhs: &'a T, rhs: &'a T) -> Relative<'a, T>

The beginning of a chained equality expression, using a relative based comparison.

use std::f64;
use approx::Relative;

Relative::new(&1.0, &1.0).eq();
Relative::new(&1.0, &1.0).epsilon(f64::EPSILON).eq();
Relative::new(&1.0, &1.0).max_relative(1.0).eq();
Relative::new(&1.0, &1.0).epsilon(f64::EPSILON).max_relative(1.0).eq();
Relative::new(&1.0, &1.0).max_relative(1.0).epsilon(f64::EPSILON).eq();
source

pub fn epsilon(self, epsilon: <T as ApproxEq>::Epsilon) -> Relative<'a, T>

Replace the epsilon value with the one specified.

source

pub fn max_relative( self, max_relative: <T as ApproxEq>::Epsilon ) -> Relative<'a, T>

Replace the maximum relative value with the one specified.

source

pub fn eq(self) -> bool

Peform the equality comparison

source

pub fn ne(self) -> bool

Peform the inequality comparison

Auto Trait Implementations§

§

impl<'a, T> RefUnwindSafe for Relative<'a, T>where T: RefUnwindSafe, <T as ApproxEq>::Epsilon: RefUnwindSafe,

§

impl<'a, T> Send for Relative<'a, T>where T: Sync, <T as ApproxEq>::Epsilon: Send,

§

impl<'a, T> Sync for Relative<'a, T>where T: Sync, <T as ApproxEq>::Epsilon: Sync,

§

impl<'a, T> Unpin for Relative<'a, T>where <T as ApproxEq>::Epsilon: Unpin,

§

impl<'a, T> UnwindSafe for Relative<'a, T>where T: RefUnwindSafe, <T as ApproxEq>::Epsilon: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.