[geos-commits] [SCM] GEOS branch master updated. 24652fb98c4da0ef41d8f21d6dd021b680e62fcd
git at osgeo.org
git at osgeo.org
Mon Dec 10 07:39:57 PST 2018
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 24652fb98c4da0ef41d8f21d6dd021b680e62fcd (commit)
from 4ae0648ae8f23952a9ca30b57f2706f3492b1e28 (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 24652fb98c4da0ef41d8f21d6dd021b680e62fcd
Author: Daniel Baston <dbaston at gmail.com>
Date: Tue Dec 4 14:36:55 2018 -0500
Fix mem leaks in SIRtreePointInRing
Fixes #944
diff --git a/include/geos/algorithm/SIRtreePointInRing.h b/include/geos/algorithm/SIRtreePointInRing.h
index cb29a69..6b1e0c3 100644
--- a/include/geos/algorithm/SIRtreePointInRing.h
+++ b/include/geos/algorithm/SIRtreePointInRing.h
@@ -18,7 +18,10 @@
#include <geos/export.h>
#include <geos/algorithm/PointInRing.h> // for inheritance
+#include <geos/index/strtree/SIRtree.h>
+#include <geos/geom/LineSegment.h>
+#include <memory>
#include <vector>
// Forward declarations
@@ -28,11 +31,6 @@ namespace geos {
class LineSegment;
class LinearRing;
}
- namespace index {
- namespace strtree {
- class SIRtree;
- }
- }
}
@@ -42,14 +40,15 @@ namespace algorithm { // geos::algorithm
class GEOS_DLL SIRtreePointInRing: public PointInRing {
private:
geom::LinearRing *ring;
- index::strtree::SIRtree *sirTree;
+ index::strtree::SIRtree sirTree;
+ std::vector<std::unique_ptr<geom::LineSegment>> segments;
int crossings; // number of segment/ray crossings
void buildIndex();
void testLineSegment(const geom::Coordinate& p,
geom::LineSegment *seg);
public:
SIRtreePointInRing(geom::LinearRing *newRing);
- ~SIRtreePointInRing() override;
+ ~SIRtreePointInRing() override = default;
bool isInside(const geom::Coordinate& pt) override;
};
diff --git a/src/algorithm/SIRtreePointInRing.cpp b/src/algorithm/SIRtreePointInRing.cpp
index 18087e5..19adc14 100644
--- a/src/algorithm/SIRtreePointInRing.cpp
+++ b/src/algorithm/SIRtreePointInRing.cpp
@@ -35,30 +35,23 @@ namespace algorithm { // geos.algorithm
SIRtreePointInRing::SIRtreePointInRing(LinearRing *newRing):
PointInRing(),
ring(newRing),
- sirTree(nullptr),
crossings(0)
{
buildIndex();
}
-SIRtreePointInRing::~SIRtreePointInRing()
-{
- delete sirTree;
-}
-
void
SIRtreePointInRing::buildIndex()
{
- //Envelope *env=ring->getEnvelopeInternal();
- sirTree=new SIRtree();
- const CoordinateSequence *pts=ring->getCoordinatesRO();
+ const CoordinateSequence *pts = ring->getCoordinatesRO();
const std::size_t npts=pts->getSize();
for(std::size_t i=1; i<npts; ++i)
{
if(pts->getAt(i-1)==pts->getAt(i)) continue; // Optimization suggested by MD. [Jon Aquino]
- LineSegment *seg=new LineSegment(pts->getAt(i-1), pts->getAt(i));
- sirTree->insert(seg->p0.y, seg->p1.y, seg);
+ std::unique_ptr<LineSegment> seg{new LineSegment(pts->getAt(i-1), pts->getAt(i))};
+ sirTree.insert(seg->p0.y, seg->p1.y, seg.get());
+ segments.push_back(std::move(seg));
}
}
@@ -67,20 +60,17 @@ SIRtreePointInRing::isInside(const Coordinate& pt)
{
crossings=0;
// test all segments intersected by vertical ray at pt
- vector<void*> *segs=sirTree->query(pt.y);
- //System.out.println("query size=" + segs.size());
- for(int i=0;i<(int)segs->size();i++) {
- LineSegment *seg=(LineSegment*) (*segs)[i];
+ std::unique_ptr<vector<void*>> segs{sirTree.query(pt.y)};
+
+ for(const auto& hit : *segs) {
+ LineSegment *seg = static_cast<LineSegment*>(hit);
testLineSegment(pt,seg);
}
/*
* p is inside if number of crossings is odd.
*/
- if ((crossings%2)==1) {
- return true;
- }
- return false;
+ return (crossings % 2) == 1;
}
void
@@ -108,7 +98,6 @@ SIRtreePointInRing::testLineSegment(const Coordinate& p,LineSegment *seg)
* segment straddles x axis,so compute intersection.
*/
xInt=RobustDeterminant::signOfDet2x2(x1,y1,x2,y2)/(y2-y1);
- //xsave=xInt;
/*
* crosses ray if strictly positive intersection.
*/
diff --git a/tests/unit/Makefile.am b/tests/unit/Makefile.am
index 17efa4d..9af1fd3 100644
--- a/tests/unit/Makefile.am
+++ b/tests/unit/Makefile.am
@@ -52,6 +52,7 @@ geos_unit_SOURCES = \
algorithm/PointLocatorTest.cpp \
algorithm/RobustLineIntersectionTest.cpp \
algorithm/RobustLineIntersectorTest.cpp \
+ algorithm/SIRtreePointInRingTest.cpp \
geom/CoordinateArraySequenceFactoryTest.cpp \
geom/CoordinateArraySequenceTest.cpp \
geom/CoordinateListTest.cpp \
diff --git a/tests/unit/algorithm/SIRtreePointInRingTest.cpp b/tests/unit/algorithm/SIRtreePointInRingTest.cpp
new file mode 100644
index 0000000..2ec04c5
--- /dev/null
+++ b/tests/unit/algorithm/SIRtreePointInRingTest.cpp
@@ -0,0 +1,56 @@
+//
+// Test Suite for geos::algorithm::SIRtreePointInRing
+
+#include <tut/tut.hpp>
+// geos
+#include <geos/geom/Coordinate.h>
+#include <geos/algorithm/SIRtreePointInRing.h>
+#include <geos/io/WKTReader.h>
+#include <geos/geom/Geometry.h>
+#include <geos/geom/LinearRing.h>
+// std
+#include <sstream>
+#include <string>
+#include <memory>
+
+namespace tut
+{
+ //
+ // Test Group
+ //
+
+ // dummy data, not used
+ struct test_sirtreepointinring_data {
+ using SIRtreePointInRing = geos::algorithm::SIRtreePointInRing;
+ using Geometry = geos::geom::Geometry;
+ using Coordinate = geos::geom::Coordinate;
+
+ geos::io::WKTReader reader;
+ std::unique_ptr<Geometry> geom;
+ };
+
+ typedef test_group<test_sirtreepointinring_data> group;
+ typedef group::object object;
+
+ group test_sirtreepointinring_data("geos::algorithm::SIRtreePointInRing");
+
+ //
+ // Test Cases
+ //
+
+ template<>
+ template<>
+ void object::test<1>()
+ {
+ using geos::geom::LinearRing;
+ geom.reset(reader.read("LINEARRING (0 0, 1 0, 1 1, 0 1, 0 0)"));
+
+ SIRtreePointInRing pir{dynamic_cast<LinearRing*>(geom.get())};
+
+ Coordinate c{0.5, 0.5};
+
+ ensure(pir.isInside(c));
+ }
+
+} // namespace tut
+
-----------------------------------------------------------------------
Summary of changes:
include/geos/algorithm/SIRtreePointInRing.h | 13 +++---
src/algorithm/SIRtreePointInRing.cpp | 29 ++++---------
tests/unit/Makefile.am | 1 +
tests/unit/algorithm/SIRtreePointInRingTest.cpp | 56 +++++++++++++++++++++++++
4 files changed, 72 insertions(+), 27 deletions(-)
create mode 100644 tests/unit/algorithm/SIRtreePointInRingTest.cpp
hooks/post-receive
--
GEOS
More information about the geos-commits
mailing list