[geos-commits] r3182 - in trunk: src/algorithm src/geom src/geom/prep src/geom/util src/io src/operation/overlay src/operation/union src/operation/valid tests/unit/geom tests/unit/operation/union

svn_geos at osgeo.org svn_geos at osgeo.org
Fri Feb 4 05:12:57 EST 2011


Author: strk
Date: 2011-02-04 02:12:57 -0800 (Fri, 04 Feb 2011)
New Revision: 3182

Modified:
   trunk/src/algorithm/MinimumDiameter.cpp
   trunk/src/geom/Geometry.cpp
   trunk/src/geom/Polygon.cpp
   trunk/src/geom/prep/AbstractPreparedPolygonContains.cpp
   trunk/src/geom/prep/PreparedPolygon.cpp
   trunk/src/geom/util/GeometryEditor.cpp
   trunk/src/io/WKTWriter.cpp
   trunk/src/operation/overlay/OverlayOp.cpp
   trunk/src/operation/union/CascadedPolygonUnion.cpp
   trunk/src/operation/valid/ConnectedInteriorTester.cpp
   trunk/src/operation/valid/IsValidOp.cpp
   trunk/tests/unit/geom/PolygonTest.cpp
   trunk/tests/unit/operation/union/CascadedPolygonUnionTest.cpp
Log:
Even more static casts drops

Modified: trunk/src/algorithm/MinimumDiameter.cpp
===================================================================
--- trunk/src/algorithm/MinimumDiameter.cpp	2011-02-04 08:50:42 UTC (rev 3181)
+++ trunk/src/algorithm/MinimumDiameter.cpp	2011-02-04 10:12:57 UTC (rev 3182)
@@ -179,9 +179,14 @@
 	//System.out.println("Input = " + geom);
 	CoordinateSequence* pts=NULL;
 	if (typeid(*geom)==typeid(Polygon))
-		pts=((Polygon*)geom)->getExteriorRing()->getCoordinates();
+	{
+		const Polygon* p = dynamic_cast<const Polygon*>(geom);
+		pts=p->getExteriorRing()->getCoordinates();
+	}
 	else
+	{
 		pts=geom->getCoordinates();
+	}
 
 	// special cases for lines or points or degenerate rings
 	switch(pts->getSize())

Modified: trunk/src/geom/Geometry.cpp
===================================================================
--- trunk/src/geom/Geometry.cpp	2011-02-04 08:50:42 UTC (rev 3181)
+++ trunk/src/geom/Geometry.cpp	2011-02-04 10:12:57 UTC (rev 3182)
@@ -354,10 +354,12 @@
 
 	// optimization for rectangle arguments
 	if (isRectangle()) {
-		return predicate::RectangleIntersects::intersects((Polygon&)*this, *g);
+		const Polygon* p = dynamic_cast<const Polygon*>(this);
+		return predicate::RectangleIntersects::intersects(*p, *g);
 	}
 	if (g->isRectangle()) {
-		return predicate::RectangleIntersects::intersects((const Polygon&)*g, *this);
+		const Polygon* p = dynamic_cast<const Polygon*>(g);
+		return predicate::RectangleIntersects::intersects(*p, *this);
 	}
 
 	IntersectionMatrix *im=relate(g);
@@ -419,7 +421,8 @@
 
 	// optimization for rectangle arguments
 	if (isRectangle()) {
-		return predicate::RectangleContains::contains((Polygon&)*this, *g);
+		const Polygon* p = dynamic_cast<const Polygon*>(this);
+		return predicate::RectangleContains::contains(*p, *g);
 	}
 	// Incorrect: contains is not commutative
 	//if (g->isRectangle()) {

Modified: trunk/src/geom/Polygon.cpp
===================================================================
--- trunk/src/geom/Polygon.cpp	2011-02-04 08:50:42 UTC (rev 3181)
+++ trunk/src/geom/Polygon.cpp	2011-02-04 10:12:57 UTC (rev 3182)
@@ -331,9 +331,10 @@
 }
 
 int
-Polygon::compareToSameClass(const Geometry *p) const
+Polygon::compareToSameClass(const Geometry *g) const
 {
-	return shell->compareToSameClass(((Polygon*)p)->shell);
+	const Polygon* p = dynamic_cast<const Polygon*>(g);
+	return shell->compareToSameClass(p->shell);
 }
 
 /*

Modified: trunk/src/geom/prep/AbstractPreparedPolygonContains.cpp
===================================================================
--- trunk/src/geom/prep/AbstractPreparedPolygonContains.cpp	2011-02-04 08:50:42 UTC (rev 3181)
+++ trunk/src/geom/prep/AbstractPreparedPolygonContains.cpp	2011-02-04 10:12:57 UTC (rev 3182)
@@ -70,11 +70,12 @@
 		return false;
     }
 	
-    const geom::Geometry* g = geom.getGeometryN(0);
-	const geom::Polygon* poly = static_cast<const Polygon*>(g);
+  const geom::Geometry* g = geom.getGeometryN(0);
+  const geom::Polygon* poly = dynamic_cast<const Polygon*>(g);
+  assert(poly);
 
-    std::size_t numHoles = poly->getNumInteriorRing();
-	return (0 == numHoles);
+  std::size_t numHoles = poly->getNumInteriorRing();
+  return (0 == numHoles);
 }
 	
 

Modified: trunk/src/geom/prep/PreparedPolygon.cpp
===================================================================
--- trunk/src/geom/prep/PreparedPolygon.cpp	2011-02-04 08:50:42 UTC (rev 3181)
+++ trunk/src/geom/prep/PreparedPolygon.cpp	2011-02-04 10:12:57 UTC (rev 3182)
@@ -92,7 +92,7 @@
     if ( isRectangle )
     {
         geom::Geometry const& geom = getGeometry();
-        geom::Polygon const& poly = static_cast<geom::Polygon const&>(geom);
+        geom::Polygon const& poly = dynamic_cast<geom::Polygon const&>(geom);
         
         return operation::predicate::RectangleContains::contains(poly, *g);
     }
@@ -138,7 +138,7 @@
     if ( isRectangle )
     {
         geom::Geometry const& geom = getGeometry();
-        geom::Polygon const& poly = static_cast<geom::Polygon const&>(geom);
+        geom::Polygon const& poly = dynamic_cast<geom::Polygon const&>(geom);
         
         return operation::predicate::RectangleIntersects::intersects(poly, *g);
     }

Modified: trunk/src/geom/util/GeometryEditor.cpp
===================================================================
--- trunk/src/geom/util/GeometryEditor.cpp	2011-02-04 08:50:42 UTC (rev 3181)
+++ trunk/src/geom/util/GeometryEditor.cpp	2011-02-04 10:12:57 UTC (rev 3182)
@@ -107,7 +107,9 @@
 Polygon*
 GeometryEditor::editPolygon(const Polygon *polygon,GeometryEditorOperation *operation)
 {
-	Polygon* newPolygon=(Polygon*) operation->edit(polygon, factory);
+	Polygon* newPolygon= dynamic_cast<Polygon*>(
+    operation->edit(polygon, factory)
+  );
 	if (newPolygon->isEmpty()) {
 		//RemoveSelectedPlugIn relies on this behaviour. [Jon Aquino]
 		return newPolygon;

Modified: trunk/src/io/WKTWriter.cpp
===================================================================
--- trunk/src/io/WKTWriter.cpp	2011-02-04 08:50:42 UTC (rev 3181)
+++ trunk/src/io/WKTWriter.cpp	2011-02-04 10:12:57 UTC (rev 3182)
@@ -534,7 +534,10 @@
 				level2=level+1;
 				doIndent=true;
 			}
-			appendPolygonText((Polygon *) multiPolygon->getGeometryN(i), level2, doIndent, writer);
+			const Polygon *p = dynamic_cast<const Polygon *>(
+			  multiPolygon->getGeometryN(i)
+			);
+			appendPolygonText(p, level2, doIndent, writer);
 		}
 		writer->write(")");
 	}

Modified: trunk/src/operation/overlay/OverlayOp.cpp
===================================================================
--- trunk/src/operation/overlay/OverlayOp.cpp	2011-02-04 08:50:42 UTC (rev 3181)
+++ trunk/src/operation/overlay/OverlayOp.cpp	2011-02-04 10:12:57 UTC (rev 3182)
@@ -459,7 +459,8 @@
 	// OverlayOp::getAverageZ(int) called with a ! polygon
 	assert(targetGeom->getGeometryTypeId() == GEOS_POLYGON);
 
-	avgz[targetIndex] = getAverageZ((const Polygon *)targetGeom);
+	const Polygon* p = dynamic_cast<const Polygon*>(targetGeom);
+	avgz[targetIndex] = getAverageZ(p);
 	avgzcomputed[targetIndex] = true;
 	return avgz[targetIndex];
 }
@@ -761,7 +762,8 @@
 	size_t gvsize=gv->size();
 	resultPolyList=new vector<Polygon*>(gvsize);
 	for(size_t i=0; i<gvsize; ++i) {
-		(*resultPolyList)[i]=(Polygon*)(*gv)[i];
+		Polygon* p = dynamic_cast<Polygon*>((*gv)[i]);
+		(*resultPolyList)[i]=p;
 	}
 	delete gv;
 

Modified: trunk/src/operation/union/CascadedPolygonUnion.cpp
===================================================================
--- trunk/src/operation/union/CascadedPolygonUnion.cpp	2011-02-04 08:50:42 UTC (rev 3181)
+++ trunk/src/operation/union/CascadedPolygonUnion.cpp	2011-02-04 10:12:57 UTC (rev 3182)
@@ -54,7 +54,7 @@
     typedef geom::MultiPolygon::const_iterator iterator;
     iterator end = multipoly->end();
     for (iterator i = multipoly->begin(); i != end; ++i)
-        polys.push_back(static_cast<geom::Polygon*>(*i));
+        polys.push_back(dynamic_cast<geom::Polygon*>(*i));
 
     CascadedPolygonUnion op (&polys);
     return op.Union();

Modified: trunk/src/operation/valid/ConnectedInteriorTester.cpp
===================================================================
--- trunk/src/operation/valid/ConnectedInteriorTester.cpp	2011-02-04 08:50:42 UTC (rev 3181)
+++ trunk/src/operation/valid/ConnectedInteriorTester.cpp	2011-02-04 10:12:57 UTC (rev 3182)
@@ -251,7 +251,7 @@
 	if (const MultiPolygon* mp=dynamic_cast<const MultiPolygon*>(g))
 	{
 		for (size_t i=0, n=mp->getNumGeometries(); i<n; i++) {
-			const Polygon *p=static_cast<const Polygon*>(mp->getGeometryN(i));
+			const Polygon *p=dynamic_cast<const Polygon*>(mp->getGeometryN(i));
 			visitInteriorRing(p->getExteriorRing(), graph);
 		}
 	}

Modified: trunk/src/operation/valid/IsValidOp.cpp
===================================================================
--- trunk/src/operation/valid/IsValidOp.cpp	2011-02-04 08:50:42 UTC (rev 3181)
+++ trunk/src/operation/valid/IsValidOp.cpp	2011-02-04 10:12:57 UTC (rev 3182)
@@ -233,7 +233,7 @@
 
 	for (unsigned int i=0; i<ngeoms; ++i)
 	{
-		const Polygon *p = (const Polygon *)g->getGeometryN(i);
+		const Polygon *p = dynamic_cast<const Polygon *>(g->getGeometryN(i));
 
 		checkInvalidCoordinates(p);
 		if (validErr != NULL) return;
@@ -473,22 +473,21 @@
 {
 	for(unsigned int i=0, ngeoms = mp->getNumGeometries(); i<ngeoms; ++i)
 	{
-		assert(dynamic_cast<const Polygon *>(mp->getGeometryN(i)));
-		const Polygon *p=static_cast<const Polygon *>(
+		const Polygon *p=dynamic_cast<const Polygon *>(
 				mp->getGeometryN(i));
+		assert(p);
 
-		assert(dynamic_cast<const LinearRing*>(p->getExteriorRing()));
-		const LinearRing *shell=static_cast<const LinearRing*>(
+		const LinearRing *shell=dynamic_cast<const LinearRing*>(
 				p->getExteriorRing());
+		assert(shell);
 
 		for(unsigned int j=0; j<ngeoms; ++j)
 		{
 			if (i==j) continue;
 
-			assert(dynamic_cast<const Polygon *>(
-					mp->getGeometryN(j)));
-			const Polygon *p2=static_cast<const Polygon *>(
+			const Polygon *p2 = dynamic_cast<const Polygon *>(
 					mp->getGeometryN(j));
+			assert(p2);
 
 			if (shell->isEmpty() || p2->isEmpty()) continue;
 

Modified: trunk/tests/unit/geom/PolygonTest.cpp
===================================================================
--- trunk/tests/unit/geom/PolygonTest.cpp	2011-02-04 08:50:42 UTC (rev 3181)
+++ trunk/tests/unit/geom/PolygonTest.cpp	2011-02-04 10:12:57 UTC (rev 3182)
@@ -50,7 +50,7 @@
 			// Create non-empty LinearRing
 			GeometryPtr geo = 0;
 			geo = reader_.read("POLYGON((0 10, 5 5, 10 5, 15 10, 10 15, 5 15, 0 10))");
-			poly_ = static_cast<PolygonPtr>(geo);
+			poly_ = dynamic_cast<PolygonPtr>(geo);
 		}
 
         ~test_polygon_data() 
@@ -432,7 +432,7 @@
 		ensure( geo != 0 );
 		ensure_equals( geo->getGeometryTypeId(), geos::geom::GEOS_POLYGON );
 		
-		PolygonPtr poly = static_cast<PolygonPtr>(geo);
+		PolygonPtr poly = dynamic_cast<PolygonPtr>(geo);
 		ensure( poly != 0 );
 		ensure_equals( poly->getNumInteriorRing(), holesNum );
 

Modified: trunk/tests/unit/operation/union/CascadedPolygonUnionTest.cpp
===================================================================
--- trunk/tests/unit/operation/union/CascadedPolygonUnionTest.cpp	2011-02-04 08:50:42 UTC (rev 3181)
+++ trunk/tests/unit/operation/union/CascadedPolygonUnionTest.cpp	2011-02-04 10:12:57 UTC (rev 3182)
@@ -114,7 +114,7 @@
         {
             std::string wkt(*p);
             geos::geom::Polygon* geom = 
-                static_cast<geos::geom::Polygon*>(wktreader.read(wkt));
+                dynamic_cast<geos::geom::Polygon*>(wktreader.read(wkt));
             g.push_back(geom);
         }
 
@@ -130,7 +130,7 @@
             for (int j = 0; j < num; ++j) {
                 std::auto_ptr<geos::geom::Point> pt(
                     gf.createPoint(geos::geom::Coordinate(i, j)));
-                g->push_back(static_cast<geos::geom::Polygon*>(pt->buffer(radius)));
+                g->push_back(dynamic_cast<geos::geom::Polygon*>(pt->buffer(radius)));
             }
         }
     }



More information about the geos-commits mailing list