[geos-commits] r3181 - in trunk: src/geom src/geom/util src/io src/operation/linemerge tests/unit/geom

svn_geos at osgeo.org svn_geos at osgeo.org
Fri Feb 4 03:50:42 EST 2011


Author: strk
Date: 2011-02-04 00:50:42 -0800 (Fri, 04 Feb 2011)
New Revision: 3181

Modified:
   trunk/src/geom/GeometryFactory.cpp
   trunk/src/geom/LineString.cpp
   trunk/src/geom/Polygon.cpp
   trunk/src/geom/util/GeometryEditor.cpp
   trunk/src/geom/util/GeometryTransformer.cpp
   trunk/src/io/WKTWriter.cpp
   trunk/src/operation/linemerge/LineSequencer.cpp
   trunk/tests/unit/geom/GeometryFactoryTest.cpp
   trunk/tests/unit/geom/LineStringTest.cpp
   trunk/tests/unit/geom/LinearRingTest.cpp
   trunk/tests/unit/geom/PolygonTest.cpp
Log:
Drop more static casts

Modified: trunk/src/geom/GeometryFactory.cpp
===================================================================
--- trunk/src/geom/GeometryFactory.cpp	2011-02-03 21:50:17 UTC (rev 3180)
+++ trunk/src/geom/GeometryFactory.cpp	2011-02-04 08:50:42 UTC (rev 3181)
@@ -520,7 +520,7 @@
 GeometryFactory::createPolygon(const LinearRing &shell, const vector<Geometry *> &holes)
 	const
 {
-	LinearRing *newRing = (LinearRing *)shell.clone();
+	LinearRing *newRing = dynamic_cast<LinearRing *>(shell.clone());
 	vector<Geometry *>*newHoles = new vector<Geometry *>(holes.size());
 	for (size_t i=0; i<holes.size(); i++)
 	{

Modified: trunk/src/geom/LineString.cpp
===================================================================
--- trunk/src/geom/LineString.cpp	2011-02-03 21:50:17 UTC (rev 3180)
+++ trunk/src/geom/LineString.cpp	2011-02-04 08:50:42 UTC (rev 3181)
@@ -347,8 +347,8 @@
 int
 LineString::compareToSameClass(const Geometry *ls) const
 {
-	assert(dynamic_cast<const LineString*>(ls));
-	const LineString *line=static_cast<const LineString*>(ls);
+	const LineString *line=dynamic_cast<const LineString*>(ls);
+	assert(line);
 	// MD - optimized implementation
 	int mynpts=points->getSize();
 	int othnpts=line->points->getSize();

Modified: trunk/src/geom/Polygon.cpp
===================================================================
--- trunk/src/geom/Polygon.cpp	2011-02-03 21:50:17 UTC (rev 3180)
+++ trunk/src/geom/Polygon.cpp	2011-02-04 08:50:42 UTC (rev 3181)
@@ -60,7 +60,11 @@
 	holes=new vector<Geometry *>(nholes);
 	for(size_t i=0; i<nholes; ++i)
 	{
-		LinearRing *h=new LinearRing(* (LinearRing*)(*p.holes)[i]);
+    // TODO: holes is a vector of Geometry, anyway
+    //       so there's no point in casting here,
+    //       just use ->clone instead !
+		const LinearRing* lr = dynamic_cast<const LinearRing *>((*p.holes)[i]);
+		LinearRing *h=new LinearRing(*lr);
 		(*holes)[i]=h;
 	}
 }
@@ -117,7 +121,8 @@
 	size_t nholes=holes->size();
 	for (size_t i=0; i<nholes; ++i)
 	{
-		const CoordinateSequence* childCoords=((LinearRing *)(*holes)[i])->getCoordinatesRO();
+		const LinearRing* lr = dynamic_cast<const LinearRing *>((*holes)[i]);
+		const CoordinateSequence* childCoords = lr->getCoordinatesRO();
 		childCoords->toVector(*cl);
 	}
 
@@ -130,7 +135,8 @@
 	size_t numPoints = shell->getNumPoints();
 	for(size_t i=0, n=holes->size(); i<n; ++i)
 	{
-		numPoints += ((LinearRing *)(*holes)[i])->getNumPoints();
+		const LinearRing* lr = dynamic_cast<const LinearRing *>((*holes)[i]);
+		numPoints += lr->getNumPoints();
 	}
 	return numPoints;
 }
@@ -191,7 +197,8 @@
 const LineString*
 Polygon::getInteriorRingN(size_t n) const
 {
-	return (LineString *) (*holes)[n];
+  const LinearRing* lr = dynamic_cast<const LinearRing *>((*holes)[n]);
+	return lr;
 }
 
 string
@@ -224,14 +231,11 @@
 
 	vector<Geometry *> *rings = new vector<Geometry *>(holes->size()+1);
 
-	//(*rings)[0]=shell->clone(); // new LineString(*shell);
 	(*rings)[0] = gf->createLineString(*shell).release();
 	for(size_t i=0, n=holes->size(); i<n; ++i)
 	{
-		//(*rings)[i + 1] = new LineString((const LineString &)*(*holes)[i]);
-		assert( dynamic_cast<LineString *>( (*holes)[i] ) );
-		LineString* hole = static_cast<LineString *>( (*holes)[i] );
-		assert(hole);
+		const LinearRing* hole = dynamic_cast<const LinearRing *>((*holes)[i]);
+		assert( hole );
 		LineString* ls = gf->createLineString( *hole ).release();
 		(*rings)[i + 1] = ls;
 	}
@@ -280,7 +284,8 @@
 	shell->apply_ro(filter);
 	for(size_t i=0, n=holes->size(); i<n; ++i)
 	{
-		((LinearRing *)(*holes)[i])->apply_ro(filter);
+		const LinearRing* lr = dynamic_cast<const LinearRing *>((*holes)[i]);
+		lr->apply_ro(filter);
 	}
 }
 
@@ -290,7 +295,8 @@
 	shell->apply_rw(filter);
 	for(size_t i=0, n=holes->size(); i<n; ++i)
 	{
-		((LinearRing *)(*holes)[i])->apply_rw(filter);
+		LinearRing* lr = dynamic_cast<LinearRing *>((*holes)[i]);
+		lr->apply_rw(filter);
 	}
 }
 
@@ -318,7 +324,8 @@
 	normalize(shell, true);
 	for(size_t i=0, n=holes->size(); i<n; ++i)
 	{
-		normalize((LinearRing *)(*holes)[i], false);
+		LinearRing* lr = dynamic_cast<LinearRing *>((*holes)[i]);
+		normalize(lr, false);
 	}
 	sort(holes->begin(), holes->end(), GeometryGreaterThen());
 }
@@ -369,7 +376,7 @@
 	area+=fabs(algorithm::CGAlgorithms::signedArea(shell->getCoordinatesRO()));
 	for(size_t i=0, n=holes->size(); i<n; ++i)
 	{
-		LinearRing *lr = static_cast<LinearRing *>((*holes)[i]);
+		const LinearRing *lr = dynamic_cast<const LinearRing *>((*holes)[i]);
 		const CoordinateSequence *h=lr->getCoordinatesRO();
         	area-=fabs(algorithm::CGAlgorithms::signedArea(h));
 	}

Modified: trunk/src/geom/util/GeometryEditor.cpp
===================================================================
--- trunk/src/geom/util/GeometryEditor.cpp	2011-02-03 21:50:17 UTC (rev 3180)
+++ trunk/src/geom/util/GeometryEditor.cpp	2011-02-04 08:50:42 UTC (rev 3181)
@@ -115,7 +115,7 @@
 
 	Geometry* editResult = edit(newPolygon->getExteriorRing(),operation);
 
-	LinearRing* shell = static_cast<LinearRing*>(editResult);
+	LinearRing* shell = dynamic_cast<LinearRing*>(editResult);
 	if (shell->isEmpty()) {
 		//RemoveSelectedPlugIn relies on this behaviour. [Jon Aquino]
 		delete shell;
@@ -130,8 +130,8 @@
 		Geometry *hole_geom = edit(newPolygon->getInteriorRingN(i),
 			operation);
 
-		assert(dynamic_cast<LinearRing*>(hole_geom));
-		LinearRing *hole = static_cast<LinearRing*>(hole_geom);
+		LinearRing *hole = dynamic_cast<LinearRing*>(hole_geom);
+		assert(hole);
 
 		if (hole->isEmpty())
 		{

Modified: trunk/src/geom/util/GeometryTransformer.cpp
===================================================================
--- trunk/src/geom/util/GeometryTransformer.cpp	2011-02-03 21:50:17 UTC (rev 3180)
+++ trunk/src/geom/util/GeometryTransformer.cpp	2011-02-04 08:50:42 UTC (rev 3181)
@@ -228,9 +228,9 @@
 
 	for (unsigned int i=0, n=geom->getNumGeometries(); i<n; i++)
 	{
-		assert(dynamic_cast<const LineString*>(geom->getGeometryN(i)));
-		const LineString* l = static_cast<const LineString*>(
+		const LineString* l = dynamic_cast<const LineString*>(
 				geom->getGeometryN(i));
+		assert(l);
 
 		Geometry::AutoPtr transformGeom = transformLineString(l, geom);
 		if ( transformGeom.get() == NULL ) continue;
@@ -257,9 +257,9 @@
 
 	bool isAllValidLinearRings = true;
 
-	assert(dynamic_cast<const LinearRing*>(geom->getExteriorRing()));
-	const LinearRing* lr = static_cast<const LinearRing*>(
+	const LinearRing* lr = dynamic_cast<const LinearRing*>(
 			geom->getExteriorRing());
+	assert(lr);
 
 	Geometry::AutoPtr shell = transformLinearRing(lr, geom);
 	if ( shell.get() == NULL
@@ -272,10 +272,9 @@
 	vector<Geometry*>* holes = new vector<Geometry*>();
 	for (unsigned int i=0, n=geom->getNumInteriorRing(); i<n; i++)
 	{
-		assert(dynamic_cast<const LinearRing*>(
-			geom->getInteriorRingN(i)));
-		const LinearRing* lr = static_cast<const LinearRing*>(
+		const LinearRing* lr = dynamic_cast<const LinearRing*>(
 			geom->getInteriorRingN(i));
+		assert(lr);
 
 		Geometry::AutoPtr hole(transformLinearRing(lr, geom));
 
@@ -294,10 +293,9 @@
 	if ( isAllValidLinearRings)
 	{
 		Geometry* sh = shell.release();
-		assert(dynamic_cast<LinearRing*>(sh));
-		return Geometry::AutoPtr(factory->createPolygon(
-			static_cast<LinearRing*>(sh),
-			holes));
+		LinearRing* lr = dynamic_cast<LinearRing*>(sh);
+    assert(lr);
+		return Geometry::AutoPtr(factory->createPolygon(lr, holes));
 	}
 	else
 	{
@@ -332,9 +330,9 @@
 
 	for (unsigned int i=0, n=geom->getNumGeometries(); i<n; i++)
 	{
-		assert(dynamic_cast<const Polygon*>(geom->getGeometryN(i)));
-		const Polygon* p = static_cast<const Polygon*>(
+		const Polygon* p = dynamic_cast<const Polygon*>(
 				geom->getGeometryN(i));
+		assert(p);
 
 		Geometry::AutoPtr transformGeom = transformPolygon(p, geom);
 		if ( transformGeom.get() == NULL ) continue;

Modified: trunk/src/io/WKTWriter.cpp
===================================================================
--- trunk/src/io/WKTWriter.cpp	2011-02-03 21:50:17 UTC (rev 3180)
+++ trunk/src/io/WKTWriter.cpp	2011-02-04 08:50:42 UTC (rev 3181)
@@ -510,7 +510,10 @@
 				level2=level+1;
 				doIndent=true;
 			}
-			appendLineStringText((LineString *) multiLineString->getGeometryN(i), level2, doIndent, writer);
+			const LineString* ls = dynamic_cast<const LineString *>(
+			  multiLineString->getGeometryN(i)
+			);
+			appendLineStringText(ls, level2, doIndent, writer);
 		}
 		writer->write(")");
 	}

Modified: trunk/src/operation/linemerge/LineSequencer.cpp
===================================================================
--- trunk/src/operation/linemerge/LineSequencer.cpp	2011-02-03 21:50:17 UTC (rev 3180)
+++ trunk/src/operation/linemerge/LineSequencer.cpp	2011-02-04 08:50:42 UTC (rev 3181)
@@ -67,10 +67,11 @@
 
 	for (unsigned int i=0, n=mls->getNumGeometries(); i<n; ++i)
 	{
-		assert(dynamic_cast<const LineString*>(mls->getGeometryN(i)));
+		const LineString* lineptr = \
+			dynamic_cast<const LineString*>(mls->getGeometryN(i));
+		assert(lineptr);
+		const LineString& line = *lineptr;
 
-		const LineString& line = \
-			static_cast<const LineString&>(*(mls->getGeometryN(i)));
 
 		const Coordinate* startNode = &(line.getCoordinateN(0));
 		const Coordinate* endNode = &(line.getCoordinateN(line.getNumPoints() - 1));
@@ -208,8 +209,8 @@
 				lineToAdd = reverse(line);
 			} else {
 				Geometry* lineClone = line->clone();
-				assert(dynamic_cast<LineString *>(lineClone));
-				lineToAdd = static_cast<LineString *>(lineClone); 
+				lineToAdd = dynamic_cast<LineString *>(lineClone); 
+				assert(lineToAdd);
 			}
 
 			lines->push_back(lineToAdd);

Modified: trunk/tests/unit/geom/GeometryFactoryTest.cpp
===================================================================
--- trunk/tests/unit/geom/GeometryFactoryTest.cpp	2011-02-03 21:50:17 UTC (rev 3180)
+++ trunk/tests/unit/geom/GeometryFactoryTest.cpp	2011-02-04 08:50:42 UTC (rev 3181)
@@ -760,7 +760,8 @@
 		GeometryPtr geo = reader_.read(("LINEARRING(7 7, 12 7, 12 12, 7 12, 7 7)"));
 		ensure( geo != 0 );
 
-		LinearRingPtr hole = static_cast<LinearRingPtr>(geo);
+		LinearRingPtr hole = dynamic_cast<LinearRingPtr>(geo);
+		ensure( hole );
 		ensure( hole->isRing() );
 		ensure_equals( hole->getNumPoints(), interiorSize );
 

Modified: trunk/tests/unit/geom/LineStringTest.cpp
===================================================================
--- trunk/tests/unit/geom/LineStringTest.cpp	2011-02-03 21:50:17 UTC (rev 3180)
+++ trunk/tests/unit/geom/LineStringTest.cpp	2011-02-04 08:50:42 UTC (rev 3181)
@@ -343,7 +343,7 @@
 		GeometryPtr geo = reader_.read("LINESTRING (0 0, 5 5, 10 5, 10 10)");
 		ensure( geo != 0 );
 
-		LineStringPtr line = static_cast<LineStringPtr>(geo);
+		LineStringPtr line = dynamic_cast<LineStringPtr>(geo);
 		ensure(line != 0);
 		
 		GeometryPtr envelope = line->getEnvelope();	
@@ -365,7 +365,7 @@
 		GeometryPtr geo = reader_.read("LINESTRING (0 0, 5 5, 10 5, 10 10)");
 		ensure( geo != 0 );
 
-		LineStringPtr line = static_cast<LineStringPtr>(geo);
+		LineStringPtr line = dynamic_cast<LineStringPtr>(geo);
 		ensure(line != 0);
 		
 		GeometryPtr boundary = line->getBoundary();	
@@ -387,7 +387,7 @@
 		GeometryPtr geo = reader_.read("LINESTRING (0 0, 5 5, 10 5, 10 10)");
 		ensure( geo != 0 );
 
-		LineStringPtr line = static_cast<LineStringPtr>(geo);
+		LineStringPtr line = dynamic_cast<LineStringPtr>(geo);
 		ensure(line != 0);
 		
 		GeometryPtr hull = line->convexHull();	

Modified: trunk/tests/unit/geom/LinearRingTest.cpp
===================================================================
--- trunk/tests/unit/geom/LinearRingTest.cpp	2011-02-03 21:50:17 UTC (rev 3180)
+++ trunk/tests/unit/geom/LinearRingTest.cpp	2011-02-04 08:50:42 UTC (rev 3181)
@@ -56,7 +56,7 @@
 			// Create non-empty LinearRing
 			GeometryPtr geo = 0;
 			geo = reader_.read("LINEARRING(0 10, 5 5, 10 5, 15 10, 10 15, 5 15, 0 10)");
-			ring_ = static_cast<LinearRingPtr>(geo);
+			ring_ = dynamic_cast<LinearRingPtr>(geo);
 		}
 
 		~test_linearring_data()
@@ -411,7 +411,7 @@
 			GeometryPtr geo = reader_.read("LINEARRING(0 0, 5 5, 10 10, 15 5, 5 5, 0 10)");
 			ensure(geo != 0);
 
-			LinearRingPtr ring = static_cast<LinearRingPtr>(geo);
+			LinearRingPtr ring = dynamic_cast<LinearRingPtr>(geo);
 			ensure(ring != 0);
 
 			ensure( !ring->isValid() );

Modified: trunk/tests/unit/geom/PolygonTest.cpp
===================================================================
--- trunk/tests/unit/geom/PolygonTest.cpp	2011-02-03 21:50:17 UTC (rev 3180)
+++ trunk/tests/unit/geom/PolygonTest.cpp	2011-02-04 08:50:42 UTC (rev 3181)
@@ -107,7 +107,7 @@
 
 			// Exterior (clone is required here because Polygon takes ownership)
 			GeometryPtr geo = ring.clone();
-			LinearRingPtr exterior = static_cast<LinearRingPtr>(geo);
+			LinearRingPtr exterior = dynamic_cast<LinearRingPtr>(geo);
 			
 			// Create non-empty Polygon
 			//geos::geom::Polygon poly(exterior, 0, &factory_);



More information about the geos-commits mailing list