[geos-commits] r4141 - in trunk: include/geos/geomgraph include/geos/geomgraph/index src/geomgraph src/geomgraph/index src/operation/valid

svn_geos at osgeo.org svn_geos at osgeo.org
Tue Jan 19 16:03:10 PST 2016


Author: pramsey
Date: 2016-01-19 16:03:10 -0800 (Tue, 19 Jan 2016)
New Revision: 4141

Modified:
   trunk/include/geos/geomgraph/GeometryGraph.h
   trunk/include/geos/geomgraph/index/SegmentIntersector.h
   trunk/include/geos/geomgraph/index/SimpleMCSweepLineIntersector.h
   trunk/src/geomgraph/GeometryGraph.cpp
   trunk/src/geomgraph/index/SegmentIntersector.cpp
   trunk/src/geomgraph/index/SimpleMCSweepLineIntersector.cpp
   trunk/src/operation/valid/ConsistentAreaTester.cpp
   trunk/src/operation/valid/IsValidOp.cpp
Log:
#757, fix memory exhaustion case in isvalid


Modified: trunk/include/geos/geomgraph/GeometryGraph.h
===================================================================
--- trunk/include/geos/geomgraph/GeometryGraph.h	2016-01-20 00:02:46 UTC (rev 4140)
+++ trunk/include/geos/geomgraph/GeometryGraph.h	2016-01-20 00:03:10 UTC (rev 4141)
@@ -219,12 +219,25 @@
 		return computeSelfNodes(*li, computeRingSelfNodes, env);
 	}
 
+	index::SegmentIntersector* computeSelfNodes(
+			algorithm::LineIntersector *li,
+			bool computeRingSelfNodes,
+			bool isDoneIfProperInt,
+			const geom::Envelope *env=0)
+	{
+		return computeSelfNodes(*li, computeRingSelfNodes, isDoneIfProperInt, env);
+	}
+
 	// Quick inline calling the function above, the above should probably
 	// be deprecated.
 	index::SegmentIntersector* computeSelfNodes(
 			algorithm::LineIntersector& li,
 			bool computeRingSelfNodes, const geom::Envelope *env=0);
 
+	index::SegmentIntersector* computeSelfNodes(
+			algorithm::LineIntersector& li,
+			bool computeRingSelfNodes, bool isDoneIfProperInt, const geom::Envelope *env=0);
+
 	index::SegmentIntersector* computeEdgeIntersections(GeometryGraph *g,
 		algorithm::LineIntersector *li, bool includeProper,
 		const geom::Envelope *env=0);

Modified: trunk/include/geos/geomgraph/index/SegmentIntersector.h
===================================================================
--- trunk/include/geos/geomgraph/index/SegmentIntersector.h	2016-01-20 00:02:46 UTC (rev 4140)
+++ trunk/include/geos/geomgraph/index/SegmentIntersector.h	2016-01-20 00:03:10 UTC (rev 4141)
@@ -56,6 +56,10 @@
 
 	bool hasProperInterior;
 
+	bool isDone;
+	
+	bool isDoneWhenProperInt;
+
 	// the proper intersection point found
 	geom::Coordinate properIntersectionPoint;
 
@@ -99,6 +103,8 @@
 		hasIntersectionVar(false),
 		hasProper(false),
 		hasProperInterior(false),
+		isDone(false),
+		isDoneWhenProperInt(false),
 		li(newLi),
 		includeProper(newIncludeProper),
 		recordIsolated(newRecordIsolated),
@@ -123,6 +129,10 @@
 
 	void addIntersections(Edge *e0, int segIndex0, Edge *e1, int segIndex1);
 
+	void setIsDoneIfProperInt(bool isDoneWhenProperInt);
+
+	bool getIsDone();
+	
 };
 
 } // namespace geos.geomgraph.index

Modified: trunk/include/geos/geomgraph/index/SimpleMCSweepLineIntersector.h
===================================================================
--- trunk/include/geos/geomgraph/index/SimpleMCSweepLineIntersector.h	2016-01-20 00:02:46 UTC (rev 4140)
+++ trunk/include/geos/geomgraph/index/SimpleMCSweepLineIntersector.h	2016-01-20 00:03:10 UTC (rev 4141)
@@ -20,6 +20,7 @@
 #include <vector>
 
 #include <geos/geomgraph/index/EdgeSetIntersector.h> // for inheritance
+#include <geos/geomgraph/index/SegmentIntersector.h>
 
 #ifdef _MSC_VER
 #pragma warning(push)
@@ -31,7 +32,7 @@
 	namespace geomgraph {
 		class Edge;
 		namespace index {
-			class SegmentIntersector;
+			// class SegmentIntersector;
 			class SweepLineEvent;
 		}
 	}

Modified: trunk/src/geomgraph/GeometryGraph.cpp
===================================================================
--- trunk/src/geomgraph/GeometryGraph.cpp	2016-01-20 00:02:46 UTC (rev 4140)
+++ trunk/src/geomgraph/GeometryGraph.cpp	2016-01-20 00:03:10 UTC (rev 4141)
@@ -363,31 +363,35 @@
 GeometryGraph::computeSelfNodes(LineIntersector &li,
   bool computeRingSelfNodes, const Envelope *env)
 {
-	SegmentIntersector *si=new SegmentIntersector(&li,true,false);
-    	auto_ptr<EdgeSetIntersector> esi(createEdgeSetIntersector());
+	return computeSelfNodes(li, computeRingSelfNodes, false, env);
+}
 
+SegmentIntersector*
+GeometryGraph::computeSelfNodes(LineIntersector &li,
+  bool computeRingSelfNodes, bool isDoneIfProperInt, const Envelope *env)
+{
+	SegmentIntersector *si = new SegmentIntersector(&li, true, false);
+	si->setIsDoneIfProperInt(isDoneIfProperInt);
+	auto_ptr<EdgeSetIntersector> esi(createEdgeSetIntersector());
+
 	typedef vector<Edge*> EC;
 	EC *se = edges;
 	EC self_edges_copy;
+
 	if ( env && ! env->covers(parentGeom->getEnvelopeInternal()) ) {
 		collect_intersecting_edges(env, se->begin(), se->end(), self_edges_copy);
     //cerr << "(computeSelfNodes) Self edges reduced from " << se->size() << " to " << self_edges_copy.size() << endl;
 		se = &self_edges_copy;
 	}
 
-	// optimized test for Polygons and Rings
-	if (! computeRingSelfNodes
-	    && ( dynamic_cast<const LinearRing*>(parentGeom)
+	bool isRings = dynamic_cast<const LinearRing*>(parentGeom)
 	    || dynamic_cast<const Polygon*>(parentGeom)
-	    || dynamic_cast<const MultiPolygon*>(parentGeom) ))
-	{
-		esi->computeIntersections(se, si, false);
-	}
-	else
-	{
-		esi->computeIntersections(se, si, true);
-	}
+	    || dynamic_cast<const MultiPolygon*>(parentGeom);
 
+	bool computeAllSegments = computeRingSelfNodes || ! isRings;
+	
+	esi->computeIntersections(se, si, computeAllSegments);
+
 #if GEOS_DEBUG
 	cerr << "SegmentIntersector # tests = " << si->numTests << endl;
 #endif // GEOS_DEBUG

Modified: trunk/src/geomgraph/index/SegmentIntersector.cpp
===================================================================
--- trunk/src/geomgraph/index/SegmentIntersector.cpp	2016-01-20 00:02:46 UTC (rev 4140)
+++ trunk/src/geomgraph/index/SegmentIntersector.cpp	2016-01-20 00:03:10 UTC (rev 4141)
@@ -73,6 +73,18 @@
 	return hasIntersectionVar;
 }
 
+void 
+SegmentIntersector::setIsDoneIfProperInt(bool idwpi) 
+{
+	isDoneWhenProperInt = idwpi;
+}
+
+bool 
+SegmentIntersector::getIsDone() 
+{
+	return isDone;
+}
+
 /*
  * A proper intersection is an intersection which is interior to at least two
  * line segments.  Note that a proper intersection is not necessarily
@@ -184,6 +196,10 @@
 				cerr<<"SegmentIntersector::addIntersections(): properIntersectionPoint: "<<properIntersectionPoint.toString()<<endl;
 #endif // DEBUG_INTERSECT
 				hasProper=true;
+				if (isDoneWhenProperInt) 
+				{
+					isDone = true;
+				}
 				if (!isBoundaryPoint(li,bdyNodes))
 					hasProperInterior=true;
 			}

Modified: trunk/src/geomgraph/index/SimpleMCSweepLineIntersector.cpp
===================================================================
--- trunk/src/geomgraph/index/SimpleMCSweepLineIntersector.cpp	2016-01-20 00:02:46 UTC (rev 4140)
+++ trunk/src/geomgraph/index/SimpleMCSweepLineIntersector.cpp	2016-01-20 00:03:10 UTC (rev 4141)
@@ -135,6 +135,10 @@
 		{
 			processOverlaps(i,ev->getDeleteEventIndex(),ev,si);
 		}
+		if (si->getIsDone()) 
+		{
+			break;
+		}	
 	}
 }
 

Modified: trunk/src/operation/valid/ConsistentAreaTester.cpp
===================================================================
--- trunk/src/operation/valid/ConsistentAreaTester.cpp	2016-01-20 00:02:46 UTC (rev 4140)
+++ trunk/src/operation/valid/ConsistentAreaTester.cpp	2016-01-20 00:03:10 UTC (rev 4141)
@@ -69,7 +69,10 @@
 	 * To fully check validity, it is necessary to
 	 * compute ALL intersections, including self-intersections within a single edge.
 	 */
-	auto_ptr<SegmentIntersector> intersector(geomGraph->computeSelfNodes(&li, true));
+	auto_ptr<SegmentIntersector> intersector(geomGraph->computeSelfNodes(&li, true, true));
+	/**
+	* A proper intersection means that the area is not consistent.
+	*/
 	if (intersector->hasProperIntersection()) {
 		invalidPoint=intersector->getProperIntersectionPoint();
 		return false;

Modified: trunk/src/operation/valid/IsValidOp.cpp
===================================================================
--- trunk/src/operation/valid/IsValidOp.cpp	2016-01-20 00:02:46 UTC (rev 4140)
+++ trunk/src/operation/valid/IsValidOp.cpp	2016-01-20 00:03:10 UTC (rev 4141)
@@ -189,7 +189,7 @@
 	if (validErr!=NULL) return;
 
 	LineIntersector li;
-	delete graph.computeSelfNodes(&li, true);
+	delete graph.computeSelfNodes(&li, true, true);
 	checkNoSelfIntersectingRings(&graph);
 }
 



More information about the geos-commits mailing list