[geos-commits] r3259 - in trunk: include/geos/operation/distance src/operation/distance

svn_geos at osgeo.org svn_geos at osgeo.org
Wed Mar 2 08:45:13 EST 2011


Author: strk
Date: 2011-03-02 05:45:13 -0800 (Wed, 02 Mar 2011)
New Revision: 3259

Modified:
   trunk/include/geos/operation/distance/DistanceOp.h
   trunk/src/operation/distance/DistanceOp.cpp
Log:
Fixed Geometry.distance() and DistanceOp to return 0.0 for empty inputs (JTS-1.11)

Modified: trunk/include/geos/operation/distance/DistanceOp.h
===================================================================
--- trunk/include/geos/operation/distance/DistanceOp.h	2011-03-02 13:13:50 UTC (rev 3258)
+++ trunk/include/geos/operation/distance/DistanceOp.h	2011-03-02 13:45:13 UTC (rev 3259)
@@ -4,6 +4,7 @@
  * GEOS - Geometry Engine Open Source
  * http://geos.refractions.net
  *
+ * Copyright (C) 2011 Sandro Santilli <strk at keybit.net>
  * Copyright (C) 2006 Refractions Research Inc.
  *
  * This is free software; you can redistribute and/or modify it under
@@ -13,7 +14,7 @@
  *
  **********************************************************************
  *
- * Last port: operation/distance/DistanceOp.java rev 1.21 (JTS-1.10)
+ * Last port: operation/distance/DistanceOp.java r335 (JTS-1.12-)
  *
  **********************************************************************/
 
@@ -80,6 +81,8 @@
 	 * @param g0 a {@link Geometry}
 	 * @param g1 another {@link Geometry}
 	 * @return the distance between the geometries
+	 * @return 0 if either input geometry is empty
+	 * @throws IllegalArgumentException if either input geometry is null
 	 */
 	static double distance(const geom::Geometry& g0,
 	                       const geom::Geometry& g1);

Modified: trunk/src/operation/distance/DistanceOp.cpp
===================================================================
--- trunk/src/operation/distance/DistanceOp.cpp	2011-03-02 13:13:50 UTC (rev 3258)
+++ trunk/src/operation/distance/DistanceOp.cpp	2011-03-02 13:45:13 UTC (rev 3259)
@@ -4,6 +4,7 @@
  * GEOS - Geometry Engine Open Source
  * http://geos.refractions.net
  *
+ * Copyright (C) 2011 Sandro Santilli <strk at keybit.net>
  * Copyright (C) 2006 Refractions Research Inc.
  * Copyright (C) 2001-2002 Vivid Solutions Inc.
  *
@@ -14,7 +15,7 @@
  *
  **********************************************************************
  *
- * Last port: operation/distance/DistanceOp.java rev 1.21 (JTS-1.10)
+ * Last port: operation/distance/DistanceOp.java r335 (JTS-1.12-)
  *
  **********************************************************************/
 
@@ -34,6 +35,7 @@
 #include <geos/geom/util/PolygonExtracter.h>
 #include <geos/geom/util/LinearComponentExtracter.h>
 #include <geos/geom/util/PointExtracter.h>
+#include <geos/util/IllegalArgumentException.h>
 
 #include <vector>
 #include <iostream>
@@ -138,6 +140,11 @@
 double
 DistanceOp::distance()
 {
+	using geos::util::IllegalArgumentException;
+
+	if ( geom[0] == 0 || geom[1] == 0 )
+		throw IllegalArgumentException("null geometries are not supported");
+	if ( geom[0]->isEmpty() || geom[1]->isEmpty() ) return 0.0;
 	computeMinDistance();
 	return minDistance;
 }



More information about the geos-commits mailing list