]> granicus.if.org Git - postgis/commitdiff
Fix left over sub-tolerance last segment in ST_RemoveRepeatedPoints
authorSandro Santilli <strk@keybit.net>
Mon, 28 Dec 2015 17:08:50 +0000 (17:08 +0000)
committerSandro Santilli <strk@keybit.net>
Mon, 28 Dec 2015 17:08:50 +0000 (17:08 +0000)
See #3410

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

liblwgeom/ptarray.c
regress/remove_repeated_points_expected

index 8393e07ac345467973385492e8750c98f545f9b4..7fa7505878768f530fe093cd8f488812227e452c 100644 (file)
@@ -1446,19 +1446,26 @@ ptarray_remove_repeated_points_minpoints(const POINTARRAY *in, double tolerance,
        for ( ipn = 1; ipn < in->npoints; ++ipn)
        {
                this_point = getPoint2d_cp(in, ipn);
-               if ( (ipn >= in->npoints-minpoints+1 && opn < minpoints) || /* need extra points to hit minponts */
-                        (ipn == in->npoints-1 && memcmp(getPoint_internal(in, ipn-1), getPoint_internal(in, ipn), ptsize) != 0) || /* last point (and not exact dupe) */
-                    (tolerance == 0 && memcmp(getPoint_internal(in, ipn-1), getPoint_internal(in, ipn), ptsize) != 0) || /* not an exact dupe */
-                    (tolerance > 0.0 && distance2d_sqr_pt_pt(last_point, this_point) > tolsq) ) /* not within the removal tolerance */
+               if ( ipn < in->npoints-minpoints+1 || opn >= minpoints ) /* need extra points to hit minponts */
                {
-                       /* 
-                        * The point is different (see above) from the previous,
-                        * so we add it to output 
-                        */
-                       memcpy(getPoint_internal(out, opn++), getPoint_internal(in, ipn), ptsize);
-                       last_point = this_point;
-                       LWDEBUGF(3, " Point %d differs from point %d. Out points: %d", ipn, ipn-1, opn);
+                       if (
+                               (tolerance == 0 && memcmp(getPoint_internal(in, ipn-1), getPoint_internal(in, ipn), ptsize) == 0) || /* exact dupe */
+                               (tolerance > 0.0 && distance2d_sqr_pt_pt(last_point, this_point) <= tolsq) /* within the removal tolerance */
+                       ) continue;
                }
+
+               /*
+                * The point is different (see above) from the previous,
+                * so we add it to output
+                */
+               memcpy(getPoint_internal(out, opn++), getPoint_internal(in, ipn), ptsize);
+               last_point = this_point;
+               LWDEBUGF(3, " Point %d differs from point %d. Out points: %d", ipn, ipn-1, opn);
+       }
+       /* Keep the last point */
+       if ( memcmp(last_point, getPoint_internal(in, ipn-1), ptsize) != 0 )
+       {
+               memcpy(getPoint_internal(out, opn-1), getPoint_internal(in, ipn-1), ptsize);
        }
 
        LWDEBUGF(3, " in:%d out:%d", out->npoints, opn);
index 69836d4405260488e2e513cadab3f250c0a4fb71..38214fc58b7f84a8a4d1614f4761fc12eab61bf0 100644 (file)
@@ -12,4 +12,4 @@
 11|LINESTRING(0 0,0 0)
 12|3
 13|LINESTRING(0 0,2 0,4 0)
-14|LINESTRING(10 0,10 9,10 10)
+14|LINESTRING(10 0,10 10)