]> granicus.if.org Git - postgis/commitdiff
lw_segment_side may return any negative number, not just -1 (#2420)
authorSandro Santilli <strk@keybit.net>
Wed, 14 Aug 2013 07:37:23 +0000 (07:37 +0000)
committerSandro Santilli <strk@keybit.net>
Wed, 14 Aug 2013 07:37:23 +0000 (07:37 +0000)
Adds other unit tests for line desegmentation excercising quadrant
computation.

git-svn-id: http://svn.osgeo.org/postgis/trunk@11801 b70326c6-7e19-0410-871a-916f4a2858ee

liblwgeom/cunit/cu_ptarray.c
liblwgeom/lwsegmentize.c

index 6078f54d7c8d92c1d1188e1a44f768812c21ccd2..ae2022e000c34e214a5ace4d298a9c18567ba651 100644 (file)
@@ -431,6 +431,24 @@ static void test_ptarray_desegmentize()
        lwgeom_free(out);
        lwfree(str);    
 
+       in = lwgeom_from_text("LINESTRING(10 10,0 10,0 0,10 0)");
+       out = lwgeom_desegmentize(in);
+       str = lwgeom_to_wkt(out, WKT_ISO, 8, NULL);
+       CU_ASSERT_STRING_EQUAL(str, "LINESTRING(10 10,0 10,0 0,10 0)");
+       printf("%s\n", str);
+       lwgeom_free(in);
+       lwgeom_free(out);
+       lwfree(str);
+
+       in = lwgeom_from_text("LINESTRING(0 0,10 0,10 10,0 10)");
+       out = lwgeom_desegmentize(in);
+       str = lwgeom_to_wkt(out, WKT_ISO, 8, NULL);
+       CU_ASSERT_STRING_EQUAL(str, "LINESTRING(0 0,10 0,10 10,0 10)");
+       printf("%s\n", str);
+       lwgeom_free(in);
+       lwgeom_free(out);
+       lwfree(str);
+
        // See http://trac.osgeo.org/postgis/ticket/2412
        in = lwgeom_from_text("LINESTRING(0 0, 1 1)");
        out = lwgeom_desegmentize(in);
index 47966e67a745ca6b81d81bfe36409f3f43fba019..dacf0074dc4c13a6766d7087267c0c40b1f087aa 100644 (file)
@@ -675,11 +675,11 @@ pta_desegmentize(POINTARRAY *points, int type, int srid)
                                lw_arc_center((POINT2D*)&first, (POINT2D*)&b, (POINT2D*)&a1, (POINT2D*)&center);
                                angle = lw_arc_angle((POINT2D*)&first, (POINT2D*)&center, (POINT2D*)&b);
         int p2_side = lw_segment_side((POINT2D*)&first, (POINT2D*)&a1, (POINT2D*)&b);
-        if ( p2_side != -1 ) angle = -angle; 
+        if ( p2_side >= 0 ) angle = -angle; 
 
                                if ( angle < 0 ) angle = 2 * M_PI + angle;
                                num_quadrants = ( 4 * angle ) / ( 2 * M_PI );
-                               LWDEBUGF(4, "arc angle is %g, quandrants:%g", angle, num_quadrants);
+                               LWDEBUGF(4, "arc angle (%g %g, %g %g, %g %g) is %g (side is %d), quandrants:%g", first.x, first.y, center.x, center.y, b.x, b.y, angle, p2_side, num_quadrants);
                        }
                        /* a1 is first point, b is last point */
                        if ( arc_edges < min_quad_edges * num_quadrants ) {