PostGIS  2.1.10dev-r@@SVN_REVISION@@
int lw_dist2d_point_curvepoly ( LWPOINT point,
LWCURVEPOLY poly,
DISTPTS dl 
)

Definition at line 619 of file measures.c.

References DIST_MAX, DIST_MIN, DISTPTS::distance, getPoint2d_cp(), lw_dist2d_recursive(), LW_OUTSIDE, LW_TRUE, LWDEBUG, lwerror(), lwgeom_contains_point(), DISTPTS::mode, LWCURVEPOLY::nrings, DISTPTS::p1, DISTPTS::p2, LWPOINT::point, LWCURVEPOLY::rings, POINT2D::x, and POINT2D::y.

Referenced by lw_dist2d_distribute_bruteforce().

620 {
621  const POINT2D *p;
622  int i;
623 
624  p = getPoint2d_cp(point->point, 0);
625 
626  if (dl->mode == DIST_MAX)
627  lwerror("lw_dist2d_point_curvepoly cannot calculate max distance");
628 
629  /* Return distance to outer ring if not inside it */
630  if ( lwgeom_contains_point(poly->rings[0], p) == LW_OUTSIDE )
631  {
632  return lw_dist2d_recursive((LWGEOM*)point, poly->rings[0], dl);
633  }
634 
635  /*
636  * Inside the outer ring.
637  * Scan though each of the inner rings looking to
638  * see if its inside. If not, distance==0.
639  * Otherwise, distance = pt to ring distance
640  */
641  for ( i = 1; i < poly->nrings; i++)
642  {
643  /* Inside a hole. Distance = pt -> ring */
644  if ( lwgeom_contains_point(poly->rings[i], p) != LW_OUTSIDE )
645  {
646  LWDEBUG(3, " inside a hole");
647  return lw_dist2d_recursive((LWGEOM*)point, poly->rings[i], dl);
648  }
649  }
650 
651  LWDEBUG(3, " inside the polygon");
652  if (dl->mode == DIST_MIN)
653  {
654  dl->distance = 0.0;
655  dl->p1.x = dl->p2.x = p->x;
656  dl->p1.y = dl->p2.y = p->y;
657  }
658 
659  return LW_TRUE; /* Is inside the polygon */
660 }
LWGEOM ** rings
Definition: liblwgeom.h:491
int lw_dist2d_recursive(const LWGEOM *lwg1, const LWGEOM *lwg2, DISTPTS *dl)
This is a recursive function delivering every possible combinatin of subgeometries.
Definition: measures.c:237
#define DIST_MAX
int mode
Definition: measures.h:26
#define DIST_MIN
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:50
POINTARRAY * point
Definition: liblwgeom.h:367
POINT2D p1
Definition: measures.h:24
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:67
double x
Definition: liblwgeom.h:284
const POINT2D * getPoint2d_cp(const POINTARRAY *pa, int n)
Returns a POINT2D pointer into the POINTARRAY serialized_ptlist, suitable for reading from...
Definition: lwgeom_api.c:458
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:51
POINT2D p2
Definition: measures.h:25
double y
Definition: liblwgeom.h:284
double distance
Definition: measures.h:23
#define LW_OUTSIDE
int lwgeom_contains_point(const LWGEOM *geom, const POINT2D *pt)
Definition: lwcompound.c:116

Here is the call graph for this function:

Here is the caller graph for this function: