Description: Fix test error caused by floating point rounding issue
Author: Greg Sharp <gregsharp.geo@yahoo.com>
fix FTBFS for platforms still on ITK 3.20
Bug-Debian: http://bugs.debian.org/789314
Last-Updated: 2015-07-10 23:36:37 +0200

--- a/src/plastimatch/base/plm_image_header.cxx
+++ b/src/plastimatch/base/plm_image_header.cxx
@@ -433,24 +433,25 @@
     }
 }
 
-double 
-Plm_image_header::plm_round(double val, int digits)
-{
-	return floor(val * pow((double)10, digits) + 0.5) / pow((double)10, digits);
-}
-
-/* Return 1 if the two headers are the same. Added tolerance (5 digits) */
+/* Return true if the two headers are the same, within tolerance */
 bool
-Plm_image_header::compare (Plm_image_header *pli1, Plm_image_header *pli2,int digits)
+Plm_image_header::compare (Plm_image_header *pli1, Plm_image_header *pli2,
+    float threshold)
 {
     int d;
     for (d = 0; d < 3; d++) {
-    if (plm_round(pli1->m_origin[d],5) != plm_round(pli2->m_origin[d],5)) return 0;
-    if (plm_round(pli1->m_spacing[d],5) != plm_round(pli2->m_spacing[d],5)) return 0;
-    if (plm_round(pli1->Size(d),5) != plm_round(pli2->Size(d),5)) return 0;
+        if (fabs (pli1->m_origin[d] - pli2->m_origin[d]) > threshold) {
+           return false;
+        }
+        if (fabs (pli1->m_spacing[d] - pli2->m_spacing[d]) > threshold) {
+            return false;
+        }
+        if (pli1->Size(d) != pli2->Size(d)) {
+            return false;
+        }
     }
 
     /* GCS FIX: check direction cosines */
 
-    return 1;
+    return true;
 }
--- a/src/plastimatch/base/plm_image_header.h
+++ b/src/plastimatch/base/plm_image_header.h
@@ -69,9 +69,11 @@
     int Size (int d) const { return m_region.GetSize()[d]; }
     const SizeType& GetSize (void) const { return m_region.GetSize (); }
 public:
-    /*! \brief Return true if the two headers are the same. Tolerance can be specified via using digits (=number of digits used for rounding values) */
-    static bool compare (Plm_image_header *pli1, Plm_image_header *pli2,int digits=5);
-    static double plm_round(double val, int digits);
+    /*! \brief Return true if the two headers are the same. 
+      Tolerance on origin and spacing can be specified 
+      using the threshold parameter */
+    static bool compare (Plm_image_header *pli1, Plm_image_header *pli2, 
+        float threshold = 1e-5);
 
     int dim (int d) const { return m_region.GetSize()[d]; }
     float origin (int d) const { return m_origin[d]; }
