[geos-commits] r3748 - in trunk: include/geos/algorithm src/algorithm tests/xmltester/tests/general

svn_geos at osgeo.org svn_geos at osgeo.org
Mon Jan 14 03:16:02 PST 2013


Author: strk
Date: 2013-01-14 03:16:01 -0800 (Mon, 14 Jan 2013)
New Revision: 3748

Modified:
   trunk/include/geos/algorithm/InteriorPointArea.h
   trunk/src/algorithm/InteriorPointArea.cpp
   trunk/tests/xmltester/tests/general/TestInteriorPoint.xml
Log:
Fix EMPTY return from zero-area polygon (#613)

Modified: trunk/include/geos/algorithm/InteriorPointArea.h
===================================================================
--- trunk/include/geos/algorithm/InteriorPointArea.h	2013-01-14 11:12:35 UTC (rev 3747)
+++ trunk/include/geos/algorithm/InteriorPointArea.h	2013-01-14 11:16:01 UTC (rev 3748)
@@ -3,6 +3,7 @@
  * GEOS - Geometry Engine Open Source
  * http://geos.osgeo.org
  *
+ * Copyright (C) 2013 Sandro Santilli <strk at keybit.net>
  * Copyright (C) 2005-2006 Refractions Research Inc.
  * Copyright (C) 2001-2002 Vivid Solutions Inc.
  *
@@ -11,6 +12,10 @@
  * by the Free Software Foundation. 
  * See the COPYING file for more information.
  *
+ **********************************************************************
+ *
+ * Last port: algorithm/InteriorPointArea.java r728 (JTS-1.13+)
+ *
  **********************************************************************/
 
 #ifndef GEOS_ALGORITHM_INTERIORPOINTAREA_H

Modified: trunk/src/algorithm/InteriorPointArea.cpp
===================================================================
--- trunk/src/algorithm/InteriorPointArea.cpp	2013-01-14 11:12:35 UTC (rev 3747)
+++ trunk/src/algorithm/InteriorPointArea.cpp	2013-01-14 11:16:01 UTC (rev 3748)
@@ -3,7 +3,7 @@
  * GEOS - Geometry Engine Open Source
  * http://geos.osgeo.org
  *
- * Copyright (C) 2011      Sandro Santilli <strk at keybit.net>
+ * Copyright (C) 2013 Sandro Santilli <strk at keybit.net>
  * Copyright (C) 2005-2006 Refractions Research Inc.
  * Copyright (C) 2001-2002 Vivid Solutions Inc.
  *
@@ -12,6 +12,10 @@
  * by the Free Software Foundation. 
  * See the COPYING file for more information.
  *
+ **********************************************************************
+ *
+ * Last port: algorithm/InteriorPointArea.java r728 (JTS-1.13+)
+ *
  **********************************************************************/
 
 #include <geos/algorithm/InteriorPointArea.h>
@@ -89,13 +93,25 @@
 void
 InteriorPointArea::addPolygon(const Geometry *geometry)
 {
+  if (geometry->isEmpty()) return;
+
+  Coordinate intPt;
+  double width;
+
   auto_ptr<LineString> bisector ( horizontalBisector(geometry) );
-  auto_ptr<Geometry> intersections ( bisector->intersection(geometry) );
-  const Geometry *widestIntersection = widestGeometry(intersections.get());
-  const Envelope *env = widestIntersection->getEnvelopeInternal();
-  double width=env->getWidth();
+  if ( bisector->getLength() == 0.0 ) {
+    width = 0;
+    intPt = bisector->getCoordinateN(0);
+  }
+  else {
+    auto_ptr<Geometry> intersections ( bisector->intersection(geometry) );
+    const Geometry *widestIntersection = widestGeometry(intersections.get());
+    const Envelope *env = widestIntersection->getEnvelopeInternal();
+    width=env->getWidth();
+    env->centre(intPt);
+  }
   if (!foundInterior || width>maxWidth) {
-    env->centre(interiorPoint);
+    interiorPoint = intPt;
     maxWidth = width;
     foundInterior=true;
   }

Modified: trunk/tests/xmltester/tests/general/TestInteriorPoint.xml
===================================================================
--- trunk/tests/xmltester/tests/general/TestInteriorPoint.xml	2013-01-14 11:12:35 UTC (rev 3747)
+++ trunk/tests/xmltester/tests/general/TestInteriorPoint.xml	2013-01-14 11:16:01 UTC (rev 3748)
@@ -2,6 +2,12 @@
   <precisionModel scale="1.0" offsetx="0.0" offsety="0.0"/>
 
 <case>
+  <desc>P - empty</desc>
+  <a>    POINT EMPTY  </a>
+<test><op name="getInteriorPoint" arg1="A" >    POINT EMPTY   </op></test>
+</case>
+
+<case>
   <desc>P - single point</desc>
   <a>    POINT(10 10)  </a>
 <test><op name="getInteriorPoint" arg1="A" >    POINT(10 10)   </op></test>
@@ -9,7 +15,7 @@
 
 <case>
   <desc>P - single point</desc>
-  <a>    MULTIPOINT (60 300, 200 200, 240 240, 200 300, 40 140, 80 240, 140 240, 100 160, 140 200, 60 200)
+  <a>    MULTIPOINT ((60 300), (200 200), (240 240), (200 300), (40 140), (80 240), (140 240), (100 160), (140 200), (60 200))
 	</a>
 <test><op name="getInteriorPoint" arg1="A" >    POINT (140 240)   </op></test>
 </case>
@@ -29,6 +35,18 @@
 </case>
 
 <case>
+  <desc>L - zero length line</desc>
+  <a>    LINESTRING (10 10, 10 10)  </a>
+<test><op name="getInteriorPoint" arg1="A" >    POINT (10 10)   </op></test>
+</case>
+
+<case>
+  <desc>mL - zero length lines</desc>
+  <a>    MULTILINESTRING ((10 10, 10 10), (20 20, 20 20))  </a>
+<test><op name="getInteriorPoint" arg1="A" >    POINT (10 10)   </op></test>
+</case>
+
+<case>
   <desc>mL - complex linestrings</desc>
   <a>    MULTILINESTRING ((60 240, 140 300, 180 200, 40 140, 100 100, 120 220), 
   (240 80, 260 160, 200 240, 180 340, 280 340, 240 180, 180 140, 40 200, 140 260))
@@ -44,14 +62,60 @@
 </case>
 
 <case>
+  <desc>A - empty</desc>
+  <a>    POLYGON EMPTY
+	</a>
+<test><op name="getInteriorPoint" arg1="A" >    POINT EMPTY   </op></test>
+</case>
+
+<case>
+  <desc>A - polygon with horizontal segment at centre (L shape)</desc>
+  <a>    POLYGON ((0 2, 0 4, 6 4, 6 0, 2 0, 2 2, 0 2))
+	</a>
+<test><op name="getInteriorPoint" arg1="A" >    POINT (4 2)   </op></test>
+</case>
+
+<case>
   <desc>mA - polygons with holes</desc>
-  <a>    MULTIPOLYGON (((60 320, 240 340, 260 100, 20 60, 120 180, 60 320), 
-  (200 280, 140 260, 180 160, 240 140, 200 280)), 
-  ((380 280, 300 260, 340 100, 440 80, 380 280), 
-    (380 220, 340 200, 400 100, 380 220)))
+  <a>    MULTIPOLYGON (((50 260, 240 340, 260 100, 20 60, 90 140, 50 260), (200 280, 140 240, 180 160, 240 140, 200 280)), ((380 280, 300 260, 340 100, 440 80, 380 280), (380 220, 340 200, 400 100, 380 220)))
 	</a>
-<test><op name="getInteriorPoint" arg1="A" >    POINT (138 200)  </op></test>
+<test><op name="getInteriorPoint" arg1="A" >    POINT (115 200)  </op></test>
 </case>
 
+<case>
+  <desc>GC - collection of polygons, lines, points</desc>
+  <a>    GEOMETRYCOLLECTION (POLYGON ((0 40, 40 40, 40 0, 0 0, 0 40)), 
+  LINESTRING (80 0, 80 80, 120 40), 
+  MULTIPOINT ((20 60), (40 80), (60 60)))
+	</a>
+<test><op name="getInteriorPoint" arg1="A" >    POINT (20 20)   </op></test>
+</case>
 
+<case>
+  <desc>GC - collection of zero-area polygons and lines</desc>
+  <a>    GEOMETRYCOLLECTION (POLYGON ((10 10, 10 10, 10 10, 10 10)), 
+  LINESTRING (20 20, 30 30))
+	</a>
+<test><op name="getInteriorPoint" arg1="A" >    POINT (10 10)   </op></test>
+</case>
+
+<case>
+  <desc>GC - collection of zero-area polygons and zero-length lines</desc>
+  <a>    GEOMETRYCOLLECTION (POLYGON ((10 10, 10 10, 10 10, 10 10)), 
+  LINESTRING (20 20, 20 20))
+	</a>
+<test><op name="getInteriorPoint" arg1="A" >    POINT (10 10)   </op></test>
+</case>
+
+<case>
+  <desc>GC - collection of zero-area polygons, zero-length lines, and points</desc>
+  <a>    GEOMETRYCOLLECTION (POLYGON ((10 10, 10 10, 10 10, 10 10)), 
+  LINESTRING (20 20, 20 20),
+  MULTIPOINT ((20 10), (10 20)) )
+	</a>
+<test><op name="getInteriorPoint" arg1="A" >    POINT (10 10)   </op></test>
+</case>
+
+
+
 </run>



More information about the geos-commits mailing list