[geos-commits] [SCM] GEOS branch master updated. 0d6b39f5e6df426af38aa33f8d26d47b8674d391
git at osgeo.org
git at osgeo.org
Fri Sep 13 11:11:59 PDT 2019
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GEOS".
The branch, master has been updated
via 0d6b39f5e6df426af38aa33f8d26d47b8674d391 (commit)
from bb238d0f23ac7b4f030b03921bfd1e5ddd16d05e (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 0d6b39f5e6df426af38aa33f8d26d47b8674d391
Author: Daniel Baston <dbaston at gmail.com>
Date: Thu Sep 12 22:20:09 2019 -0400
Add Coordinate::distanceSquared
This can be used to shave some time off minimum distance calculations.
diff --git a/include/geos/algorithm/CentralEndpointIntersector.h b/include/geos/algorithm/CentralEndpointIntersector.h
index f70b092..4c9145c 100644
--- a/include/geos/algorithm/CentralEndpointIntersector.h
+++ b/include/geos/algorithm/CentralEndpointIntersector.h
@@ -140,12 +140,12 @@ private:
findNearestPoint(const geom::Coordinate& p,
const std::vector<geom::Coordinate>& pts) const
{
- double minDist = std::numeric_limits<double>::max();
+ double minDistSq = std::numeric_limits<double>::max();
geom::Coordinate result = geom::Coordinate::getNull();
for(std::size_t i = 0, n = pts.size(); i < n; ++i) {
- double dist = p.distance(pts[i]);
- if(dist < minDist) {
- minDist = dist;
+ double distSq = p.distanceSquared(pts[i]);
+ if(distSq < minDistSq) {
+ minDistSq = distSq;
result = pts[i];
}
}
diff --git a/include/geos/algorithm/distance/DiscreteFrechetDistance.h b/include/geos/algorithm/distance/DiscreteFrechetDistance.h
index 85cfb1c..0d9ec0f 100644
--- a/include/geos/algorithm/distance/DiscreteFrechetDistance.h
+++ b/include/geos/algorithm/distance/DiscreteFrechetDistance.h
@@ -147,7 +147,7 @@ public:
return ptDist.getDistance();
}
- const std::vector<geom::Coordinate>
+ const std::array<geom::Coordinate, 2>
getCoordinates() const
{
return ptDist.getCoordinates();
diff --git a/include/geos/algorithm/distance/DiscreteHausdorffDistance.h b/include/geos/algorithm/distance/DiscreteHausdorffDistance.h
index df198cc..b5e538a 100644
--- a/include/geos/algorithm/distance/DiscreteHausdorffDistance.h
+++ b/include/geos/algorithm/distance/DiscreteHausdorffDistance.h
@@ -148,7 +148,7 @@ public:
return ptDist.getDistance();
}
- const std::vector<geom::Coordinate>
+ const std::array<geom::Coordinate, 2>
getCoordinates() const
{
return ptDist.getCoordinates();
diff --git a/include/geos/algorithm/distance/PointPairDistance.h b/include/geos/algorithm/distance/PointPairDistance.h
index effcc5e..7ab4add 100644
--- a/include/geos/algorithm/distance/PointPairDistance.h
+++ b/include/geos/algorithm/distance/PointPairDistance.h
@@ -22,7 +22,7 @@
#include <geos/constants.h> // for DoubleNotANumber
#include <geos/geom/Coordinate.h> // for inlines
-#include <vector> // for composition
+#include <array>
#include <cassert>
namespace geos {
@@ -39,12 +39,9 @@ public:
PointPairDistance()
:
- pt(2),
- distance(DoubleNotANumber),
+ distanceSquared(DoubleNotANumber),
isNull(true)
- {
- assert(pt.size() == 2);
- }
+ {}
void
initialize()
@@ -57,17 +54,17 @@ public:
{
pt[0] = p0;
pt[1] = p1;
- distance = p0.distance(p1);
+ distanceSquared = p0.distanceSquared(p1);
isNull = false;
}
double
getDistance() const
{
- return distance;
+ return std::sqrt(distanceSquared);
}
- const std::vector<geom::Coordinate>&
+ const std::array<geom::Coordinate, 2>&
getCoordinates() const
{
return pt;
@@ -93,9 +90,9 @@ public:
initialize(p0, p1);
return;
}
- double dist = p0.distance(p1);
- if(dist > distance) {
- initialize(p0, p1, dist);
+ double distSq = p0.distanceSquared(p1);
+ if(distSq > distanceSquared) {
+ initialize(p0, p1, distSq);
}
}
@@ -112,9 +109,9 @@ public:
initialize(p0, p1);
return;
}
- double dist = p0.distance(p1);
- if(dist < distance) {
- initialize(p0, p1, dist);
+ double distSq = p0.distanceSquared(p1);
+ if(distSq < distanceSquared) {
+ initialize(p0, p1, distSq);
}
}
@@ -134,17 +131,17 @@ private:
*/
void
initialize(const geom::Coordinate& p0, const geom::Coordinate& p1,
- double dist)
+ double distSquared)
{
pt[0] = p0;
pt[1] = p1;
- distance = dist;
+ distanceSquared = distSquared;
isNull = false;
}
- std::vector<geom::Coordinate> pt;
+ std::array<geom::Coordinate, 2> pt;
- double distance;
+ double distanceSquared;
bool isNull;
};
diff --git a/include/geos/geom/Coordinate.h b/include/geos/geom/Coordinate.h
index fdd5bbb..7a41c94 100644
--- a/include/geos/geom/Coordinate.h
+++ b/include/geos/geom/Coordinate.h
@@ -113,6 +113,8 @@ public:
double distance(const Coordinate& p) const;
+ double distanceSquared(const Coordinate& p) const;
+
int hashCode() const;
/**
diff --git a/include/geos/geom/Coordinate.inl b/include/geos/geom/Coordinate.inl
index 49d2b96..74df6fd 100644
--- a/include/geos/geom/Coordinate.inl
+++ b/include/geos/geom/Coordinate.inl
@@ -97,6 +97,14 @@ Coordinate::distance(const Coordinate& p) const
return std::sqrt(dx * dx + dy * dy);
}
+INLINE double
+Coordinate::distanceSquared(const Coordinate& p) const
+{
+ double dx = x - p.x;
+ double dy = y - p.y;
+ return dx * dx + dy * dy;
+}
+
INLINE int
Coordinate::hashCode() const
{
-----------------------------------------------------------------------
Summary of changes:
.../geos/algorithm/CentralEndpointIntersector.h | 8 ++---
.../algorithm/distance/DiscreteFrechetDistance.h | 2 +-
.../algorithm/distance/DiscreteHausdorffDistance.h | 2 +-
.../geos/algorithm/distance/PointPairDistance.h | 35 ++++++++++------------
include/geos/geom/Coordinate.h | 2 ++
include/geos/geom/Coordinate.inl | 8 +++++
6 files changed, 32 insertions(+), 25 deletions(-)
hooks/post-receive
--
GEOS
More information about the geos-commits
mailing list