From: Sandro Santilli Date: Mon, 28 Dec 2015 17:08:50 +0000 (+0000) Subject: Fix left over sub-tolerance last segment in ST_RemoveRepeatedPoints X-Git-Tag: 2.3.0beta1~310 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f45721116ba7719bb182346fef7b5b591370ef2a;p=postgis Fix left over sub-tolerance last segment in ST_RemoveRepeatedPoints See #3410 git-svn-id: http://svn.osgeo.org/postgis/trunk@14528 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/liblwgeom/ptarray.c b/liblwgeom/ptarray.c index 8393e07ac..7fa750587 100644 --- a/liblwgeom/ptarray.c +++ b/liblwgeom/ptarray.c @@ -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); diff --git a/regress/remove_repeated_points_expected b/regress/remove_repeated_points_expected index 69836d440..38214fc58 100644 --- a/regress/remove_repeated_points_expected +++ b/regress/remove_repeated_points_expected @@ -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)