From: Mark Cave-Ayland Date: Wed, 8 Jul 2009 04:48:54 +0000 (+0000) Subject: Fix #183: ST_LineToCurve gives getPoint4d_p offset error. This was due to the lookahe... X-Git-Tag: 1.5.0b1~588 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5812cc0cbe138c68e970de000e60173e4a449de8;p=postgis Fix #183: ST_LineToCurve gives getPoint4d_p offset error. This was due to the lookahead in the curve segmentising code going off the end of the point array. git-svn-id: http://svn.osgeo.org/postgis/trunk@4270 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/liblwgeom/lwsegmentize.c b/liblwgeom/lwsegmentize.c index d45f6a758..4cfe4fb3d 100644 --- a/liblwgeom/lwsegmentize.c +++ b/liblwgeom/lwsegmentize.c @@ -828,33 +828,44 @@ pta_desegmentize(POINTARRAY *points, int type, int SRID) * We now need to move ahead one point to * determine if it's a potential new curve, * since the last_angle value is corrupt. + * + * Note we can only look ahead one point if + * we are not already at the end of our + * set of points. */ - i++; - getPoint4d_p(points, i-2, &a); - getPoint4d_p(points, i-1, &b); - getPoint4d_p(points, i, &c); - - dxab = b.x - a.x; - dyab = b.y - a.y; - dxbc = c.x - b.x; - dybc = c.y - b.y; - - theta = atan2(dyab, dxab); - last_angle = theta - atan2(dybc, dxbc); - last_length = sqrt(dxbc*dxbc+dybc*dybc); - length = sqrt(dxab*dxab+dyab*dyab); - if ((last_length - length) < EPSILON_SQLMM) + if (i < points->npoints - 1) { - isline = -1; - LWDEBUG(3, "Restarting as unknown."); + i++; + + getPoint4d_p(points, i-2, &a); + getPoint4d_p(points, i-1, &b); + getPoint4d_p(points, i, &c); + + dxab = b.x - a.x; + dyab = b.y - a.y; + dxbc = c.x - b.x; + dybc = c.y - b.y; + + theta = atan2(dyab, dxab); + last_angle = theta - atan2(dybc, dxbc); + last_length = sqrt(dxbc*dxbc+dybc*dybc); + length = sqrt(dxab*dxab+dyab*dyab); + if ((last_length - length) < EPSILON_SQLMM) + { + isline = -1; + LWDEBUG(3, "Restarting as unknown."); + } + else + { + isline = 1; + LWDEBUG(3, "Restarting as line."); + } } else { - isline = 1; - LWDEBUG(3, "Restarting as line."); + /* Indicate that we have tracked a CIRCSTRING */ + isline = 0; } - - } /* We didn't know what we were tracking, now we do. */ else