[geos-commits] r2335 - in branches/3.1: source/operation/distance
tests/unit/operation/distance
svn_geos at osgeo.org
svn_geos at osgeo.org
Wed Apr 8 12:41:11 EDT 2009
Author: pramsey
Date: 2009-04-08 12:41:11 -0400 (Wed, 08 Apr 2009)
New Revision: 2335
Modified:
branches/3.1/source/operation/distance/DistanceOp.cpp
branches/3.1/tests/unit/operation/distance/DistanceOpTest.cpp
Log:
DistanceOp fix for #236 from trunk.
Modified: branches/3.1/source/operation/distance/DistanceOp.cpp
===================================================================
--- branches/3.1/source/operation/distance/DistanceOp.cpp 2009-04-08 16:33:32 UTC (rev 2334)
+++ branches/3.1/source/operation/distance/DistanceOp.cpp 2009-04-08 16:41:11 UTC (rev 2335)
@@ -109,10 +109,27 @@
CoordinateSequence*
DistanceOp::closestPoints()
{
- computeMinDistance();
- CoordinateSequence* closestPts=new CoordinateArraySequence();
- closestPts->add((*minDistanceLocation)[0]->getCoordinate());
- closestPts->add((*minDistanceLocation)[1]->getCoordinate());
+ assert(0 != minDistanceLocation);
+ std::vector<GeometryLocation*>& locs = *minDistanceLocation;
+
+ computeMinDistance();
+
+ // FIXME: This code (refactored to make the bug visible) causes
+ // crash reported in Ticket #236
+ // NOTE: In order to reproduce, uncomment test case test<17>
+ // in tests/unit/operation/distance/DistanceOpTest.cpp
+ GeometryLocation* loc0 = locs[0];
+ GeometryLocation* loc1 = locs[1];
+ // Assertion fails, so...
+ assert(0 != loc0 && 0 != loc1);
+ // ...accesss violation is thrown.
+ Coordinate& c0 = loc0->getCoordinate();
+ Coordinate& c1 = loc1->getCoordinate();
+
+ CoordinateSequence* closestPts = new CoordinateArraySequence();
+ closestPts->add(c0);
+ closestPts->add(c1);
+
return closestPts;
}
Modified: branches/3.1/tests/unit/operation/distance/DistanceOpTest.cpp
===================================================================
--- branches/3.1/tests/unit/operation/distance/DistanceOpTest.cpp 2009-04-08 16:33:32 UTC (rev 2334)
+++ branches/3.1/tests/unit/operation/distance/DistanceOpTest.cpp 2009-04-08 16:41:11 UTC (rev 2335)
@@ -7,11 +7,12 @@
// GEOS
#include <geos/operation/distance/DistanceOp.h>
#include <geos/platform.h>
+#include <geos/geom/Coordinate.h>
#include <geos/geom/GeometryFactory.h>
#include <geos/geom/Geometry.h>
#include <geos/algorithm/PointLocator.h>
#include <geos/io/WKTReader.h>
-#include <geos/geom/Coordinate.h>
+#include <geos/geom/CoordinateSequence.h>
#include <memory>
#include <vector>
@@ -30,14 +31,9 @@
typedef geos::geom::Geometry::AutoPtr GeomPtr;
test_distanceop_data()
- :
- gf(),
- wktreader(&gf)
- {
- }
-
+ : gf(), wktreader(&gf)
+ {}
};
-
typedef test_group<test_distanceop_data> group;
typedef group::object object;
@@ -47,7 +43,6 @@
//
// Test Cases
//
-
template<>
template<>
void object::test<1>()
@@ -65,7 +60,8 @@
// TODO: test closestPoints() and
// closestLocations()
-
+ geos::geom::CoordinateSequence* coords = dist.closestPoints();
+ ensure(0 != coords);
}
template<>
@@ -380,6 +376,28 @@
}
+ // Test for crash reported in Ticket #236:
+ // http://trac.osgeo.org/geos/ticket/236
+ template<>
+ template<>
+ void object::test<17>()
+ {
+ using geos::operation::distance::DistanceOp;
+
+ std::string wkt0("POLYGON((0 0, 0 1, 1 1, 1 0, 0 0))");
+ std::string wkt1("POLYGON((1.25 0.25, 1.25 0.75, 1.75 0.75, 1.75 0.25, 1.25 0.25))");
+
+ GeomPtr g0(wktreader.read(wkt0));
+ GeomPtr g1(wktreader.read(wkt1));
+
+ DistanceOp dist(g0.get(), g1.get());
+ ensure_equals(dist.distance(), 0.25);
+
+ // FIXME: This operation crashes becasue of both GeometryLocation's are NULL
+ // in DistanceOp::closestPoints()
+ //geos::geom::CoordinateSequence* cs dist.closestPoints();
+ }
+
// TODO: finish the tests by adding:
// LINESTRING - *all*
// MULTILINESTRING - *all*
More information about the geos-commits
mailing list