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

Function msSquareDistancePointToShape

mapsearch.c:476–515  ·  view source on GitHub ↗

** As msDistancePointToShape; avoid expensive sqrt calls */

Source from the content-addressed store, hash-verified

474** As msDistancePointToShape; avoid expensive sqrt calls
475*/
476double msSquareDistancePointToShape(pointObj *point, shapeObj *shape)
477{
478 int i, j;
479 double dist, minDist=-1;
480
481 switch(shape->type) {
482 case(MS_SHAPE_POINT):
483 for(j=0;j<shape->numlines;j++) {
484 for(i=0; i<shape->line[j].numpoints; i++) {
485 dist = msSquareDistancePointToPoint(point, &(shape->line[j].point[i]));
486 if((dist < minDist) || (minDist < 0)) minDist = dist;
487 }
488 }
489 break;
490 case(MS_SHAPE_LINE):
491 for(j=0;j<shape->numlines;j++) {
492 for(i=1; i<shape->line[j].numpoints; i++) {
493 dist = msSquareDistancePointToSegment(point, &(shape->line[j].point[i-1]), &(shape->line[j].point[i]));
494 if((dist < minDist) || (minDist < 0)) minDist = dist;
495 }
496 }
497 break;
498 case(MS_SHAPE_POLYGON):
499 if(msIntersectPointPolygon(point, shape))
500 minDist = 0; /* point is IN the shape */
501 else { /* treat shape just like a line */
502 for(j=0;j<shape->numlines;j++) {
503 for(i=1; i<shape->line[j].numpoints; i++) {
504 dist = msSquareDistancePointToSegment(point, &(shape->line[j].point[i-1]), &(shape->line[j].point[i]));
505 if((dist < minDist) || (minDist < 0)) minDist = dist;
506 }
507 }
508 }
509 break;
510 default:
511 break;
512 }
513
514 return(minDist);
515}
516
517double msDistanceShapeToShape(shapeObj *shape1, shapeObj *shape2)
518{

Callers 2

msDistancePointToShapeFunction · 0.85
msDistanceShapeToShapeFunction · 0.85

Calls 3

msIntersectPointPolygonFunction · 0.85

Tested by

no test coverage detected