PostGIS  2.5.0beta2dev-r@@SVN_REVISION@@

◆ lw_dist2d_point_curvepoly()

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

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

664 {
665  const POINT2D *p;
666  uint32_t i;
667 
668  p = getPoint2d_cp(point->point, 0);
669 
670  if (dl->mode == DIST_MAX)
671  lwerror("lw_dist2d_point_curvepoly cannot calculate max distance");
672 
673  /* Return distance to outer ring if not inside it */
674  if ( lwgeom_contains_point(poly->rings[0], p) == LW_OUTSIDE )
675  {
676  return lw_dist2d_recursive((LWGEOM*)point, poly->rings[0], dl);
677  }
678 
679  /*
680  * Inside the outer ring.
681  * Scan though each of the inner rings looking to
682  * see if its inside. If not, distance==0.
683  * Otherwise, distance = pt to ring distance
684  */
685  for ( i = 1; i < poly->nrings; i++)
686  {
687  /* Inside a hole. Distance = pt -> ring */
688  if ( lwgeom_contains_point(poly->rings[i], p) != LW_OUTSIDE )
689  {
690  LWDEBUG(3, " inside a hole");
691  return lw_dist2d_recursive((LWGEOM*)point, poly->rings[i], dl);
692  }
693  }
694 
695  LWDEBUG(3, " inside the polygon");
696  if (dl->mode == DIST_MIN)
697  {
698  dl->distance = 0.0;
699  dl->p1.x = dl->p2.x = p->x;
700  dl->p1.y = dl->p2.y = p->y;
701  }
702 
703  return LW_TRUE; /* Is inside the polygon */
704 }
LWGEOM ** rings
Definition: liblwgeom.h:537
int lw_dist2d_recursive(const LWGEOM *lwg1, const LWGEOM *lwg2, DISTPTS *dl)
This is a recursive function delivering every possible combination of subgeometries.
Definition: measures.c:277
int mode
Definition: measures.h:51
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:83
POINTARRAY * point
Definition: liblwgeom.h:413
POINT2D p1
Definition: measures.h:49
unsigned int uint32_t
Definition: uthash.h:78
double x
Definition: liblwgeom.h:330
#define DIST_MIN
Definition: measures.h:41
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:75
POINT2D p2
Definition: measures.h:50
double y
Definition: liblwgeom.h:330
double distance
Definition: measures.h:48
#define DIST_MAX
Definition: measures.h:40
uint32_t nrings
Definition: liblwgeom.h:535
#define LW_OUTSIDE
int lwgeom_contains_point(const LWGEOM *geom, const POINT2D *pt)
Definition: lwcompound.c:129
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:190
const POINT2D * getPoint2d_cp(const POINTARRAY *pa, uint32_t n)
Returns a POINT2D pointer into the POINTARRAY serialized_ptlist, suitable for reading from...
Definition: lwgeom_api.c:364
Here is the call graph for this function:
Here is the caller graph for this function: