From c95f5b3412c22bf779973462f16f36ec3eccc8b8 Mon Sep 17 00:00:00 2001
From: Julien Osman <julien.osman@csgroup.eu>
Date: Tue, 5 May 2020 11:19:48 +0200
Subject: [PATCH] REFAC: use itk::Math::AlmostEquals for floats comparison

---
 Modules/Core/Metadata/include/otbImageMetadata.h | 1 +
 Modules/Core/Metadata/src/otbImageMetadata.cxx   | 4 ++--
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/Modules/Core/Metadata/include/otbImageMetadata.h b/Modules/Core/Metadata/include/otbImageMetadata.h
index 77a405ac21..ac8b9f2c57 100644
--- a/Modules/Core/Metadata/include/otbImageMetadata.h
+++ b/Modules/Core/Metadata/include/otbImageMetadata.h
@@ -25,6 +25,7 @@
 #include "otbMetaDataKey.h"
 #include "OTBMetadataExport.h"
 #include "otbMacro.h"
+#include "itkMath.h"
 
 #include <boost/any.hpp>
 #include <vector>
diff --git a/Modules/Core/Metadata/src/otbImageMetadata.cxx b/Modules/Core/Metadata/src/otbImageMetadata.cxx
index 631f482a72..1997503e25 100644
--- a/Modules/Core/Metadata/src/otbImageMetadata.cxx
+++ b/Modules/Core/Metadata/src/otbImageMetadata.cxx
@@ -479,7 +479,7 @@ void ImageMetadata::compact()
     {
       auto otherKey = bandIt->NumericKeys.find(kv.first);
       if ((otherKey == bandIt->NumericKeys.end())
-       || !(std::fabs(otherKey->second != kv.second) <= std::numeric_limits<double>::epsilon()))
+       || !itk::Math::AlmostEquals(otherKey->second, kv.second))
       {
         compactVal = false;
         break;
@@ -531,7 +531,7 @@ void ImageMetadata::compact()
     {
       auto otherKey = bandIt->TimeKeys.find(kv.first);
       if ((otherKey == bandIt->TimeKeys.end())
-       || !(std::fabs(otherKey->second.frac_sec != kv.second.frac_sec) <= std::numeric_limits<double>::epsilon()))
+       || !itk::Math::AlmostEquals(otherKey->second.frac_sec, kv.second.frac_sec))
       {
         compactVal = false;
         break;
-- 
GitLab