[geos-commits] [SCM] GEOS branch master updated. 1866159c644fb5c74f13f0714ebaba8e5c3e65ff

git at osgeo.org git at osgeo.org
Thu Dec 27 16:44:08 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  1866159c644fb5c74f13f0714ebaba8e5c3e65ff (commit)
       via  cf5c431b0e74a9e315286f053b1d36ffd7a005bd (commit)
       via  7014e2b6509709f70dc08ca3b4b4d843d3df2a71 (commit)
       via  e28a0ddaa86eafabc0f706dbaab2a1924da764d8 (commit)
       via  6b846f06b16ef3a3e19dabd78bdae8a68a29d1c1 (commit)
       via  e9e5d36bea09c7e8831896a0fb201bc4e4968179 (commit)
       via  4ee12f2bcf6d7cf4330ca071ba63d7c3f3a1557a (commit)
       via  aad567105de086046f7ee057161a390f026337b9 (commit)
       via  32c292da64c84c6a5c8d5a9365aeade2ef530cfe (commit)
       via  42bd6eca3de1cf6d746eb04b644f42994f166f3c (commit)
       via  56acc15f0ac215bde0739017490a44963841ca22 (commit)
       via  b5f78b41ff219ef1cd5ce594ca8043845c0e4bd0 (commit)
       via  e0f1224cfe172c71763f8d7ce138127532b06fb6 (commit)
       via  af66a6d49b9def34f2392c788e8418de11a0e0c0 (commit)
       via  8de4141a244fb0e853a365d08aea3794598aef18 (commit)
       via  5f0919f1d25651ba3372bd34ec6d31e5ceb5cc14 (commit)
      from  b0504db56985a34c9c097b502c5878795d454b3b (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 1866159c644fb5c74f13f0714ebaba8e5c3e65ff
Merge: cf5c431 5f0919f
Author: Daniel Baston <dbaston at gmail.com>
Date:   Thu Dec 27 19:43:43 2018 -0500

    Merge remote-tracking branch 'sir-sigurd/collection-get-coordinate'


commit cf5c431b0e74a9e315286f053b1d36ffd7a005bd
Merge: b0504db 7014e2b
Author: Daniel Baston <dbaston at gmail.com>
Date:   Thu Dec 27 19:42:10 2018 -0500

    Merge branch 'optimize-tps'


commit 7014e2b6509709f70dc08ca3b4b4d843d3df2a71
Author: Daniel Baston <dbaston at gmail.com>
Date:   Sat Dec 22 20:49:22 2018 -0500

    Change std::map to std::unordered_map in TopologyPreservingSimplifier

diff --git a/src/simplify/TopologyPreservingSimplifier.cpp b/src/simplify/TopologyPreservingSimplifier.cpp
index b3a7022..c82935d 100644
--- a/src/simplify/TopologyPreservingSimplifier.cpp
+++ b/src/simplify/TopologyPreservingSimplifier.cpp
@@ -32,7 +32,7 @@
 #include <geos/util/IllegalArgumentException.h>
 
 #include <memory> // for unique_ptr
-#include <map>
+#include <unordered_map>
 #include <cassert>
 #include <iostream>
 
@@ -41,7 +41,7 @@ using namespace geos::geom;
 namespace geos {
 namespace simplify { // geos::simplify
 
-typedef std::map<const geom::Geometry*, TaggedLineString* > LinesMap;
+using LinesMap = std::unordered_map<const geom::Geometry*, TaggedLineString*>;
 
 
 namespace { // module-statics

commit e28a0ddaa86eafabc0f706dbaab2a1924da764d8
Author: Daniel Baston <dbaston at gmail.com>
Date:   Sat Dec 22 20:44:50 2018 -0500

    Optimize intersection testing
    
    Robust line intersection tests are slow, so avoid testing each line
    segment against itself and then ignoring the positive result.

diff --git a/src/simplify/TaggedLineStringSimplifier.cpp b/src/simplify/TaggedLineStringSimplifier.cpp
index 4b5c6c0..95218c0 100644
--- a/src/simplify/TaggedLineStringSimplifier.cpp
+++ b/src/simplify/TaggedLineStringSimplifier.cpp
@@ -242,15 +242,9 @@ TaggedLineStringSimplifier::hasBadInputIntersection(
 	{
 		const TaggedLineSegment* querySeg = static_cast<const TaggedLineSegment*>(ls);
 
-		if (hasInteriorIntersection(*querySeg, candidateSeg))
+		if (!isInLineSection(parentLine, sectionIndex, querySeg) && hasInteriorIntersection(*querySeg, candidateSeg))
 		{
 
-			if ( isInLineSection(parentLine,
-					sectionIndex, querySeg) )
-			{
-				continue;
-			}
-
 			return true;
 		}
 	}

commit 6b846f06b16ef3a3e19dabd78bdae8a68a29d1c1
Author: Daniel Baston <dbaston at gmail.com>
Date:   Sat Dec 22 20:43:15 2018 -0500

    Use std::pair instead of length-2 std::vector

diff --git a/include/geos/simplify/TaggedLineStringSimplifier.h b/include/geos/simplify/TaggedLineStringSimplifier.h
index 034c919..dae0571 100644
--- a/include/geos/simplify/TaggedLineStringSimplifier.h
+++ b/include/geos/simplify/TaggedLineStringSimplifier.h
@@ -112,11 +112,11 @@ private:
 			double& maxDistance);
 
 	bool hasBadIntersection(const TaggedLineString* parentLine,
-                       const std::vector<std::size_t>& sectionIndex,
+                       const std::pair<std::size_t, std::size_t>& sectionIndex,
                        const geom::LineSegment& candidateSeg);
 
 	bool hasBadInputIntersection(const TaggedLineString* parentLine,
-                       const std::vector<std::size_t>& sectionIndex,
+                       const std::pair<std::size_t, std::size_t>& sectionIndex,
                        const geom::LineSegment& candidateSeg);
 
 	bool hasBadOutputIntersection(const geom::LineSegment& candidateSeg);
@@ -137,7 +137,7 @@ private:
 	 */
 	static bool isInLineSection(
 		const TaggedLineString* parentLine,
-		const std::vector<std::size_t>& sectionIndex,
+		const std::pair<std::size_t, std::size_t>& sectionIndex,
 		const TaggedLineSegment* seg);
 
 	/** \brief
diff --git a/src/simplify/TaggedLineStringSimplifier.cpp b/src/simplify/TaggedLineStringSimplifier.cpp
index b51cf4b..4b5c6c0 100644
--- a/src/simplify/TaggedLineStringSimplifier.cpp
+++ b/src/simplify/TaggedLineStringSimplifier.cpp
@@ -95,8 +95,6 @@ TaggedLineStringSimplifier::simplifySection(std::size_t i,
 	          << std::endl;
 #endif
 
-	vector<std::size_t> sectionIndex(2);
-
 	if((i+1) == j)
 	{
 
@@ -146,10 +144,7 @@ TaggedLineStringSimplifier::simplifySection(std::size_t i,
 	// test if flattened section would cause intersection
 	LineSegment candidateSeg(linePts->getAt(i), linePts->getAt(j));
 
-	sectionIndex[0] = i;
-	sectionIndex[1] = j;
-
-	if (hasBadIntersection(line, sectionIndex, candidateSeg))
+	if (hasBadIntersection(line, std::make_pair(i, j), candidateSeg))
 			isValidToSimplify = false;
 
 	if (isValidToSimplify)
@@ -192,7 +187,7 @@ TaggedLineStringSimplifier::flatten(std::size_t start, std::size_t end)
 bool
 TaggedLineStringSimplifier::hasBadIntersection(
 		const TaggedLineString* parentLine,
-		const vector<std::size_t>& sectionIndex,
+		const pair<size_t, size_t>& sectionIndex,
 		const LineSegment& candidateSeg)
 {
 	if (hasBadOutputIntersection(candidateSeg))
@@ -237,7 +232,7 @@ TaggedLineStringSimplifier::hasInteriorIntersection(
 bool
 TaggedLineStringSimplifier::hasBadInputIntersection(
 		const TaggedLineString* parentLine,
-		const vector<std::size_t>& sectionIndex,
+		const pair<std::size_t, std::size_t>& sectionIndex,
 		const LineSegment& candidateSeg)
 {
 	unique_ptr< vector<LineSegment*> > querySegs =
@@ -267,7 +262,7 @@ TaggedLineStringSimplifier::hasBadInputIntersection(
 bool
 TaggedLineStringSimplifier::isInLineSection(
 		const TaggedLineString* line,
-		const vector<std::size_t>& sectionIndex,
+		const pair<size_t, size_t>& sectionIndex,
 		const TaggedLineSegment* seg)
 {
 	// not in this line
@@ -275,7 +270,7 @@ TaggedLineStringSimplifier::isInLineSection(
 		return false;
 
 	std::size_t segIndex = seg->getIndex();
-	if (segIndex >= sectionIndex[0] && segIndex < sectionIndex[1])
+	if (segIndex >= sectionIndex.first && segIndex < sectionIndex.second)
 		return true;
 
 	return false;

commit e9e5d36bea09c7e8831896a0fb201bc4e4968179
Author: Daniel Baston <dbaston at gmail.com>
Date:   Sat Dec 22 20:35:31 2018 -0500

    Avoid specifying iterator type

diff --git a/src/index/quadtree/NodeBase.cpp b/src/index/quadtree/NodeBase.cpp
index 3103be4..394ab01 100644
--- a/src/index/quadtree/NodeBase.cpp
+++ b/src/index/quadtree/NodeBase.cpp
@@ -254,8 +254,7 @@ NodeBase::remove(const Envelope* itemEnv, void* item)
 
 	// otherwise, try and remove the item from the list of items
 	// in this node
-	vector<void*>::iterator foundIter =
-		find(items.begin(), items.end(), item);
+	auto foundIter = find(items.begin(), items.end(), item);
 	if ( foundIter != items.end() ) {
 		items.erase(foundIter);
 		return true;

commit 4ee12f2bcf6d7cf4330ca071ba63d7c3f3a1557a
Author: Daniel Baston <dbaston at gmail.com>
Date:   Sat Dec 22 20:31:53 2018 -0500

    Simplify for loop

diff --git a/src/index/quadtree/NodeBase.cpp b/src/index/quadtree/NodeBase.cpp
index 54c65b9..3103be4 100644
--- a/src/index/quadtree/NodeBase.cpp
+++ b/src/index/quadtree/NodeBase.cpp
@@ -219,10 +219,8 @@ NodeBase::visitItems(const Envelope* searchEnv, ItemVisitor& visitor)
 
 	// would be nice to filter items based on search envelope, but can't
 	// until they contain an envelope
-	for (vector<void*>::iterator i=items.begin(), e=items.end();
-			i!=e; i++)
-	{
-		visitor.visitItem(*i);
+	for (auto& item : items) {
+		visitor.visitItem(item);
 	}
 }
 

commit aad567105de086046f7ee057161a390f026337b9
Author: Daniel Baston <dbaston at gmail.com>
Date:   Sat Dec 22 20:30:17 2018 -0500

    Use std::array for Quadtree nodes

diff --git a/include/geos/index/quadtree/NodeBase.h b/include/geos/index/quadtree/NodeBase.h
index 10e197c..4d9d76e 100644
--- a/include/geos/index/quadtree/NodeBase.h
+++ b/include/geos/index/quadtree/NodeBase.h
@@ -20,6 +20,7 @@
 #define GEOS_IDX_QUADTREE_NODEBASE_H
 
 #include <geos/export.h>
+#include <array>
 #include <vector>
 #include <string>
 
@@ -119,7 +120,7 @@ protected:
 	 *
 	 * Nodes are owned by this class
 	 */
-	Node* subnode[4];
+	std::array<Node*, 4> subnodes;
 
 	virtual bool isSearchMatch(const geom::Envelope& searchEnv) const=0;
 };
@@ -130,8 +131,11 @@ protected:
 inline bool
 NodeBase::hasChildren() const
 {
-	for (int i = 0; i < 4; i++)
-		if (subnode[i]) return true;
+	for (const auto& subnode : subnodes) {
+		if (subnode != nullptr)
+			return true;
+	}
+
 	return false;
 }
 
diff --git a/src/index/quadtree/Node.cpp b/src/index/quadtree/Node.cpp
index 2e30440..20a3525 100644
--- a/src/index/quadtree/Node.cpp
+++ b/src/index/quadtree/Node.cpp
@@ -101,9 +101,9 @@ Node::find(const Envelope *searchEnv)
 	int subnodeIndex=getSubnodeIndex(searchEnv, centre);
 	if (subnodeIndex==-1)
 		return this;
-	if (subnode[subnodeIndex]!=nullptr) {
+	if (subnodes[subnodeIndex]!=nullptr) {
 		// query lies in subquad, so search it
-		Node *node=subnode[subnodeIndex];
+		Node *node=subnodes[subnodeIndex];
 		return node->find(searchEnv);
 	}
 	// no existing subquad, so return this one anyway
@@ -121,8 +121,8 @@ Node::insertNode(std::unique_ptr<Node> node)
 	if (node->level == level-1)
 	{
 		// We take ownership of node
-		delete subnode[index];
-		subnode[index] = node.release();
+		delete subnodes[index];
+		subnodes[index] = node.release();
 
 		//System.out.println("inserted");
 	}
@@ -136,8 +136,8 @@ Node::insertNode(std::unique_ptr<Node> node)
 		childNode->insertNode(std::move(node));
 
 		// We take ownership of childNode
-		delete subnode[index];
-		subnode[index] = childNode.release();
+		delete subnodes[index];
+		subnodes[index] = childNode.release();
 	}
 }
 
@@ -145,11 +145,11 @@ Node*
 Node::getSubnode(int index)
 {
 	assert(index >=0 && index < 4);
-	if (subnode[index] == nullptr)
+	if (subnodes[index] == nullptr)
 	{
-		subnode[index] = createSubnode(index).release();
+		subnodes[index] = createSubnode(index).release();
 	}
-	return subnode[index];
+	return subnodes[index];
 }
 
 std::unique_ptr<Node>
diff --git a/src/index/quadtree/NodeBase.cpp b/src/index/quadtree/NodeBase.cpp
index d8191a0..54c65b9 100644
--- a/src/index/quadtree/NodeBase.cpp
+++ b/src/index/quadtree/NodeBase.cpp
@@ -63,22 +63,22 @@ NodeBase::getSubnodeIndex(const Envelope *env, const Coordinate& centre)
 
 NodeBase::NodeBase()
 {
-	subnode[0]=nullptr;
-	subnode[1]=nullptr;
-	subnode[2]=nullptr;
-	subnode[3]=nullptr;
+	subnodes[0]=nullptr;
+	subnodes[1]=nullptr;
+	subnodes[2]=nullptr;
+	subnodes[3]=nullptr;
 }
 
 NodeBase::~NodeBase()
 {
-	delete subnode[0];
-	delete subnode[1];
-	delete subnode[2];
-	delete subnode[3];
-	subnode[0]=nullptr;
-	subnode[1]=nullptr;
-	subnode[2]=nullptr;
-	subnode[3]=nullptr;
+	delete subnodes[0];
+	delete subnodes[1];
+	delete subnodes[2];
+	delete subnodes[3];
+	subnodes[0]=nullptr;
+	subnodes[1]=nullptr;
+	subnodes[2]=nullptr;
+	subnodes[3]=nullptr;
 }
 
 vector<void*>&
@@ -102,11 +102,11 @@ NodeBase::addAllItems(vector<void*>& resultItems) const
 	// be wholly contained in any single subnode
 	resultItems.insert(resultItems.end(), items.begin(), items.end());
 
-	for(int i=0; i<4; ++i)
+	for(const auto& subnode : subnodes)
 	{
-		if ( subnode[i] )
+		if (subnode != nullptr)
 		{
-			subnode[i]->addAllItems(resultItems);
+			subnode->addAllItems(resultItems);
 		}
 	}
 	return resultItems;
@@ -123,11 +123,11 @@ NodeBase::addAllItemsFromOverlapping(const Envelope& searchEnv,
 	// be wholly contained in any single subnode
 	resultItems.insert(resultItems.end(), items.begin(), items.end());
 
-	for(int i=0; i<4; ++i)
+	for(const auto& subnode : subnodes)
 	{
-		if ( subnode[i] )
+		if (subnode != nullptr)
 		{
-			subnode[i]->addAllItemsFromOverlapping(searchEnv,
+			subnode->addAllItemsFromOverlapping(searchEnv,
 			                                       resultItems);
 		}
 	}
@@ -139,11 +139,12 @@ unsigned int
 NodeBase::depth() const
 {
 	unsigned int maxSubDepth=0;
-	for (int i=0; i<4; ++i)
+
+	for (const auto& subnode : subnodes)
 	{
-		if (subnode[i] != nullptr)
+		if (subnode != nullptr)
 		{
-			unsigned int sqd=subnode[i]->depth();
+			unsigned int sqd=subnode->depth();
 			if ( sqd > maxSubDepth )
 				maxSubDepth=sqd;
 		}
@@ -155,11 +156,11 @@ size_t
 NodeBase::size() const
 {
 	size_t subSize = 0;
-	for(int i=0; i<4; i++)
+	for(const auto& subnode : subnodes)
 	{
-		if (subnode[i] != nullptr)
+		if (subnode != nullptr)
 		{
-			subSize += subnode[i]->size();
+			subSize += subnode->size();
 		}
 	}
 	return subSize + items.size();
@@ -169,11 +170,9 @@ size_t
 NodeBase::getNodeCount() const
 {
 	size_t subSize = 0;
-	for(int i=0; i<4; ++i)
-	{
-		if (subnode[i] != nullptr)
-		{
-			subSize += subnode[i]->size();
+	for (const auto& subnode : subnodes) {
+		if (subnode != nullptr) {
+			subSize += subnode->size();
 		}
 	}
 
@@ -185,11 +184,11 @@ NodeBase::toString() const
 {
 	ostringstream s;
 	s<<"ITEMS:"<<items.size()<<endl;
-	for (int i=0; i<4; i++)
+	for (size_t i=0; i < subnodes.size(); i++)
 	{
 		s<<"subnode["<<i<<"] ";
-		if ( subnode[i] == nullptr ) s<<"NULL";
-		else s<<subnode[i]->toString();
+		if ( subnodes[i] == nullptr ) s<<"NULL";
+		else s<<subnodes[i]->toString();
 		s<<endl;
 	}
 	return s.str();
@@ -205,9 +204,9 @@ NodeBase::visit(const Envelope* searchEnv, ItemVisitor& visitor)
 	// be wholly contained in any single subnode
 	visitItems(searchEnv, visitor);
 
-	for (int i = 0; i < 4; i++) {
-		if (subnode[i] != nullptr) {
-			subnode[i]->visit(searchEnv, visitor);
+	for (const auto& subnode : subnodes) {
+		if (subnode != nullptr) {
+			subnode->visit(searchEnv, visitor);
 		}
 	}
 }
@@ -235,18 +234,18 @@ NodeBase::remove(const Envelope* itemEnv, void* item)
 	if (! isSearchMatch(*itemEnv)) return false;
 
 	bool found = false;
-	for (int i = 0; i < 4; ++i)
+	for (auto& subnode : subnodes)
 	{
-		if ( subnode[i] )
+		if (subnode != nullptr)
 		{
-			found = subnode[i]->remove(itemEnv, item);
+			found = subnode->remove(itemEnv, item);
 			if (found)
 			{
 				// trim subtree if empty
-				if (subnode[i]->isPrunable())
+				if (subnode->isPrunable())
 				{
-					delete subnode[i];
-					subnode[i] = nullptr;
+					delete subnode;
+					subnode = nullptr;
 				}
 				break;
 			}
diff --git a/src/index/quadtree/Root.cpp b/src/index/quadtree/Root.cpp
index a0301fc..3dbe298 100644
--- a/src/index/quadtree/Root.cpp
+++ b/src/index/quadtree/Root.cpp
@@ -66,7 +66,7 @@ Root::insert(const Envelope *itemEnv, void* item)
 	 * the item must be contained in one quadrant, so insert it into the
 	 * tree for that quadrant (which may not yet exist)
 	 */
-	Node *node = subnode[index];
+	Node *node = subnodes[index];
 
 #if GEOS_DEBUG
 	std::cerr<<"("<<this<<") subnode["<<index<<"] @ "<<node<<std::endl;
@@ -79,7 +79,7 @@ Root::insert(const Envelope *itemEnv, void* item)
 	if (node==nullptr || !node->getEnvelope()->contains(itemEnv))
 	{
 		std::unique_ptr<Node> snode (node); // may be NULL
-		node = nullptr; subnode[index] = nullptr;
+		node = nullptr; subnodes[index] = nullptr;
 
 		std::unique_ptr<Node> largerNode =
 			Node::createExpanded(std::move(snode), *itemEnv);
@@ -89,8 +89,8 @@ Root::insert(const Envelope *itemEnv, void* item)
 #endif
 
 		// Previous subnode was passed as a child of the larger one
-		assert(!subnode[index]);
-		subnode[index] = largerNode.release();
+		assert(!subnodes[index]);
+		subnodes[index] = largerNode.release();
 	}
 
 #if GEOS_DEBUG
@@ -100,7 +100,7 @@ Root::insert(const Envelope *itemEnv, void* item)
 	 * At this point we have a subquad which exists and must contain
 	 * contains the env for the item.  Insert the item into the tree.
 	 */
-	insertContained(subnode[index], itemEnv, item);
+	insertContained(subnodes[index], itemEnv, item);
 
 #if GEOS_DEBUG
 	std::cerr<<"("<<this<<") done calling insertContained with subnode " << subnode[index] << std::endl;

commit 32c292da64c84c6a5c8d5a9365aeade2ef530cfe
Author: Daniel Baston <dbaston at gmail.com>
Date:   Sat Dec 22 20:08:07 2018 -0500

    Use unique_ptr for Quadtree-owned envelopes

diff --git a/include/geos/index/quadtree/Quadtree.h b/include/geos/index/quadtree/Quadtree.h
index 0ce3746..21cca2a 100644
--- a/include/geos/index/quadtree/Quadtree.h
+++ b/include/geos/index/quadtree/Quadtree.h
@@ -20,9 +20,11 @@
 #define GEOS_IDX_QUADTREE_QUADTREE_H
 
 #include <geos/export.h>
+#include <geos/geom/Envelope.h>
 #include <geos/index/SpatialIndex.h> // for inheritance
 #include <geos/index/quadtree/Root.h> // for composition
 
+#include <memory>
 #include <vector>
 #include <string>
 
@@ -33,9 +35,6 @@
 
 // Forward declarations
 namespace geos {
-	namespace geom {
-		class Envelope;
-	}
 	namespace index {
 		namespace quadtree {
 			// class Root;
@@ -73,7 +72,7 @@ class GEOS_DLL Quadtree: public SpatialIndex {
 
 private:
 
-	std::vector<geom::Envelope *> newEnvelopes;
+	std::vector<std::unique_ptr<geom::Envelope>> newEnvelopes;
 
 	void collectStats(const geom::Envelope& itemEnv);
 
@@ -113,7 +112,7 @@ public:
 		minExtent(1.0)
 	{}
 
-	~Quadtree() override;
+	~Quadtree() override = default;
 
 	/// Returns the number of levels in the tree.
 	int depth();
diff --git a/src/index/quadtree/Quadtree.cpp b/src/index/quadtree/Quadtree.cpp
index e8e02ef..e09623b 100644
--- a/src/index/quadtree/Quadtree.cpp
+++ b/src/index/quadtree/Quadtree.cpp
@@ -66,13 +66,6 @@ Quadtree::ensureExtent(const Envelope *itemEnv, double minExtent)
 }
 
 /*public*/
-Quadtree::~Quadtree()
-{
-	for (unsigned int i=0; i<newEnvelopes.size(); i++)
-		delete newEnvelopes[i];
-}
-
-/*public*/
 int
 Quadtree::depth()
 {
@@ -93,7 +86,7 @@ Quadtree::insert(const Envelope *itemEnv, void* item)
 	collectStats(*itemEnv);
 
 	Envelope *insertEnv=ensureExtent(itemEnv,minExtent);
-	if ( insertEnv != itemEnv ) newEnvelopes.push_back(insertEnv);
+	if ( insertEnv != itemEnv ) newEnvelopes.emplace_back(insertEnv);
 	root.insert(insertEnv,item);
 #if GEOS_DEBUG
 	cerr<<"Quadtree::insert("<<itemEnv->toString()<<", "<<item<<")"<<endl;

commit 42bd6eca3de1cf6d746eb04b644f42994f166f3c
Author: Daniel Baston <dbaston at gmail.com>
Date:   Sat Dec 22 20:04:45 2018 -0500

    Store LineSegmentIndex Quadtree as value, not pointer

diff --git a/include/geos/simplify/LineSegmentIndex.h b/include/geos/simplify/LineSegmentIndex.h
index 507232d..d4dce8d 100644
--- a/include/geos/simplify/LineSegmentIndex.h
+++ b/include/geos/simplify/LineSegmentIndex.h
@@ -51,7 +51,7 @@ class GEOS_DLL LineSegmentIndex {
 
 public:
 
-	LineSegmentIndex();
+	LineSegmentIndex() = default;
 
 	~LineSegmentIndex() = default;
 
@@ -62,11 +62,11 @@ public:
 	void remove(const geom::LineSegment* seg);
 
 	std::unique_ptr< std::vector<geom::LineSegment*> >
-			query(const geom::LineSegment* seg) const;
+			query(const geom::LineSegment* seg);
 
 private:
 
-	std::unique_ptr<index::quadtree::Quadtree> index;
+	index::quadtree::Quadtree index;
 
 	std::vector<std::unique_ptr<geom::Envelope>> newEnvelopes;
 
diff --git a/src/simplify/LineSegmentIndex.cpp b/src/simplify/LineSegmentIndex.cpp
index 71159db..04efda0 100644
--- a/src/simplify/LineSegmentIndex.cpp
+++ b/src/simplify/LineSegmentIndex.cpp
@@ -105,12 +105,6 @@ public:
 
 };
 
-/*public*/
-LineSegmentIndex::LineSegmentIndex()
-	:
-	index(new Quadtree())
-{
-}
 
 /*public*/
 void
@@ -129,7 +123,7 @@ LineSegmentIndex::add(const LineSegment* seg)
 
 	// We need a cast because index wants a non-const,
 	// although it won't change the argument
-	index->insert(env.get(), const_cast<LineSegment*>(seg));
+	index.insert(env.get(), const_cast<LineSegment*>(seg));
 
 	newEnvelopes.push_back(std::move(env));
 }
@@ -142,17 +136,17 @@ LineSegmentIndex::remove(const LineSegment* seg)
 
 	// We need a cast because index wants a non-const
 	// although it won't change the argument
-	index->remove(&env, const_cast<LineSegment*>(seg));
+	index.remove(&env, const_cast<LineSegment*>(seg));
 }
 
 /*public*/
 unique_ptr< vector<LineSegment*> >
-LineSegmentIndex::query(const LineSegment* querySeg) const
+LineSegmentIndex::query(const LineSegment* querySeg)
 {
 	Envelope env(querySeg->p0, querySeg->p1);
 
 	LineSegmentVisitor visitor(querySeg);
-	index->query(&env, visitor);
+	index.query(&env, visitor);
 
 	unique_ptr< vector<LineSegment*> > itemsFound = visitor.getItems();
 

commit 56acc15f0ac215bde0739017490a44963841ca22
Author: Daniel Baston <dbaston at gmail.com>
Date:   Sat Dec 22 20:01:40 2018 -0500

    Simplify for loop definition

diff --git a/src/simplify/LineSegmentIndex.cpp b/src/simplify/LineSegmentIndex.cpp
index b194d77..71159db 100644
--- a/src/simplify/LineSegmentIndex.cpp
+++ b/src/simplify/LineSegmentIndex.cpp
@@ -116,10 +116,7 @@ LineSegmentIndex::LineSegmentIndex()
 void
 LineSegmentIndex::add(const TaggedLineString& line)
 {
-	const vector<TaggedLineSegment*>& segs = line.getSegments();
-	for (size_t i=0, n=segs.size(); i<n; ++i)
-	{
-		const LineSegment* seg = segs[i];
+	for (const LineSegment* seg : line.getSegments()) {
 		add(seg);
 	}
 }

commit b5f78b41ff219ef1cd5ce594ca8043845c0e4bd0
Author: Daniel Baston <dbaston at gmail.com>
Date:   Sat Dec 22 20:00:22 2018 -0500

    Remove C-style casts

diff --git a/src/simplify/LineSegmentIndex.cpp b/src/simplify/LineSegmentIndex.cpp
index f2671b3..b194d77 100644
--- a/src/simplify/LineSegmentIndex.cpp
+++ b/src/simplify/LineSegmentIndex.cpp
@@ -132,7 +132,7 @@ LineSegmentIndex::add(const LineSegment* seg)
 
 	// We need a cast because index wants a non-const,
 	// although it won't change the argument
-	index->insert(env.get(), (LineSegment*)seg);
+	index->insert(env.get(), const_cast<LineSegment*>(seg));
 
 	newEnvelopes.push_back(std::move(env));
 }
@@ -145,7 +145,7 @@ LineSegmentIndex::remove(const LineSegment* seg)
 
 	// We need a cast because index wants a non-const
 	// although it won't change the argument
-	index->remove(&env, (LineSegment*)seg);
+	index->remove(&env, const_cast<LineSegment*>(seg));
 }
 
 /*public*/

commit e0f1224cfe172c71763f8d7ce138127532b06fb6
Author: Daniel Baston <dbaston at gmail.com>
Date:   Sat Dec 22 19:57:42 2018 -0500

    Use unique_ptr for managed Envelopes in LineSegmentIndex

diff --git a/include/geos/simplify/LineSegmentIndex.h b/include/geos/simplify/LineSegmentIndex.h
index fa6ed0e..507232d 100644
--- a/include/geos/simplify/LineSegmentIndex.h
+++ b/include/geos/simplify/LineSegmentIndex.h
@@ -24,6 +24,8 @@
 #define GEOS_SIMPLIFY_LINESEGMENTINDEX_H
 
 #include <geos/export.h>
+#include <geos/geom/Envelope.h>
+#include <geos/index/quadtree/Quadtree.h>
 #include <vector>
 #include <memory> // for unique_ptr
 
@@ -35,17 +37,11 @@
 // Forward declarations
 namespace geos {
 	namespace geom {
-		class Envelope;
 		class LineSegment;
 	}
 	namespace simplify {
 		class TaggedLineString;
 	}
-	namespace index {
-		namespace quadtree {
-			class Quadtree;
-		}
-	}
 }
 
 namespace geos {
@@ -57,7 +53,7 @@ public:
 
 	LineSegmentIndex();
 
-	~LineSegmentIndex();
+	~LineSegmentIndex() = default;
 
 	void add(const TaggedLineString& line);
 
@@ -72,7 +68,7 @@ private:
 
 	std::unique_ptr<index::quadtree::Quadtree> index;
 
-	std::vector<geom::Envelope*> newEnvelopes;
+	std::vector<std::unique_ptr<geom::Envelope>> newEnvelopes;
 
 	// Copying is turned off
 	LineSegmentIndex(const LineSegmentIndex&);
diff --git a/src/simplify/LineSegmentIndex.cpp b/src/simplify/LineSegmentIndex.cpp
index da6d23e..f2671b3 100644
--- a/src/simplify/LineSegmentIndex.cpp
+++ b/src/simplify/LineSegmentIndex.cpp
@@ -113,15 +113,6 @@ LineSegmentIndex::LineSegmentIndex()
 }
 
 /*public*/
-LineSegmentIndex::~LineSegmentIndex()
-{
-	for (size_t i=0, n=newEnvelopes.size(); i<n; ++i)
-	{
-		delete newEnvelopes[i];
-	}
-}
-
-/*public*/
 void
 LineSegmentIndex::add(const TaggedLineString& line)
 {
@@ -137,12 +128,13 @@ LineSegmentIndex::add(const TaggedLineString& line)
 void
 LineSegmentIndex::add(const LineSegment* seg)
 {
-	Envelope* env = new Envelope(seg->p0, seg->p1);
-	newEnvelopes.push_back(env);
+	std::unique_ptr<Envelope> env{new Envelope(seg->p0, seg->p1)};
 
 	// We need a cast because index wants a non-const,
 	// although it won't change the argument
-	index->insert(env, (LineSegment*)seg);
+	index->insert(env.get(), (LineSegment*)seg);
+
+	newEnvelopes.push_back(std::move(env));
 }
 
 /*public*/

commit af66a6d49b9def34f2392c788e8418de11a0e0c0
Author: Daniel Baston <dbaston at gmail.com>
Date:   Sat Dec 22 19:51:31 2018 -0500

    Simplify for loop syntax

diff --git a/src/simplify/TaggedLineStringSimplifier.cpp b/src/simplify/TaggedLineStringSimplifier.cpp
index 29320e9..b51cf4b 100644
--- a/src/simplify/TaggedLineStringSimplifier.cpp
+++ b/src/simplify/TaggedLineStringSimplifier.cpp
@@ -27,6 +27,7 @@
 //#include <geos/geom/GeometryFactory.h>
 //#include <geos/geom/CoordinateSequenceFactory.h>
 
+#include <algorithm>
 #include <cassert>
 #include <memory>
 
@@ -211,13 +212,8 @@ TaggedLineStringSimplifier::hasBadOutputIntersection(
 	unique_ptr< vector<LineSegment*> > querySegs =
 		outputIndex->query(&candidateSeg);
 
-	for (vector<LineSegment*>::iterator
-			it = querySegs->begin(), iEnd = querySegs->end();
-			it != iEnd;
-			++it)
+	for (const LineSegment* querySeg : *querySegs)
 	{
-		LineSegment* querySeg = *it;
-		assert(querySeg);
 		if (hasInteriorIntersection(*querySeg, candidateSeg))
 		{
 			return true;
@@ -247,15 +243,9 @@ TaggedLineStringSimplifier::hasBadInputIntersection(
 	unique_ptr< vector<LineSegment*> > querySegs =
 		inputIndex->query(&candidateSeg);
 
-	for (vector<LineSegment*>::iterator
-			it = querySegs->begin(), iEnd = querySegs->end();
-			it != iEnd;
-			++it)
+	for (const LineSegment* ls : *querySegs)
 	{
-		assert(*it);
-		assert(dynamic_cast<TaggedLineSegment*>(*it));
-		TaggedLineSegment* querySeg =
-			static_cast<TaggedLineSegment*>(*it);
+		const TaggedLineSegment* querySeg = static_cast<const TaggedLineSegment*>(ls);
 
 		if (hasInteriorIntersection(*querySeg, candidateSeg))
 		{

commit 8de4141a244fb0e853a365d08aea3794598aef18
Author: Daniel Baston <dbaston at gmail.com>
Date:   Sat Dec 22 19:49:20 2018 -0500

    Fix typos in comments

diff --git a/src/index/quadtree/NodeBase.cpp b/src/index/quadtree/NodeBase.cpp
index 5d2a841..d8191a0 100644
--- a/src/index/quadtree/NodeBase.cpp
+++ b/src/index/quadtree/NodeBase.cpp
@@ -99,7 +99,7 @@ vector<void*>&
 NodeBase::addAllItems(vector<void*>& resultItems) const
 {
 	// this node may have items as well as subnodes (since items may not
-	// be wholely contained in any single subnode
+	// be wholly contained in any single subnode
 	resultItems.insert(resultItems.end(), items.begin(), items.end());
 
 	for(int i=0; i<4; ++i)
@@ -120,7 +120,7 @@ NodeBase::addAllItemsFromOverlapping(const Envelope& searchEnv,
 		return;
 
 	// this node may have items as well as subnodes (since items may not
-	// be wholely contained in any single subnode
+	// be wholly contained in any single subnode
 	resultItems.insert(resultItems.end(), items.begin(), items.end());
 
 	for(int i=0; i<4; ++i)
@@ -202,7 +202,7 @@ NodeBase::visit(const Envelope* searchEnv, ItemVisitor& visitor)
 	if (! isSearchMatch(*searchEnv)) return;
 
 	// this node may have items as well as subnodes (since items may not
-	// be wholely contained in any single subnode
+	// be wholly contained in any single subnode
 	visitItems(searchEnv, visitor);
 
 	for (int i = 0; i < 4; i++) {
diff --git a/src/simplify/LineSegmentIndex.cpp b/src/simplify/LineSegmentIndex.cpp
index efffb6f..da6d23e 100644
--- a/src/simplify/LineSegmentIndex.cpp
+++ b/src/simplify/LineSegmentIndex.cpp
@@ -141,7 +141,7 @@ LineSegmentIndex::add(const LineSegment* seg)
 	newEnvelopes.push_back(env);
 
 	// We need a cast because index wants a non-const,
-	// altought it won't change the argument
+	// although it won't change the argument
 	index->insert(env, (LineSegment*)seg);
 }
 
@@ -152,7 +152,7 @@ LineSegmentIndex::remove(const LineSegment* seg)
 	Envelope env(seg->p0, seg->p1);
 
 	// We need a cast because index wants a non-const
-	// altought it won't change the argument
+	// although it won't change the argument
 	index->remove(&env, (LineSegment*)seg);
 }
 

commit 5f0919f1d25651ba3372bd34ec6d31e5ceb5cc14
Author: Sergey Fedoseev <fedoseev.sergey at gmail.com>
Date:   Tue Dec 18 23:21:08 2018 +0500

    Fix #947: Fix getCoordinate() of non-empty collection with empty first item.

diff --git a/src/geom/GeometryCollection.cpp b/src/geom/GeometryCollection.cpp
index 3ead8fa..738ace8 100644
--- a/src/geom/GeometryCollection.cpp
+++ b/src/geom/GeometryCollection.cpp
@@ -273,8 +273,13 @@ GeometryCollection::getCoordinate() const
 {
 	// should use unique_ptr here or return NULL or throw an exception !
 	// 	--strk;
-	if (isEmpty()) return new Coordinate();
-    	return (*geometries)[0]->getCoordinate();
+    for (size_t i = 0; i < geometries->size(); ++i)
+    {
+        if (!(*geometries)[i]->isEmpty()) {
+            return (*geometries)[i]->getCoordinate();
+        }
+    }
+    return new Coordinate();
 }
 
 /**
diff --git a/tests/unit/Makefile.am b/tests/unit/Makefile.am
index 2dcbd1c..f722757 100644
--- a/tests/unit/Makefile.am
+++ b/tests/unit/Makefile.am
@@ -67,6 +67,7 @@ geos_unit_SOURCES = \
 	geom/Geometry/equalsTest.cpp \
 	geom/Geometry/isRectangleTest.cpp \
 	geom/Geometry/normalize.cpp \
+	geom/GeometryCollectionTest.cpp \
 	geom/GeometryFactoryTest.cpp \
 	geom/IntersectionMatrixTest.cpp \
 	geom/LinearRingTest.cpp \
diff --git a/tests/unit/geom/GeometryCollectionTest.cpp b/tests/unit/geom/GeometryCollectionTest.cpp
new file mode 100644
index 0000000..89860f7
--- /dev/null
+++ b/tests/unit/geom/GeometryCollectionTest.cpp
@@ -0,0 +1,56 @@
+//
+// Test Suite for geos::geom::GeometryCollection class.
+
+#include <tut/tut.hpp>
+#include <utility.h>
+
+
+namespace tut {
+//
+// Test Group
+//
+
+// Common data used by tests
+struct test_geometry_collection_data {
+    typedef geos::geom::GeometryFactory GeometryFactory;
+
+    geos::geom::PrecisionModel pm_;
+    GeometryFactory::Ptr factory_;
+
+    test_geometry_collection_data()
+        : pm_(1000), factory_(GeometryFactory::create(&pm_, 0))
+    {
+    }
+};
+
+typedef test_group<test_geometry_collection_data> group;
+typedef group::object object;
+
+group test_geometry_collection_group("geos::geom::GeometryCollection");
+
+//
+// Test Cases
+//
+
+// Test of user's constructor to build empty Point
+template<>
+template<>
+void object::test<1>()
+{
+    GeometryPtr empty_point = factory_->createPoint();
+    ensure( empty_point != nullptr );
+
+    geos::geom::Coordinate coord(1, 2);
+    GeometryPtr point = factory_->createPoint(coord);
+    ensure( point != nullptr );
+
+    std::vector<GeometryPtr> geoms{empty_point, point};
+    GeometryColPtr col = factory_->createGeometryCollection(geoms);
+    ensure( col != nullptr );
+
+    ensure( col->getCoordinate() != nullptr );
+    ensure_equals( col->getCoordinate()->x, 1 );
+    ensure_equals( col->getCoordinate()->y, 2 );
+}
+
+} // namespace tut

-----------------------------------------------------------------------

Summary of changes:
 include/geos/index/quadtree/NodeBase.h             | 10 ++-
 include/geos/index/quadtree/Quadtree.h             |  9 +-
 include/geos/simplify/LineSegmentIndex.h           | 18 ++--
 include/geos/simplify/TaggedLineStringSimplifier.h |  6 +-
 src/geom/GeometryCollection.cpp                    |  9 +-
 src/index/quadtree/Node.cpp                        | 18 ++--
 src/index/quadtree/NodeBase.cpp                    | 96 +++++++++++-----------
 src/index/quadtree/Quadtree.cpp                    |  9 +-
 src/index/quadtree/Root.cpp                        | 10 +--
 src/simplify/LineSegmentIndex.cpp                  | 37 +++------
 src/simplify/TaggedLineStringSimplifier.cpp        | 41 +++------
 src/simplify/TopologyPreservingSimplifier.cpp      |  4 +-
 tests/unit/Makefile.am                             |  1 +
 tests/unit/geom/GeometryCollectionTest.cpp         | 56 +++++++++++++
 14 files changed, 168 insertions(+), 156 deletions(-)
 create mode 100644 tests/unit/geom/GeometryCollectionTest.cpp


hooks/post-receive
-- 
GEOS


More information about the geos-commits mailing list