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
This commit is contained in:
Mark Cave-Ayland 2009-07-08 04:48:54 +00:00
parent 3ddf5e2d54
commit 5812cc0cbe

View file

@ -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