From: Sandro Santilli Date: Mon, 21 Nov 2011 08:08:18 +0000 (+0000) Subject: Improve robustness of ptarray_isccw (see #1302) X-Git-Tag: 2.0.0alpha1~662 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=50593de78168f734be0481ef996179e5b3e684f4;p=postgis Improve robustness of ptarray_isccw (see #1302) git-svn-id: http://svn.osgeo.org/postgis/trunk@8198 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/liblwgeom/lwgeom_api.c b/liblwgeom/lwgeom_api.c index 65c8bbdad..c53899ab4 100644 --- a/liblwgeom/lwgeom_api.c +++ b/liblwgeom/lwgeom_api.c @@ -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; inpoints-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; }