/*
* Given a point, returns the location of closest point on pointarray
- * as a fraction of total length (0: first point -- 1: last point)
+ * as a fraction of total length (0: first point -- 1: last point).
+ *
+ * If not-null, the third argument will be set to the actual distance
+ * of the point from the pointarray.
*/
-extern double ptarray_locate_point(POINTARRAY *, POINT2D *);
+extern double ptarray_locate_point(POINTARRAY *, POINT2D *, double *);
/*
* Write into *ret the coordinates of the closest point on
/*
* Given a point, returns the location of closest point on pointarray
+ * and, optionally, it's actual distance from the point array.
*/
double
-ptarray_locate_point(POINTARRAY *pa, POINT2D *p)
+ptarray_locate_point(POINTARRAY *pa, POINT2D *p, double* mindistout)
{
double mindist=-1;
double tlen, plen;
LWDEBUGF(3, "plen %g, tlen %g", plen, tlen);
LWDEBUGF(3, "mindist: %g", mindist);
+ if ( mindistout ) *mindistout = mindist;
+
return plen/tlen;
}
pa = lwline->points;
lwpoint_getPoint2d_p(lwpoint, &p);
- ret = ptarray_locate_point(pa, &p);
+ ret = ptarray_locate_point(pa, &p, NULL);
PG_RETURN_FLOAT8(ret);
}