[geos-commits] r3741 - in trunk: src/algorithm tests/unit/capi
svn_geos at osgeo.org
svn_geos at osgeo.org
Fri Jan 11 06:58:04 PST 2013
Author: strk
Date: 2013-01-11 06:58:04 -0800 (Fri, 11 Jan 2013)
New Revision: 3741
Modified:
trunk/src/algorithm/InteriorPointLine.cpp
trunk/tests/unit/capi/GEOSPointOnSurfaceTest.cpp
Log:
Fix GEOSPointOnSurface with zero-length linestring (#609)
Modified: trunk/src/algorithm/InteriorPointLine.cpp
===================================================================
--- trunk/src/algorithm/InteriorPointLine.cpp 2013-01-11 14:35:38 UTC (rev 3740)
+++ trunk/src/algorithm/InteriorPointLine.cpp 2013-01-11 14:58:04 UTC (rev 3741)
@@ -47,8 +47,8 @@
std::cerr << "Centroid: " << centroid << std::endl;
#endif
addInterior(g);
- if (!hasInterior) addEndpoints(g);
}
+ if (!hasInterior) addEndpoints(g);
}
InteriorPointLine::~InteriorPointLine()
@@ -118,8 +118,11 @@
void
InteriorPointLine::addEndpoints(const CoordinateSequence *pts)
{
- add(pts->getAt(0));
- add(pts->getAt(pts->getSize()-1));
+ size_t npts = pts->size();
+ if ( npts ) {
+ add(pts->getAt(0));
+ if ( npts > 1 ) add(pts->getAt(npts-1));
+ }
}
/*private*/
Modified: trunk/tests/unit/capi/GEOSPointOnSurfaceTest.cpp
===================================================================
--- trunk/tests/unit/capi/GEOSPointOnSurfaceTest.cpp 2013-01-11 14:35:38 UTC (rev 3740)
+++ trunk/tests/unit/capi/GEOSPointOnSurfaceTest.cpp 2013-01-11 14:58:04 UTC (rev 3741)
@@ -167,7 +167,25 @@
wkt_ = GEOSWKTWriter_write(wktw_, geom2_);
ensure_equals(std::string(wkt_), std::string( "POINT EMPTY"));
+ }
+ // Single point linestring -- see http://trac.osgeo.org/geos/ticket/609
+ template<>
+ template<>
+ void object::test<6>()
+ {
+ geom1_ = GEOSGeomFromWKT("LINESTRING(0 0, 0 0)");
+
+ ensure( 0 != geom1_ );
+
+ geom2_ = GEOSPointOnSurface(geom1_);
+
+ ensure( 0 != geom2_ );
+
+ wkt_ = GEOSWKTWriter_write(wktw_, geom2_);
+
+ ensure_equals(std::string(wkt_), std::string( "POINT (0 0)"));
+
}
} // namespace tut
More information about the geos-commits
mailing list