]> granicus.if.org Git - postgis/commitdiff
Fix rare missing boxes in geometry subdivision
authorPaul Ramsey <pramsey@cleverelephant.ca>
Wed, 11 Oct 2017 14:06:07 +0000 (14:06 +0000)
committerPaul Ramsey <pramsey@cleverelephant.ca>
Wed, 11 Oct 2017 14:06:07 +0000 (14:06 +0000)
Closes #3886

git-svn-id: http://svn.osgeo.org/postgis/trunk@15966 b70326c6-7e19-0410-871a-916f4a2858ee

liblwgeom/lwgeom_geos.c

index 14799810fbf6466ffebb0515fc41fad047ce523f..1d3ccf707324accf7202d430430a1a0fd900a0ac 100644 (file)
@@ -262,19 +262,25 @@ ptarray_to_GEOSLinearRing(const POINTARRAY *pa, int autofix)
 
        if ( autofix )
        {
-               /* check ring for being closed and fix if not */
-               if ( ! ptarray_is_closed_2d(pa) )
+               if (pa->npoints < 1)
                {
-                       npa = ptarray_addPoint(pa, getPoint_internal(pa, 0), FLAGS_NDIMS(pa->flags), pa->npoints);
-                       pa = npa;
+                       lwerror("ptarray_to_GEOSLinearRing called with autofix and 0 vertices in ring, cannot fix");
                }
-               /* TODO: check ring for having at least 4 vertices */
-#if 0
+
+               /*
+               * Check ring for being closed and fix if not.
+               * Also create a copy of geometry to operate on.
+               */
+               if ( ! ptarray_is_closed_2d(pa) || pa->npoints < 4 )
+               {
+                       pa = ptarray_addPoint(pa, getPoint_internal(pa, 0), FLAGS_NDIMS(pa->flags), pa->npoints);
+                       npa = pa;
+               }
+               /* Check ring for having at least 4 vertices */
                while ( pa->npoints < 4 )
                {
-                       npa = ptarray_addPoint(npa, getPoint_internal(pa, 0), FLAGS_NDIMS(pa->flags), pa->npoints);
+                       ptarray_append_point(pa, getPoint_internal(pa, 0), LW_TRUE);
                }
-#endif
        }
 
        sq = ptarray_to_GEOSCoordSeq(pa);