]> granicus.if.org Git - postgis/commitdiff
Improve robustness of ptarray_isccw (see #1302)
authorSandro Santilli <strk@keybit.net>
Mon, 21 Nov 2011 08:08:18 +0000 (08:08 +0000)
committerSandro Santilli <strk@keybit.net>
Mon, 21 Nov 2011 08:08:18 +0000 (08:08 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@8198 b70326c6-7e19-0410-871a-916f4a2858ee

liblwgeom/lwgeom_api.c

index 65c8bbdadc90999119e09c4199b9214ce9c5e084..c53899ab47c0fceb1abd49aaaef6b33f2a063c9c 100644 (file)
@@ -556,14 +556,21 @@ ptarray_isccw(const POINTARRAY *pa)
 {
        int i;
        double area = 0;
-       POINT2D p1, p2;
+       POINT2D p1, p2, p0;
 
+       if ( pa->npoints == 0 ) return 0;
+
+       getPoint2d_p(pa, 0, &p1);
+       p0 = p1;
+       p1.x -= p0.x; p1.y -= p0.y;
        for (i=0; i<pa->npoints-1; i++)
        {
-               getPoint2d_p(pa, i, &p1);
                getPoint2d_p(pa, i+1, &p2);
+               p2.x -= p0.x; p2.y -= p0.y;
                area += (p1.y * p2.x) - (p1.x * p2.y);
+               p1 = p2;
        }
+       /* lwnotice("Signed area: %.16g", area); */
        if ( area > 0 ) return 0;
        else return 1;
 }