]> granicus.if.org Git - postgis/commitdiff
Fix #183: ST_LineToCurve gives getPoint4d_p offset error. This was due to the lookahe...
authorMark Cave-Ayland <mark.cave-ayland@siriusit.co.uk>
Wed, 8 Jul 2009 04:48:54 +0000 (04:48 +0000)
committerMark Cave-Ayland <mark.cave-ayland@siriusit.co.uk>
Wed, 8 Jul 2009 04:48:54 +0000 (04:48 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@4270 b70326c6-7e19-0410-871a-916f4a2858ee

liblwgeom/lwsegmentize.c

index d45f6a75890a74368aeeed0201bd731c85f705ff..4cfe4fb3de8833b13bf5deca57f23b32f6afd52e 100644 (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