Merge pull request #199 from phaazon/unused-arg

Unused arg in ApproxEq removed
This commit is contained in:
Sébastien Crozet 2016-08-29 21:11:55 +02:00 committed by GitHub
commit 96d7f68f14
11 changed files with 61 additions and 64 deletions

View File

@ -27,17 +27,3 @@ macro_rules! assert_approx_eq_ulps(
}
})
);
/// Asserts approximate equality of two values with the `ApproxEq` trait.
#[macro_export]
macro_rules! assert_approx_eq(
($given: expr, $expected: expr) => ({
let (given_val, expected_val) = (&($given), &($expected));
if !ApproxEq::approx_eq(given_val, expected_val) {
panic!("assertion failed: `left ≈ right` (left: `{:?}`, right: `{:?}`, tolerance: `{:?}`)",
*given_val, *expected_val,
ApproxEq::approx_epsilon(Some(*given_val))
)
}
})
);

View File

@ -873,13 +873,13 @@ macro_rules! dmat_impl(
impl<N: ApproxEq<N>> ApproxEq<N> for $dmatrix<N> {
#[inline]
fn approx_epsilon(_: Option<$dmatrix<N>>) -> N {
ApproxEq::approx_epsilon(None::<N>)
fn approx_epsilon() -> N {
<N as ApproxEq<N>>::approx_epsilon()
}
#[inline]
fn approx_ulps(_: Option<$dmatrix<N>>) -> u32 {
ApproxEq::approx_ulps(None::<N>)
fn approx_ulps() -> u32 {
<N as ApproxEq<N>>::approx_ulps()
}
#[inline]

View File

@ -378,13 +378,13 @@ macro_rules! isometry_impl(
*/
impl<N: ApproxEq<N>> ApproxEq<N> for $t<N> {
#[inline]
fn approx_epsilon(_: Option<$t<N>>) -> N {
ApproxEq::approx_epsilon(None::<N>)
fn approx_epsilon() -> N {
<N as ApproxEq<N>>::approx_epsilon()
}
#[inline]
fn approx_ulps(_: Option<$t<N>>) -> u32 {
ApproxEq::approx_ulps(None::<N>)
fn approx_ulps() -> u32 {
<N as ApproxEq<N>>::approx_ulps()
}
#[inline]

View File

@ -277,13 +277,13 @@ macro_rules! matrix_impl(
*/
impl<N: ApproxEq<N>> ApproxEq<N> for $t<N> {
#[inline]
fn approx_epsilon(_: Option<$t<N>>) -> N {
ApproxEq::approx_epsilon(None::<N>)
fn approx_epsilon() -> N {
<N as ApproxEq<N>>::approx_epsilon()
}
#[inline]
fn approx_ulps(_: Option<$t<N>>) -> u32 {
ApproxEq::approx_ulps(None::<N>)
fn approx_ulps() -> u32 {
<N as ApproxEq<N>>::approx_ulps()
}
#[inline]

View File

@ -389,13 +389,13 @@ impl<N: Rand + BaseFloat> Rand for UnitQuaternion<N> {
impl<N: ApproxEq<N>> ApproxEq<N> for UnitQuaternion<N> {
#[inline]
fn approx_epsilon(_: Option<UnitQuaternion<N>>) -> N {
ApproxEq::approx_epsilon(None::<N>)
fn approx_epsilon() -> N {
<N as ApproxEq<N>>::approx_epsilon()
}
#[inline]
fn approx_ulps(_: Option<UnitQuaternion<N>>) -> u32 {
ApproxEq::approx_ulps(None::<N>)
fn approx_ulps() -> u32 {
<N as ApproxEq<N>>::approx_ulps()
}
#[inline]

View File

@ -341,13 +341,13 @@ macro_rules! rotation_impl(
*/
impl<N: ApproxEq<N>> ApproxEq<N> for $t<N> {
#[inline]
fn approx_epsilon(_: Option<$t<N>>) -> N {
ApproxEq::approx_epsilon(None::<N>)
fn approx_epsilon() -> N {
<N as ApproxEq<N>>::approx_epsilon()
}
#[inline]
fn approx_ulps(_: Option<$t<N>>) -> u32 {
ApproxEq::approx_ulps(None::<N>)
fn approx_ulps() -> u32 {
<N as ApproxEq<N>>::approx_ulps()
}
#[inline]

View File

@ -353,13 +353,13 @@ macro_rules! similarity_impl(
*/
impl<N: ApproxEq<N>> ApproxEq<N> for $t<N> {
#[inline]
fn approx_epsilon(_: Option<$t<N>>) -> N {
ApproxEq::approx_epsilon(None::<N>)
fn approx_epsilon() -> N {
<N as ApproxEq<N>>::approx_epsilon()
}
#[inline]
fn approx_ulps(_: Option<$t<N>>) -> u32 {
ApproxEq::approx_ulps(None::<N>)
fn approx_ulps() -> u32 {
<N as ApproxEq<N>>::approx_ulps()
}
#[inline]

View File

@ -34,13 +34,13 @@ macro_rules! vectorlike_impl(
*/
impl<N: ApproxEq<N>> ApproxEq<N> for $t<N> {
#[inline]
fn approx_epsilon(_: Option<$t<N>>) -> N {
ApproxEq::approx_epsilon(None::<N>)
fn approx_epsilon() -> N {
<N as ApproxEq<N>>::approx_epsilon()
}
#[inline]
fn approx_ulps(_: Option<$t<N>>) -> u32 {
ApproxEq::approx_ulps(None::<N>)
fn approx_ulps() -> u32 {
<N as ApproxEq<N>>::approx_ulps()
}
#[inline]

View File

@ -582,13 +582,13 @@ macro_rules! vecn_dvec_common_impl(
*/
impl<N: ApproxEq<N> $(, $param : ArrayLength<N>)*> ApproxEq<N> for $vecn<N $(, $param)*> {
#[inline]
fn approx_epsilon(_: Option<$vecn<N $(, $param)*>>) -> N {
ApproxEq::approx_epsilon(None::<N>)
fn approx_epsilon() -> N {
<N as ApproxEq<N>>::approx_epsilon()
}
#[inline]
fn approx_ulps(_: Option<$vecn<N $(, $param)*>>) -> u32 {
ApproxEq::approx_ulps(None::<N>)
fn approx_ulps() -> u32 {
<N as ApproxEq<N>>::approx_ulps()
}
#[inline]

View File

@ -152,13 +152,13 @@ pub trait PartialOrder {
/// Trait for testing approximate equality
pub trait ApproxEq<Eps>: Sized {
/// Default epsilon for approximation.
fn approx_epsilon(unused_mut: Option<Self>) -> Eps;
fn approx_epsilon() -> Eps;
/// Tests approximate equality using a custom epsilon.
fn approx_eq_eps(&self, other: &Self, epsilon: &Eps) -> bool;
/// Default ULPs for approximation.
fn approx_ulps(unused_mut: Option<Self>) -> u32;
fn approx_ulps() -> u32;
/// Tests approximate equality using units in the last place (ULPs)
fn approx_eq_ulps(&self, other: &Self, ulps: u32) -> bool;
@ -166,13 +166,13 @@ pub trait ApproxEq<Eps>: Sized {
/// Tests approximate equality.
#[inline]
fn approx_eq(&self, other: &Self) -> bool {
self.approx_eq_eps(other, &ApproxEq::approx_epsilon(None::<Self>))
self.approx_eq_eps(other, &Self::approx_epsilon())
}
}
impl ApproxEq<f32> for f32 {
#[inline]
fn approx_epsilon(_: Option<f32>) -> f32 {
fn approx_epsilon() -> f32 {
1.0e-6
}
@ -181,7 +181,7 @@ impl ApproxEq<f32> for f32 {
::abs(&(*self - *other)) < *epsilon
}
fn approx_ulps(_: Option<f32>) -> u32 {
fn approx_ulps() -> u32 {
8
}
@ -203,7 +203,7 @@ impl ApproxEq<f32> for f32 {
impl ApproxEq<f64> for f64 {
#[inline]
fn approx_epsilon(_: Option<f64>) -> f64 {
fn approx_epsilon() -> f64 {
1.0e-6
}
@ -212,7 +212,7 @@ impl ApproxEq<f64> for f64 {
::abs(&(*self - *other)) < *approx_epsilon
}
fn approx_ulps(_: Option<f64>) -> u32 {
fn approx_ulps() -> u32 {
8
}
@ -231,16 +231,16 @@ impl ApproxEq<f64> for f64 {
}
impl<'a, N, T: ApproxEq<N>> ApproxEq<N> for &'a T {
fn approx_epsilon(_: Option<&'a T>) -> N {
ApproxEq::approx_epsilon(None::<T>)
fn approx_epsilon() -> N {
<T as ApproxEq<N>>::approx_epsilon()
}
fn approx_eq_eps(&self, other: &&'a T, approx_epsilon: &N) -> bool {
ApproxEq::approx_eq_eps(*self, *other, approx_epsilon)
}
fn approx_ulps(_: Option<&'a T>) -> u32 {
ApproxEq::approx_ulps(None::<T>)
fn approx_ulps() -> u32 {
<T as ApproxEq<N>>::approx_ulps()
}
fn approx_eq_ulps(&self, other: &&'a T, ulps: u32) -> bool {
@ -249,16 +249,16 @@ impl<'a, N, T: ApproxEq<N>> ApproxEq<N> for &'a T {
}
impl<'a, N, T: ApproxEq<N>> ApproxEq<N> for &'a mut T {
fn approx_epsilon(_: Option<&'a mut T>) -> N {
ApproxEq::approx_epsilon(None::<T>)
fn approx_epsilon() -> N {
<T as ApproxEq<N>>::approx_epsilon()
}
fn approx_eq_eps(&self, other: &&'a mut T, approx_epsilon: &N) -> bool {
ApproxEq::approx_eq_eps(*self, *other, approx_epsilon)
}
fn approx_ulps(_: Option<&'a mut T>) -> u32 {
ApproxEq::approx_ulps(None::<T>)
fn approx_ulps() -> u32 {
<T as ApproxEq<N>>::approx_ulps()
}
fn approx_eq_ulps(&self, other: &&'a mut T, ulps: u32) -> bool {

View File

@ -4,13 +4,24 @@
extern crate nalgebra;
use nalgebra::{ApproxEq, Vector2};
use std::fmt::Debug;
// Replace the assert_approx_eq! macro so that we can have type inference.
fn test_approx_eq<T, N>(given: &T, expected: &T) where T: Debug + ApproxEq<N>, N: Debug {
if !given.approx_eq(expected) {
panic!("assertion failed: `left ≈ right` (left: `{:?}`, right: `{:?}`, tolerance: `{:?}`)",
*given, *expected,
T::approx_epsilon()
)
}
}
#[test]
fn assert_approx_eq_f64() {
let a = 1.0f64;
let b = 1.0f64 + 1.0e-12f64;
assert_approx_eq!(a, b);
assert_approx_eq!(&a, &b);
test_approx_eq(&a, &b);
test_approx_eq(&(&a), &(&b));
}
#[test]
@ -18,7 +29,7 @@ fn assert_approx_eq_f64() {
fn assert_approx_eq_vec2_f32_fail() {
let a = Vector2::new(1.0f32, 0.0);
let b = Vector2::new(1.1f32, 0.1);
assert_approx_eq!(a, b);
test_approx_eq(&a, &b);
}
#[test]