[geos-commits] [SCM] GEOS branch 3.9 updated. be94f05a7de2c2e32c338eb8f4f36c569cdfeea0
git at osgeo.org
git at osgeo.org
Thu Jun 24 14:42:25 PDT 2021
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, 3.9 has been updated
via be94f05a7de2c2e32c338eb8f4f36c569cdfeea0 (commit)
from 3fcdbcfe30d42f814ff00da49a195c8f2298186f (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 be94f05a7de2c2e32c338eb8f4f36c569cdfeea0
Author: Even Rouault <even.rouault at spatialys.com>
Date: Thu Jun 17 00:17:11 2021 +0200
LineSegment: tiny improvement in project(const LineSegment&, ...) and closestPoint()
Those methods already compute the projection factor, but then call
project() which recomputes it again. Avoid that duplicated computation.
Didn't identify this as a hotspot, but should save a few CPU cycles.
diff --git a/include/geos/geom/LineSegment.h b/include/geos/geom/LineSegment.h
index 459f1b2..1cf412e 100644
--- a/include/geos/geom/LineSegment.h
+++ b/include/geos/geom/LineSegment.h
@@ -369,6 +369,10 @@ public:
return h ^ (std::hash<double>{}(s.p1.y) << 1);
}
};
+
+private:
+ void project(double factor, Coordinate& ret) const;
+
};
std::ostream& operator<< (std::ostream& o, const LineSegment& l);
diff --git a/src/geom/LineSegment.cpp b/src/geom/LineSegment.cpp
index bba2a45..0716766 100644
--- a/src/geom/LineSegment.cpp
+++ b/src/geom/LineSegment.cpp
@@ -105,6 +105,16 @@ LineSegment::project(const Coordinate& p, Coordinate& ret) const
ret = Coordinate(p0.x + r * (p1.x - p0.x), p0.y + r * (p1.y - p0.y));
}
+/*private*/
+void
+LineSegment::project(double factor, Coordinate& ret) const
+{
+ if( factor == 1.0 )
+ ret = p1;
+ else
+ ret = Coordinate(p0.x + factor * (p1.x - p0.x), p0.y + factor * (p1.y - p0.y));
+}
+
bool
LineSegment::project(const LineSegment& seg, LineSegment& ret) const
{
@@ -121,9 +131,9 @@ LineSegment::project(const LineSegment& seg, LineSegment& ret) const
}
Coordinate newp0;
- project(seg.p0, newp0);
+ project(pf0, newp0);
Coordinate newp1;
- project(seg.p1, newp1);
+ project(pf1, newp1);
ret.setCoordinates(newp0, newp1);
@@ -136,7 +146,7 @@ LineSegment::closestPoint(const Coordinate& p, Coordinate& ret) const
{
double factor = projectionFactor(p);
if(factor > 0 && factor < 1) {
- project(p, ret);
+ project(factor, ret);
return;
}
double dist0 = p0.distance(p);
-----------------------------------------------------------------------
Summary of changes:
include/geos/geom/LineSegment.h | 4 ++++
src/geom/LineSegment.cpp | 16 +++++++++++++---
2 files changed, 17 insertions(+), 3 deletions(-)
hooks/post-receive
--
GEOS
More information about the geos-commits
mailing list