[postgis-tickets] r14528 - Fix left over sub-tolerance last segment in ST_RemoveRepeatedPoints
Sandro Santilli
strk at keybit.net
Mon Dec 28 09:08:51 PST 2015
Author: strk
Date: 2015-12-28 09:08:50 -0800 (Mon, 28 Dec 2015)
New Revision: 14528
Modified:
trunk/liblwgeom/ptarray.c
trunk/regress/remove_repeated_points_expected
Log:
Fix left over sub-tolerance last segment in ST_RemoveRepeatedPoints
See #3410
Modified: trunk/liblwgeom/ptarray.c
===================================================================
--- trunk/liblwgeom/ptarray.c 2015-12-27 17:17:58 UTC (rev 14527)
+++ trunk/liblwgeom/ptarray.c 2015-12-28 17:08:50 UTC (rev 14528)
@@ -1446,20 +1446,27 @@
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);
out->npoints = opn;
Modified: trunk/regress/remove_repeated_points_expected
===================================================================
--- trunk/regress/remove_repeated_points_expected 2015-12-27 17:17:58 UTC (rev 14527)
+++ trunk/regress/remove_repeated_points_expected 2015-12-28 17:08:50 UTC (rev 14528)
@@ -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)
More information about the postgis-tickets
mailing list