From: Sandro Santilli Date: Thu, 9 Jun 2005 16:01:22 +0000 (+0000) Subject: Fixed bug in ptarray_locate_point X-Git-Tag: pgis_1_1_0~343 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5f002f8466e957655c3e4fb6a55c323e83567c4c;p=postgis Fixed bug in ptarray_locate_point git-svn-id: http://svn.osgeo.org/postgis/trunk@1749 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/lwgeom/ptarray.c b/lwgeom/ptarray.c index 7430b4c64..d0dc9e0ae 100644 --- a/lwgeom/ptarray.c +++ b/lwgeom/ptarray.c @@ -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; }