[geos-commits] r2560 - in trunk/source:
headers/geos/operation/distance operation/distance
svn_geos at osgeo.org
svn_geos at osgeo.org
Mon Jun 8 06:29:55 EDT 2009
Author: strk
Date: 2009-06-08 06:29:54 -0400 (Mon, 08 Jun 2009)
New Revision: 2560
Modified:
trunk/source/headers/geos/operation/distance/DistanceOp.h
trunk/source/operation/distance/DistanceOp.cpp
Log:
DistanceOp sync to JTS-1.10 (renames, docs...)
Modified: trunk/source/headers/geos/operation/distance/DistanceOp.h
===================================================================
--- trunk/source/headers/geos/operation/distance/DistanceOp.h 2009-06-08 10:07:05 UTC (rev 2559)
+++ trunk/source/headers/geos/operation/distance/DistanceOp.h 2009-06-08 10:29:54 UTC (rev 2560)
@@ -13,7 +13,7 @@
*
**********************************************************************
*
- * Last port: operation/distance/DistanceOp.java rev 1.17
+ * Last port: operation/distance/DistanceOp.java rev 1.21 (JTS-1.10)
*
**********************************************************************/
@@ -70,7 +70,7 @@
public:
/**
* \brief
- * Compute the distance between the closest points of two geometries.
+ * Compute the distance between the nearest points of two geometries.
*
* @param g0 a {@link Geometry}
* @param g1 another {@link Geometry}
@@ -98,6 +98,22 @@
double distance);
/**
+ * Compute the the nearest points of two geometries.
+ *
+ * The points are presented in the same order as the input Geometries.
+ *
+ * @param g0 a {@link Geometry}
+ * @param g1 another {@link Geometry}
+ *
+ * @return the nearest points in the geometries, ownership to caller.
+ * A NULL return means one of the geometries is empty.
+ *
+ */
+ static geom::CoordinateSequence* nearestPoints(
+ const geom::Geometry *g0,
+ const geom::Geometry *g1);
+
+ /**
* Compute the the closest points of two geometries.
*
* The points are presented in the same order as the input Geometries.
@@ -107,6 +123,8 @@
*
* @return the closest points in the geometries, ownership to caller.
* A NULL return means one of the geometries is empty.
+ *
+ * @deprecated renamed to nearestPoints
*/
static geom::CoordinateSequence* closestPoints(
const geom::Geometry *g0,
@@ -118,7 +136,7 @@
/**
* \brief
* Constructs a DistanceOp that computes the distance and
- * closest points between the two specified geometries.
+ * nearest points between the two specified geometries.
*
* @param g0 a Geometry
* @param g1 a Geometry
@@ -153,9 +171,21 @@
*
* @return a pair of {@link Coordinate}s of the closest points
* as a newly allocated object (ownership to caller)
+ *
+ * @deprecated renamed to nearestPoints
*/
geom::CoordinateSequence* closestPoints();
+ /**
+ * Report the coordinates of the nearest points in the input geometries.
+ * The points are presented in the same order as the input Geometries.
+ *
+ * @return a pair of {@link Coordinate}s of the nearest points
+ * as a newly allocated object (ownership to caller)
+ *
+ */
+ geom::CoordinateSequence* nearestPoints();
+
private:
/**
@@ -170,7 +200,7 @@
* NOTE: this is public in JTS, but we aim at API reduction here...
*
*/
- std::vector<GeometryLocation*>* closestLocations();
+ std::vector<GeometryLocation*>* nearestLocations();
// input (TODO: use two references instead..)
std::vector<geom::Geometry const*> geom;
Modified: trunk/source/operation/distance/DistanceOp.cpp
===================================================================
--- trunk/source/operation/distance/DistanceOp.cpp 2009-06-08 10:07:05 UTC (rev 2559)
+++ trunk/source/operation/distance/DistanceOp.cpp 2009-06-08 10:29:54 UTC (rev 2560)
@@ -14,7 +14,7 @@
*
**********************************************************************
*
- * Last port: operation/distance/DistanceOp.java rev 1.17
+ * Last port: operation/distance/DistanceOp.java rev 1.21 (JTS-1.10)
*
**********************************************************************/
@@ -71,14 +71,22 @@
return distOp.distance();
}
-/*public static*/
+/*public static deprecated*/
CoordinateSequence*
DistanceOp::closestPoints(const Geometry *g0, const Geometry *g1)
{
DistanceOp distOp(g0,g1);
- return distOp.closestPoints();
+ return distOp.nearestPoints();
}
+/*public static*/
+CoordinateSequence*
+DistanceOp::nearestPoints(const Geometry *g0, const Geometry *g1)
+{
+ DistanceOp distOp(g0,g1);
+ return distOp.nearestPoints();
+}
+
DistanceOp::DistanceOp(const Geometry *g0, const Geometry *g1):
geom(2),
terminateDistance(0.0),
@@ -136,11 +144,18 @@
return minDistance;
}
-
/* public */
CoordinateSequence*
DistanceOp::closestPoints()
{
+ return nearestPoints();
+}
+
+
+/* public */
+CoordinateSequence*
+DistanceOp::nearestPoints()
+{
// lazily creates minDistanceLocation
computeMinDistance();
@@ -161,20 +176,15 @@
const Coordinate& c0 = loc0->getCoordinate();
const Coordinate& c1 = loc1->getCoordinate();
- CoordinateSequence* closestPts = new CoordinateArraySequence();
- closestPts->add(c0);
- closestPts->add(c1);
+ CoordinateSequence* nearestPts = new CoordinateArraySequence();
+ nearestPts->add(c0);
+ nearestPts->add(c1);
- return closestPts;
+ return nearestPts;
}
-/**
-* Report the locations of the closest points in the input geometries.
-* The locations are presented in the same order as the input Geometries.
-*
-* @return a pair of {@link GeometryLocation}s for the closest points
-*/
-vector<GeometryLocation*>* DistanceOp::closestLocations(){
+/*private, unused!*/
+vector<GeometryLocation*>* DistanceOp::nearestLocations(){
computeMinDistance();
return minDistanceLocation;
}
@@ -238,14 +248,12 @@
{
using geom::util::PolygonExtracter;
- Polygon::ConstVect polys0;
Polygon::ConstVect polys1;
-
- PolygonExtracter::getPolygons(*(geom[0]), polys0);
PolygonExtracter::getPolygons(*(geom[1]), polys1);
+
#if GEOS_DEBUG
- std::cerr << "PolygonExtracter found " << polys0.size() << " polygons in geometry 1 and " << polys1.size() << " polygons in geometry 2 " << std::endl;
+ std::cerr << "PolygonExtracter found " << polys1.size() << " polygons in geometry 2" << std::endl;
#endif
// NOTE:
@@ -253,7 +261,7 @@
// if minDistance <= terminateDistance
vector<GeometryLocation*> *locPtPoly = new vector<GeometryLocation*>(2);
- // test if either geometry is wholely inside the other
+ // test if either geometry has a vertex inside the other
if ( ! polys1.empty() )
{
vector<GeometryLocation*> *insideLocs0 =
@@ -282,6 +290,14 @@
delete insideLocs0;
}
+ Polygon::ConstVect polys0;
+ PolygonExtracter::getPolygons(*(geom[0]), polys0);
+
+#if GEOS_DEBUG
+ std::cerr << "PolygonExtracter found " << polys0.size() << " polygons in geometry 1" << std::endl;
+#endif
+
+
if ( ! polys0.empty() )
{
vector<GeometryLocation*> *insideLocs1 = ConnectedElementLocationFilter::getLocations(geom[1]);
@@ -343,6 +359,8 @@
vector<GeometryLocation*> *locPtPoly)
{
const Coordinate &pt=ptLoc->getCoordinate();
+
+ // if pt is not in exterior, distance to geom is 0
if (Location::EXTERIOR!=ptLocator.locate(pt, static_cast<const Geometry *>(poly)))
{
minDistance = 0.0;
@@ -391,7 +409,7 @@
<< std::endl;
#endif
- // bail whenever minDistance goes to zero, since it can't get any less
+ // exit whenever minDistance goes LE than terminateDistance
computeMinDistanceLines(lines0, lines1, locGeom);
updateMinDistance(locGeom, false);
if (minDistance <= terminateDistance) {
More information about the geos-commits
mailing list