fw4spl
Compare.hpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2017.
3  * Distributed under the terms of the GNU Lesser General Public License (LGPL) as
4  * published by the Free Software Foundation.
5  * ****** END LICENSE BLOCK ****** */
6 
7 #ifndef __FWMATH_COMPARE_HPP__
8 #define __FWMATH_COMPARE_HPP__
9 
10 #include <cmath>
11 
12 namespace fwMath
13 {
14 
22 template < typename TYPE >
23 bool isEqual(TYPE a, TYPE b, const float epsilon = 0.00001F)
24 {
25  return fabs(a - b) < epsilon;
26 }
27 
35 template < typename CONTAINER >
36 bool isContainerEqual(CONTAINER& containerA, CONTAINER& containerB, const float epsilon = 0.00001F)
37 {
38  bool isEqual = true;
39  if(containerA.size() != containerB.size())
40  {
41  return false;
42  }
43 
44  typename CONTAINER::const_iterator iterA = containerA.begin();
45  typename CONTAINER::const_iterator iterB = containerB.begin();
46 
47  while(isEqual && iterA != containerA.end())
48  {
49  isEqual = ::fwMath::isEqual(*iterA, *iterB, epsilon);
50  ++iterA;
51  ++iterB;
52  }
53 
54  return isEqual;
55 }
56 
57 } // namespace fwMath
58 
59 #endif /* __FWMATH_COMPARE_HPP__ */
bool isContainerEqual(CONTAINER &containerA, CONTAINER &containerB, const float epsilon=0.00001F)
Returns true iff container a and b are equal with &#39;epsilon&#39; error margin.
Definition: Compare.hpp:36
The namespace fwMath contains classes which provide the implementation of several mathematic function...
Definition: Compare.hpp:12
bool isEqual(TYPE a, TYPE b, const float epsilon=0.00001F)
Returns true iff a and b are equal with &#39;epsilon&#39; error margin.
Definition: Compare.hpp:23