]> granicus.if.org Git - postgis/commitdiff
Fixed bug in ptarray_locate_point
authorSandro Santilli <strk@keybit.net>
Thu, 9 Jun 2005 16:01:22 +0000 (16:01 +0000)
committerSandro Santilli <strk@keybit.net>
Thu, 9 Jun 2005 16:01:22 +0000 (16:01 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@1749 b70326c6-7e19-0410-871a-916f4a2858ee

lwgeom/ptarray.c

index 7430b4c6432170384f561392f123468b7ed6e6e6..d0dc9e0ae3c68f18325c734013050a153a71ef22 100644 (file)
@@ -632,7 +632,7 @@ ptarray_locate_point(POINTARRAY *pa, POINT2D *p)
 
                if (t==1 || dist < mindist ) {
                        mindist = dist;
-                       seg=t;
+                       seg=t-1;
                }
 
                if ( mindist == 0 ) break;
@@ -640,14 +640,16 @@ ptarray_locate_point(POINTARRAY *pa, POINT2D *p)
                start = end;
        }
 
+       //lwnotice("Closest segment: %d", seg);
+
        /*
         * If mindist is not 0 we need to project the 
         * point on the closest segment.
         */
        if ( mindist > 0 )
        {
-               getPoint2d_p(pa, seg-1, &start);
-               getPoint2d_p(pa, seg, &end);
+               getPoint2d_p(pa, seg, &start);
+               getPoint2d_p(pa, seg+1, &end);
                closest_point_on_segment(p, &start, &end, &proj);
        } else {
                proj = *p;
@@ -656,6 +658,7 @@ ptarray_locate_point(POINTARRAY *pa, POINT2D *p)
        //lwnotice("Closest point on segment: %g,%g", proj.x, proj.y);
 
        tlen = lwgeom_pointarray_length2d(pa);
+       //lwnotice("tlen %g", tlen);
 
        plen=0;
        getPoint2d_p(pa, 0, &start);
@@ -669,6 +672,7 @@ ptarray_locate_point(POINTARRAY *pa, POINT2D *p)
        plen+=distance2d_pt_pt(&proj, &start);
 
        //lwnotice("plen %g, tlen %g", plen, tlen);
+       //lwnotice("mindist: %g", mindist);
 
        return plen/tlen;
 }