[postgis-tickets] r15466 - lwarc_linearize: fix total angle computation for ccw arcs

Sandro Santilli strk at kbt.io
Wed Jun 28 01:03:31 PDT 2017


Author: strk
Date: 2017-06-28 01:03:31 -0700 (Wed, 28 Jun 2017)
New Revision: 15466

Modified:
   trunk/liblwgeom/cunit/cu_lwstroke.c
   trunk/liblwgeom/lwstroke.c
Log:
lwarc_linearize: fix total angle computation for ccw arcs

Modified: trunk/liblwgeom/cunit/cu_lwstroke.c
===================================================================
--- trunk/liblwgeom/cunit/cu_lwstroke.c	2017-06-27 12:37:07 UTC (rev 15465)
+++ trunk/liblwgeom/cunit/cu_lwstroke.c	2017-06-28 08:03:31 UTC (rev 15466)
@@ -207,6 +207,22 @@
 	lwfree(str);
 	lwgeom_free(out);
 
+	/*
+	 * Clockwise ~90 degrees north-west to south-west quadrants
+	 * starting at ~22 degrees west of vertical line
+	 *
+	 * See https://trac.osgeo.org/postgis/ticket/3772
+	 */
+	toltype = LW_LINEARIZE_TOLERANCE_TYPE_MAX_DEVIATION;
+	in = lwgeom_from_text("CIRCULARSTRING(20 50,22.2 -18.52,71.96 -65.64)");
+
+	/* 4 units of max deviation - symmetric */
+	out = lwcurve_linearize(in, 4, toltype, LW_LINEARIZE_FLAG_SYMMETRIC);
+	str = lwgeom_to_text(out, 2);
+	ASSERT_STRING_EQUAL(str, "LINESTRING(20 50,16 4,34 -38,72 -66)");
+	lwfree(str);
+	lwgeom_free(out);
+
 	lwgeom_free(in);
 
 	/***********************************************************

Modified: trunk/liblwgeom/lwstroke.c
===================================================================
--- trunk/liblwgeom/lwstroke.c	2017-06-27 12:37:07 UTC (rev 15465)
+++ trunk/liblwgeom/lwstroke.c	2017-06-28 08:03:31 UTC (rev 15466)
@@ -221,7 +221,7 @@
 	if ( flags & LW_LINEARIZE_FLAG_SYMMETRIC )
 	{{
 		/* Calculate total arc angle, in radians */
-		double angle = a1 - a3;
+		double angle = clockwise ? a1 - a3 : a3 - a1;
 		if ( angle < 0 ) angle += M_PI * 2;
 		LWDEBUGF(2, "lwarc_linearize SYMMETRIC requested - total angle %g deg",
 			         angle * 180 / M_PI);



More information about the postgis-tickets mailing list