PostGIS  2.2.8dev-r@@SVN_REVISION@@

◆ lw_dist2d_point_curvepoly()

int lw_dist2d_point_curvepoly ( LWPOINT point,
LWCURVEPOLY poly,
DISTPTS dl 
)

Definition at line 645 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().

646 {
647  const POINT2D *p;
648  int i;
649 
650  p = getPoint2d_cp(point->point, 0);
651 
652  if (dl->mode == DIST_MAX)
653  lwerror("lw_dist2d_point_curvepoly cannot calculate max distance");
654 
655  /* Return distance to outer ring if not inside it */
656  if ( lwgeom_contains_point(poly->rings[0], p) == LW_OUTSIDE )
657  {
658  return lw_dist2d_recursive((LWGEOM*)point, poly->rings[0], dl);
659  }
660 
661  /*
662  * Inside the outer ring.
663  * Scan though each of the inner rings looking to
664  * see if its inside. If not, distance==0.
665  * Otherwise, distance = pt to ring distance
666  */
667  for ( i = 1; i < poly->nrings; i++)
668  {
669  /* Inside a hole. Distance = pt -> ring */
670  if ( lwgeom_contains_point(poly->rings[i], p) != LW_OUTSIDE )
671  {
672  LWDEBUG(3, " inside a hole");
673  return lw_dist2d_recursive((LWGEOM*)point, poly->rings[i], dl);
674  }
675  }
676 
677  LWDEBUG(3, " inside the polygon");
678  if (dl->mode == DIST_MIN)
679  {
680  dl->distance = 0.0;
681  dl->p1.x = dl->p2.x = p->x;
682  dl->p1.y = dl->p2.y = p->y;
683  }
684 
685  return LW_TRUE; /* Is inside the polygon */
686 }
LWGEOM ** rings
Definition: liblwgeom.h:519
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:263
int mode
Definition: measures.h:27
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:50
POINTARRAY * point
Definition: liblwgeom.h:395
POINT2D p1
Definition: measures.h:25
double x
Definition: liblwgeom.h:312
#define DIST_MIN
Definition: measures.h:17
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:472
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:61
POINT2D p2
Definition: measures.h:26
double y
Definition: liblwgeom.h:312
double distance
Definition: measures.h:24
#define DIST_MAX
Definition: measures.h:16
#define LW_OUTSIDE
int lwgeom_contains_point(const LWGEOM *geom, const POINT2D *pt)
Definition: lwcompound.c:116
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:74
Here is the call graph for this function:
Here is the caller graph for this function: