[postgis-tickets] r14529 - Fix left over sub-tolerance last segment in ST_RemoveRepeatedPoints

Sandro Santilli strk at keybit.net
Mon Dec 28 09:18:42 PST 2015


Author: strk
Date: 2015-12-28 09:18:42 -0800 (Mon, 28 Dec 2015)
New Revision: 14529

Modified:
   branches/2.2/NEWS
   branches/2.2/liblwgeom/ptarray.c
   branches/2.2/regress/remove_repeated_points_expected
Log:
Fix left over sub-tolerance last segment in ST_RemoveRepeatedPoints

Closes #3410

Modified: branches/2.2/NEWS
===================================================================
--- branches/2.2/NEWS	2015-12-28 17:08:50 UTC (rev 14528)
+++ branches/2.2/NEWS	2015-12-28 17:18:42 UTC (rev 14529)
@@ -17,7 +17,7 @@
   - #3378, Fix handling of hierarchical TopoGeometries
            in presence of multiple topologies
   - #3389, Buffer overflow in lwgeom_to_geojson
-  - #3388, Fix missing end-points in ST_Removepoints
+  - #3388, #3410, Fix missing end-points in ST_Removepoints
   - #3393, ST_Area NaN for some polygons
   - #3404, ST_ClusterWithin crashes backend
   - #3407, Fix crash on splitting a face or an edge

Modified: branches/2.2/liblwgeom/ptarray.c
===================================================================
--- branches/2.2/liblwgeom/ptarray.c	2015-12-28 17:08:50 UTC (rev 14528)
+++ branches/2.2/liblwgeom/ptarray.c	2015-12-28 17:18:42 UTC (rev 14529)
@@ -1433,20 +1433,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: branches/2.2/regress/remove_repeated_points_expected
===================================================================
--- branches/2.2/regress/remove_repeated_points_expected	2015-12-28 17:08:50 UTC (rev 14528)
+++ branches/2.2/regress/remove_repeated_points_expected	2015-12-28 17:18:42 UTC (rev 14529)
@@ -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