Skip to content

v0.2.53..v0.2.54 changeset OverlapExtractor.cpp

Garret Voltz edited this page Mar 31, 2020 · 1 revision
diff --git a/hoot-core/src/main/cpp/hoot/core/algorithms/extractors/OverlapExtractor.cpp b/hoot-core/src/main/cpp/hoot/core/algorithms/extractors/OverlapExtractor.cpp
index 3014134..12395d3 100644
--- a/hoot-core/src/main/cpp/hoot/core/algorithms/extractors/OverlapExtractor.cpp
+++ b/hoot-core/src/main/cpp/hoot/core/algorithms/extractors/OverlapExtractor.cpp
@@ -23,7 +23,7 @@
  * copyrights will be updated automatically.
  *
  * @copyright Copyright (C) 2005 VividSolutions (http://www.vividsolutions.com/)
- * @copyright Copyright (C) 2015, 2017, 2018, 2019 DigitalGlobe (http://www.digitalglobe.com/)
+ * @copyright Copyright (C) 2015, 2017, 2018, 2019, 2020 DigitalGlobe (http://www.digitalglobe.com/)
  */
 #include "OverlapExtractor.h"
 
@@ -37,6 +37,8 @@
 #include <hoot/core/util/GeometryUtils.h>
 #include <hoot/core/elements/Element.h>
 
+#include <QElapsedTimer>
+
 using namespace geos::geom;
 using namespace std;
 
@@ -52,11 +54,18 @@ OverlapExtractor::OverlapExtractor()
 double OverlapExtractor::extract(const OsmMap& map, const ConstElementPtr& target,
   const ConstElementPtr& candidate) const
 {
+  LOG_DEBUG(
+    "Calculating overlap for " << target->getElementId() << " and " << candidate->getElementId() <<
+    "...");
+
   ElementConverter ec(map.shared_from_this());
   std::shared_ptr<Geometry> g1 = ec.convertToGeometry(target);
+  if (g1->isEmpty())
+  {
+    return nullValue();
+  }
   std::shared_ptr<Geometry> g2 = ec.convertToGeometry(candidate);
-
-  if (g1->isEmpty() || g2->isEmpty())
+  if (g2->isEmpty())
   {
     return nullValue();
   }
@@ -75,14 +84,17 @@ double OverlapExtractor::extract(const OsmMap& map, const ConstElementPtr& targe
 
   double a1 = g1->getArea();
   double a2 = g2->getArea();
-  double overlapArea = overlap->getArea();
 
   if (a1 + a2 == 0)
   {
     return 0.0;
   }
 
-  return std::min(1.0, (2 * overlapArea) / (a1 + a2));
+  double overlapArea = overlap->getArea();
+
+  const double result = std::min(1.0, (2 * overlapArea) / (a1 + a2));
+
+  return result;
 }
 
 }
Clone this wiki locally