]> granicus.if.org Git - postgis/commitdiff
Since we do a full scan of pointarray from ptarray_locate_point, take the chance...
authorSandro Santilli <strk@keybit.net>
Wed, 10 Mar 2010 15:29:39 +0000 (15:29 +0000)
committerSandro Santilli <strk@keybit.net>
Wed, 10 Mar 2010 15:29:39 +0000 (15:29 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@5395 b70326c6-7e19-0410-871a-916f4a2858ee

liblwgeom/liblwgeom.h
liblwgeom/ptarray.c
postgis/lwgeom_functions_analytic.c

index 2c69fe132ee5580d0a8bf5deca47b11bd96249dd..7f097e201511f630ea3a1757598e3307bd502923 100644 (file)
@@ -1394,9 +1394,12 @@ extern POINTARRAY *ptarray_substring(POINTARRAY *, double, double);
 
 /*
  * 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
index e68433c5a68c5a01b4690f323cf2de75fdf2715f..7e9f007e59fdb7fa1e2493afb0abe38542bd51fb 100644 (file)
@@ -778,9 +778,10 @@ closest_point_on_segment(POINT2D *p, POINT2D *A, POINT2D *B, POINT2D *ret)
 
 /*
  * 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;
@@ -844,6 +845,8 @@ ptarray_locate_point(POINTARRAY *pa, POINT2D *p)
        LWDEBUGF(3, "plen %g, tlen %g", plen, tlen);
        LWDEBUGF(3, "mindist: %g", mindist);
 
+       if ( mindistout ) *mindistout = mindist;
+
        return plen/tlen;
 }
 
index 2a53994bb073ea54b1d8ed94f31f88160af49895..c0e8b1f8cb5b8302c8fca27691cad6711a390224 100644 (file)
@@ -1232,7 +1232,7 @@ Datum LWGEOM_line_locate_point(PG_FUNCTION_ARGS)
        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);
 }