int lw_dist2d_pt_seg ( POINT2D p,
POINT2D A,
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 1273 of file measures.c.

References c, DIST_MAX, DIST_MIN, DISTPTS::distance, lw_dist2d_pt_pt(), DISTPTS::mode, DISTPTS::p1, DISTPTS::p2, r, POINT2D::x, and POINT2D::y.

Referenced by lw_dist2d_pt_ptarray(), lw_dist2d_seg_seg(), and lw_dist2d_selected_seg_seg().

01274 {
01275         POINT2D c;
01276         double  r;
01277         /*if start==end, then use pt distance */
01278         if (  ( A->x == B->x) && (A->y == B->y) )
01279         {
01280                 return lw_dist2d_pt_pt(p,A,dl);
01281         }
01282         /*
01283          * otherwise, we use comp.graphics.algorithms
01284          * Frequently Asked Questions method
01285          *
01286          *  (1)        AC dot AB
01287          *         r = ---------
01288          *              ||AB||^2
01289          *      r has the following meaning:
01290          *      r=0 P = A
01291          *      r=1 P = B
01292          *      r<0 P is on the backward extension of AB
01293          *      r>1 P is on the forward extension of AB
01294          *      0<r<1 P is interior to AB
01295          */
01296 
01297         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) );
01298 
01299         /*This is for finding the maxdistance.
01300         the maxdistance have to be between two vertexes,
01301         compared to mindistance which can be between
01302         tvo vertexes vertex.*/
01303         if (dl->mode == DIST_MAX)
01304         {
01305                 if (r>=0.5)
01306                 {
01307                         return lw_dist2d_pt_pt(p,A,dl);
01308                 }
01309                 if (r<0.5)
01310                 {
01311                         return lw_dist2d_pt_pt(p,B,dl);
01312                 }
01313         }
01314 
01315         if (r<0)        /*If p projected on the line is outside point A*/
01316         {
01317                 return lw_dist2d_pt_pt(p,A,dl);
01318         }
01319         if (r>=1)       /*If p projected on the line is outside point B or on point B*/
01320         {
01321                 return lw_dist2d_pt_pt(p,B,dl);
01322         }
01323         
01324         /*If the point p is on the segment this is a more robust way to find out that*/
01325         if (( ((A->y-p->y)*(B->x-A->x)==(A->x-p->x)*(B->y-A->y) ) ) && (dl->mode ==  DIST_MIN))
01326         {
01327                 dl->distance = 0.0;
01328                 dl->p1 = *p;
01329                 dl->p2 = *p;
01330         }
01331         
01332         /*If the projection of point p on the segment is between A and B
01333         then we find that "point on segment" and send it to lw_dist2d_pt_pt*/
01334         c.x=A->x + r * (B->x-A->x);
01335         c.y=A->y + r * (B->y-A->y);
01336 
01337         return lw_dist2d_pt_pt(p,&c,dl);
01338 }

Here is the call graph for this function:

Here is the caller graph for this function:


Generated on Wed Aug 22 01:40:28 2012 for PostGIS Trunk Doxygen by  doxygen 1.4.7