PostGIS  2.1.10dev-r@@SVN_REVISION@@
 int lw_dist2d_pt_seg ( const POINT2D * p, const POINT2D * A, const POINT2D * B, DISTPTS * dl )

lw_dist2d_comp from p to line A->B This one is now sending every occation to lw_dist2d_pt_pt Before it was handling occations where r was between 0 and 1 internally and just returning the distance without identifying the points.

To get this points it was nessecary to change and it also showed to be about 10faster.

Definition at line 2011 of file measures.c.

2012 {
2013  POINT2D c;
2014  double r;
2015  /*if start==end, then use pt distance */
2016  if ( ( A->x == B->x) && (A->y == B->y) )
2017  {
2018  return lw_dist2d_pt_pt(p,A,dl);
2019  }
2020  /*
2021  * otherwise, we use comp.graphics.algorithms
2022  * Frequently Asked Questions method
2023  *
2024  * (1) AC dot AB
2025  * r = ---------
2026  * ||AB||^2
2027  * r has the following meaning:
2028  * r=0 P = A
2029  * r=1 P = B
2030  * r<0 P is on the backward extension of AB
2031  * r>1 P is on the forward extension of AB
2032  * 0<r<1 P is interior to AB
2033  */
2034
2035  r = ( (p->x-A->x) * (B->x-A->x) + (p->y-A->y) * (B->y-A->y) )/( (B->x-A->x)*(B->x-A->x) +(B->y-A->y)*(B->y-A->y) );
2036
2037  /*This is for finding the maxdistance.
2038  the maxdistance have to be between two vertexes,
2039  compared to mindistance which can be between
2040  tvo vertexes vertex.*/
2041  if (dl->mode == DIST_MAX)
2042  {
2043  if (r>=0.5)
2044  {
2045  return lw_dist2d_pt_pt(p,A,dl);
2046  }
2047  if (r<0.5)
2048  {
2049  return lw_dist2d_pt_pt(p,B,dl);
2050  }
2051  }
2052
2053  if (r<0) /*If p projected on the line is outside point A*/
2054  {
2055  return lw_dist2d_pt_pt(p,A,dl);
2056  }
2057  if (r>=1) /*If p projected on the line is outside point B or on point B*/
2058  {
2059  return lw_dist2d_pt_pt(p,B,dl);
2060  }
2061
2062  /*If the point p is on the segment this is a more robust way to find out that*/
2063  if (( ((A->y-p->y)*(B->x-A->x)==(A->x-p->x)*(B->y-A->y) ) ) && (dl->mode == DIST_MIN))
2064  {
2065  dl->distance = 0.0;
2066  dl->p1 = *p;
2067  dl->p2 = *p;
2068  }
2069
2070  /*If the projection of point p on the segment is between A and B
2071  then we find that "point on segment" and send it to lw_dist2d_pt_pt*/
2072  c.x=A->x + r * (B->x-A->x);
2073  c.y=A->y + r * (B->y-A->y);
2074
2075  return lw_dist2d_pt_pt(p,&c,dl);
2076 }
char * r
Definition: cu_in_wkt.c:25
#define DIST_MAX
int mode
Definition: measures.h:26
#define DIST_MIN
POINT2D p1
Definition: measures.h:24
double x
Definition: liblwgeom.h:284
POINT2D p2
Definition: measures.h:25
double y
Definition: liblwgeom.h:284
double distance
Definition: measures.h:23
int lw_dist2d_pt_pt(const POINT2D *thep1, const POINT2D *thep2, DISTPTS *dl)
Compares incomming points and stores the points closest to each other or most far away from each othe...
Definition: measures.c:2087

Here is the call graph for this function: Here is the caller graph for this function: 