[geos-commits] [SCM] GEOS branch master updated. 81ff4c0359100dcdb8c89109e65f0c265b451ca6

git at osgeo.org git at osgeo.org
Mon Nov 19 17:51:03 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  81ff4c0359100dcdb8c89109e65f0c265b451ca6 (commit)
       via  9b5462970c21c26df93aea83cb0181675b9663cd (commit)
      from  7dd3d0b243b30c69e4ac425bb76fa9dd731389e0 (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 81ff4c0359100dcdb8c89109e65f0c265b451ca6
Author: Raul Marin <rmrodriguez at cartodb.com>
Date:   Fri Sep 28 19:48:31 2018 +0200

    GeometryFactory: Refactor buildGeometry to use int ids

diff --git a/src/geom/GeometryFactory.cpp b/src/geom/GeometryFactory.cpp
index 2832ae8..3d88631 100644
--- a/src/geom/GeometryFactory.cpp
+++ b/src/geom/GeometryFactory.cpp
@@ -653,55 +653,46 @@ GeometryFactory::createLineString(const CoordinateSequence &fromCoords)
 Geometry*
 GeometryFactory::buildGeometry(vector<Geometry *> *newGeoms) const
 {
-	string geomClass;
+	if (!newGeoms->size())
+	{
+		// we do not need the vector anymore
+		delete newGeoms;
+		return createGeometryCollection();
+	}
+
 	bool isHeterogeneous=false;
 	bool hasGeometryCollection=false;
+	GeometryTypeId type = (*newGeoms)[0]->getGeometryTypeId();
 
-	for (size_t i=0, n=newGeoms->size(); i<n; ++i)
+	for (Geometry* gp : *newGeoms)
 	{
-		Geometry* geom = (*newGeoms)[i];
-		string partClass(typeid(*geom).name());
-		if (geomClass.empty())
-		{
-			geomClass=partClass;
-		}
-		else if (geomClass!=partClass)
+		GeometryTypeId geometryType = gp->getGeometryTypeId();
+		if (type != geometryType)
 		{
-			isHeterogeneous = true;
+			isHeterogeneous=true;
 		}
-		if ( dynamic_cast<GeometryCollection*>(geom) )
+		if (geometryType == GEOS_GEOMETRYCOLLECTION)
 		{
 			hasGeometryCollection=true;
 		}
 	}
 
-	// for the empty geometry, return an empty GeometryCollection
-	if (geomClass.empty())
-	{
-		// we do not need the vector anymore
-		delete newGeoms;
-		return createGeometryCollection();
-	}
 	if (isHeterogeneous || hasGeometryCollection)
 	{
 		return createGeometryCollection(newGeoms);
 	}
 
 	// At this point we know the collection is not hetereogenous.
-	// Determine the type of the result from the first Geometry in the
-	// list. This should always return a geometry, since otherwise
-	// an empty collection would have already been returned
-	Geometry *geom0=(*newGeoms)[0];
 	bool isCollection=newGeoms->size()>1;
 	if (isCollection)
 	{
-		if (typeid(*geom0)==typeid(Polygon)) {
+		if (type == GEOS_POLYGON) {
 			return createMultiPolygon(newGeoms);
-		} else if (typeid(*geom0)==typeid(LineString)) {
+		} else if (type == GEOS_LINESTRING) {
 			return createMultiLineString(newGeoms);
-		} else if (typeid(*geom0)==typeid(LinearRing)) {
+		} else if (type == GEOS_LINEARRING) {
 			return createMultiLineString(newGeoms);
-		} else if (typeid(*geom0)==typeid(Point)) {
+		} else if (type == GEOS_POINT) {
 			return createMultiPoint(newGeoms);
 		} else {
 			return createGeometryCollection(newGeoms);
@@ -709,6 +700,7 @@ GeometryFactory::buildGeometry(vector<Geometry *> *newGeoms) const
 	}
 
 	// since this is not a collection we can delete vector
+        Geometry *geom0=(*newGeoms)[0];
 	delete newGeoms;
 	return geom0;
 }
@@ -717,48 +709,44 @@ GeometryFactory::buildGeometry(vector<Geometry *> *newGeoms) const
 Geometry*
 GeometryFactory::buildGeometry(const vector<Geometry *> &fromGeoms) const
 {
-	string geomClass;
+	size_t geomsSize = fromGeoms.size();
+	if (geomsSize == 0)
+	{
+		return createGeometryCollection();
+	}
+
+	if (geomsSize == 1)
+	{
+		return fromGeoms[0]->clone();
+	}
+
 	bool isHeterogeneous=false;
-	bool isCollection=fromGeoms.size()>1;
-	size_t i;
-
-	for (i=0; i<fromGeoms.size(); i++) {
-		Geometry *geom = fromGeoms[i];
-		string partClass(typeid(*geom).name());
-		if (geomClass.empty()) {
-			geomClass=partClass;
-		} else if (geomClass!=partClass) {
-			isHeterogeneous = true;
+	GeometryTypeId type = fromGeoms[0]->getGeometryTypeId();
+
+	for (const Geometry *gp : fromGeoms)
+	{
+		GeometryTypeId geometryType = gp->getGeometryTypeId();
+		if (type != geometryType)
+		{
+			isHeterogeneous=true;
 		}
 	}
 
-	// for the empty geometry, return an empty GeometryCollection
-	if (geomClass.empty()) {
-		return createGeometryCollection();
-	}
-	if (isHeterogeneous) {
+	if (isHeterogeneous)
+	{
 		return createGeometryCollection(fromGeoms);
 	}
 
-	// At this point we know the collection is not hetereogenous.
-	// Determine the type of the result from the first Geometry in the
-	// list. This should always return a geometry, since otherwise
-	// an empty collection would have already been returned
-	Geometry *geom0=fromGeoms[0];
-	if (isCollection) {
-		if (typeid(*geom0)==typeid(Polygon)) {
-			return createMultiPolygon(fromGeoms);
-		} else if (typeid(*geom0)==typeid(LineString)) {
-			return createMultiLineString(fromGeoms);
-		} else if (typeid(*geom0)==typeid(LinearRing)) {
-			return createMultiLineString(fromGeoms);
-		} else if (typeid(*geom0)==typeid(Point)) {
-			return createMultiPoint(fromGeoms);
-		}
-		assert(0); // buildGeomtry encountered an unkwnon geometry type
+	if (type == GEOS_POLYGON) {
+		return createMultiPolygon(fromGeoms);
+	} else if (type == GEOS_LINESTRING) {
+		return createMultiLineString(fromGeoms);
+	} else if (type == GEOS_LINEARRING) {
+		return createMultiLineString(fromGeoms);
+	} else if (type == GEOS_POINT) {
+		return createMultiPoint(fromGeoms);
 	}
-
-	return geom0->clone();
+	assert(0); // buildGeomtry encountered an unkwnon geometry type
 }
 
 /*public*/

commit 9b5462970c21c26df93aea83cb0181675b9663cd
Author: Raul Marin <rmrodriguez at cartodb.com>
Date:   Thu Sep 27 17:05:02 2018 +0200

    Address memory warnings in buildGeometry
    
    Suite: buildarea
      Test: buildarea1 ...Uninitialized bytes in __interceptor_memcmp at offset 0 inside [0x7fffae24fa80, 4)
    ==19345==WARNING: MemorySanitizer: use-of-uninitialized-value
        #0 0x7f5ed6768c5f in std::char_traits<char>::compare(char const*, char const*, unsigned long) /build/gcc/src/gcc-build/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/char_traits.h:310:25
        #1 0x7f5ed6768c5f in std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::compare(char const*) const /build/gcc/src/gcc-build/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/basic_string.tcc:1424:37
        #2 0x7f5ed6892f40 in bool std::operator==<char, std::char_traits<char>, std::allocator<char> >(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, char const*) /usr/include/c++/8.2.1/bits/basic_string.h:6075:35
        #3 0x7f5ed6892f40 in geos::geom::GeometryFactory::buildGeometry(std::vector<geos::geom::Geometry*, std::allocator<geos::geom::Geometry*> >*) const /usr/src/debug/geos/src/geom/GeometryFactory.cpp:664:16
        #4 0x7f5ed690dd48 in geos::operation::overlay::OverlayOp::computeOverlay(geos::operation::overlay::OverlayOp::OpCode) /usr/src/debug/geos/src/operation/overlay/OverlayOp.cpp:839:28
        #5 0x7f5ed690dee1 in geos::operation::overlay::OverlayOp::getResultGeometry(geos::operation::overlay::OverlayOp::OpCode) /usr/src/debug/geos/src/operation/overlay/OverlayOp.cpp:187:16
        #6 0x7f5ed690e281 in geos::operation::overlay::OverlayOp::overlayOp(geos::geom::Geometry const*, geos::geom::Geometry const*, geos::operation::overlay::OverlayOp::OpCode) /usr/src/debug/geos/src/operation/overlay/OverlayOp.cpp:93:30
        #7 0x7f5ed688d11f in geos::operation::overlay::overlayOp::operator()(geos::geom::Geometry const*, geos::geom::Geometry const*) /usr/src/debug/geos/src/geom/../../include/geos/operation/overlay/OverlayOp.h:388:44
        #8 0x7f5ed688d11f in std::unique_ptr<geos::geom::Geometry, std::default_delete<geos::geom::Geometry> > geos::geom::BinaryOp<geos::operation::overlay::overlayOp>(geos::geom::Geometry const*, geos::geom::Geometry const*, geos::operation::overlay::overlayOp) /usr/src/debug/geos/src/geom/../../include/geos/geom/BinaryOp.h:357:3
        #9 0x7f5ed688b16f in geos::geom::Geometry::Union(geos::geom::Geometry const*) const /usr/src/debug/geos/src/geom/Geometry.cpp:586:17
        #10 0x7f5ed691885d in geos::operation::geounion::CascadedPolygonUnion::unionActual(geos::geom::Geometry*, geos::geom::Geometry*) /usr/src/debug/geos/src/operation/union/CascadedPolygonUnion.cpp:370:36
        #11 0x7f5ed6919080 in geos::operation::geounion::CascadedPolygonUnion::unionOptimized(geos::geom::Geometry*, geos::geom::Geometry*) /usr/src/debug/geos/src/operation/union/CascadedPolygonUnion.cpp:236:27
        #12 0x7f5ed6919252 in geos::operation::geounion::CascadedPolygonUnion::unionTree(geos::index::strtree::ItemsList*) /usr/src/debug/geos/src/operation/union/CascadedPolygonUnion.cpp:162:23
        #13 0x7f5ed6919630 in geos::operation::geounion::CascadedPolygonUnion::Union() /usr/src/debug/geos/src/operation/union/CascadedPolygonUnion.cpp:151:21
        #14 0x7f5ed691983d in geos::operation::geounion::CascadedPolygonUnion::Union(geos::geom::MultiPolygon const*) /usr/src/debug/geos/src/operation/union/CascadedPolygonUnion.cpp:124:20
        #15 0x7f5ed71db6a8 in GEOSUnionCascaded_r /usr/src/debug/geos/capi/geos_ts_c.cpp:2497:43
        #16 0x7f5ed7332ed6 in LWGEOM_GEOS_buildArea /home/raul/dev/public/postgis/liblwgeom/lwgeom_geos.c:1124:8
        #17 0x7f5ed7333164 in lwgeom_buildarea /home/raul/dev/public/postgis/liblwgeom/lwgeom_geos.c:1155:7
        #18 0x55b755e00bfa in buildarea1 /un/dev_public/postgis/liblwgeom/cunit/cu_buildarea.c:66:9
        #19 0x7f5ed6fb1117  (/usr/lib/libcunit.so.1+0x4117)
        #20 0x7f5ed6fb13b1  (/usr/lib/libcunit.so.1+0x43b1)
        #21 0x7f5ed6fb17b6 in CU_run_all_tests (/usr/lib/libcunit.so.1+0x47b6)
        #22 0x55b755e7f6b7 in main /un/dev_public/postgis/liblwgeom/cunit/cu_tester.c:177:13
        #23 0x7f5ed6c3c222 in __libc_start_main (/usr/lib/libc.so.6+0x24222)
        #24 0x55b755d7f0bd in _start (/un/dev_public/postgis/liblwgeom/cunit/.libs/lt-cu_tester+0x250bd)
    
    SUMMARY: MemorySanitizer: use-of-uninitialized-value /build/gcc/src/gcc-build/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/char_traits.h:310:25 in std::char_traits<char>::compare(char const*, char const*, unsigned long)

diff --git a/src/geom/GeometryFactory.cpp b/src/geom/GeometryFactory.cpp
index 896b457..2832ae8 100644
--- a/src/geom/GeometryFactory.cpp
+++ b/src/geom/GeometryFactory.cpp
@@ -653,7 +653,7 @@ GeometryFactory::createLineString(const CoordinateSequence &fromCoords)
 Geometry*
 GeometryFactory::buildGeometry(vector<Geometry *> *newGeoms) const
 {
-	string geomClass("NULL");
+	string geomClass;
 	bool isHeterogeneous=false;
 	bool hasGeometryCollection=false;
 
@@ -661,7 +661,7 @@ GeometryFactory::buildGeometry(vector<Geometry *> *newGeoms) const
 	{
 		Geometry* geom = (*newGeoms)[i];
 		string partClass(typeid(*geom).name());
-		if (geomClass=="NULL")
+		if (geomClass.empty())
 		{
 			geomClass=partClass;
 		}
@@ -676,7 +676,7 @@ GeometryFactory::buildGeometry(vector<Geometry *> *newGeoms) const
 	}
 
 	// for the empty geometry, return an empty GeometryCollection
-	if (geomClass=="NULL")
+	if (geomClass.empty())
 	{
 		// we do not need the vector anymore
 		delete newGeoms;
@@ -717,7 +717,7 @@ GeometryFactory::buildGeometry(vector<Geometry *> *newGeoms) const
 Geometry*
 GeometryFactory::buildGeometry(const vector<Geometry *> &fromGeoms) const
 {
-	string geomClass("NULL");
+	string geomClass;
 	bool isHeterogeneous=false;
 	bool isCollection=fromGeoms.size()>1;
 	size_t i;
@@ -725,7 +725,7 @@ GeometryFactory::buildGeometry(const vector<Geometry *> &fromGeoms) const
 	for (i=0; i<fromGeoms.size(); i++) {
 		Geometry *geom = fromGeoms[i];
 		string partClass(typeid(*geom).name());
-		if (geomClass=="NULL") {
+		if (geomClass.empty()) {
 			geomClass=partClass;
 		} else if (geomClass!=partClass) {
 			isHeterogeneous = true;
@@ -733,7 +733,7 @@ GeometryFactory::buildGeometry(const vector<Geometry *> &fromGeoms) const
 	}
 
 	// for the empty geometry, return an empty GeometryCollection
-	if (geomClass=="NULL") {
+	if (geomClass.empty()) {
 		return createGeometryCollection();
 	}
 	if (isHeterogeneous) {

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

Summary of changes:
 src/geom/GeometryFactory.cpp | 108 +++++++++++++++++++------------------------
 1 file changed, 48 insertions(+), 60 deletions(-)


hooks/post-receive
-- 
GEOS


More information about the geos-commits mailing list