[postgis-tickets] r17122 - Fix infinite loop when linearizing circles

Daniel Baston dbaston at gmail.com
Thu Dec 27 09:20:49 PST 2018


Author: dbaston
Date: 2018-12-27 09:20:49 -0800 (Thu, 27 Dec 2018)
New Revision: 17122

Modified:
   trunk/liblwgeom/cunit/cu_lwstroke.c
   trunk/liblwgeom/lwstroke.c
Log:
Fix infinite loop when linearizing circles

Resolves #4282



Modified: trunk/liblwgeom/cunit/cu_lwstroke.c
===================================================================
--- trunk/liblwgeom/cunit/cu_lwstroke.c	2018-12-26 04:12:21 UTC (rev 17121)
+++ trunk/liblwgeom/cunit/cu_lwstroke.c	2018-12-27 17:20:49 UTC (rev 17122)
@@ -70,6 +70,7 @@
 	ASSERT_STRING_EQUAL(str, "LINESTRING(0 0,30 70,100 100,170 70,200 0)");
 	lwfree(str);
 	lwgeom_free(out);
+
 	/* 3 segment per quadrant */
 	out = lwcurve_linearize(in, 3, toltype, 0);
 	str = lwgeom_to_text(out, 2);
@@ -132,6 +133,14 @@
 
 	lwgeom_free(in);
 
+	/* 10 segments per quadrant (circular) */
+	in = lwgeom_from_text("CIRCULARSTRING(0 0,1 0,0 0)");
+	out = lwcurve_linearize(in, 10, toltype, 0);
+
+	ASSERT_INT_EQUAL(1 + 10*4, lwgeom_count_vertices(out));
+	lwgeom_free(out);
+	lwgeom_free(in);
+
 	/***********************************************************
 	 *
 	 *  Maximum deviation tolerance type

Modified: trunk/liblwgeom/lwstroke.c
===================================================================
--- trunk/liblwgeom/lwstroke.c	2018-12-26 04:12:21 UTC (rev 17121)
+++ trunk/liblwgeom/lwstroke.c	2018-12-27 17:20:49 UTC (rev 17122)
@@ -333,7 +333,7 @@
 
 	/* Calculate total arc angle, in radians */
 	double total_angle = clockwise ? a1 - a3 : a3 - a1;
-	if ( total_angle < 0 ) total_angle += M_PI * 2;
+	if ( total_angle <= 0 ) total_angle += M_PI * 2;
 
 	/* At extreme tolerance values (very low or very high, depending on
 	 * the semantic) we may cause our arc to collapse. In this case,



More information about the postgis-tickets mailing list