MCPcopy Create free account
hub / github.com/MapServer/MapServer / msSquareDistancePointToSegment

Function msSquareDistancePointToSegment

mapsearch.c:339–359  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

337}
338
339double msSquareDistancePointToSegment(pointObj *p, pointObj *a, pointObj *b)
340{
341 double l_squared; /* squared length of line ab */
342 double r,s;
343
344 l_squared = msSquareDistancePointToPoint(a,b);
345
346 if(l_squared == 0.0) /* a = b */
347 return(msSquareDistancePointToPoint(a,p));
348
349 r = ((a->y - p->y)*(a->y - b->y) - (a->x - p->x)*(b->x - a->x))/(l_squared);
350
351 if(r > 1) /* perpendicular projection of P is on the forward extention of AB */
352 return(MS_MIN(msSquareDistancePointToPoint(p, b),msSquareDistancePointToPoint(p, a)));
353 if(r < 0) /* perpendicular projection of P is on the backward extention of AB */
354 return(MS_MIN(msSquareDistancePointToPoint(p, b),msSquareDistancePointToPoint(p, a)));
355
356 s = ((a->y - p->y)*(b->x - a->x) - (a->x - p->x)*(b->y - a->y))/l_squared;
357
358 return(fabs(s*s*l_squared));
359}
360
361#define SMALL_NUMBER 0.00000001
362#define dot(u,v) ((u).x *(v).x + (u).y *(v).y) /* vector dot product */

Callers 3

msDistancePointToSegmentFunction · 0.85
msPolygonLabelPointFunction · 0.85

Calls 1

Tested by

no test coverage detected