PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ lw_dist2d_point_curvepoly()

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

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

660 {
661  const POINT2D *p;
662  int i;
663 
664  p = getPoint2d_cp(point->point, 0);
665 
666  if (dl->mode == DIST_MAX)
667  lwerror("lw_dist2d_point_curvepoly cannot calculate max distance");
668 
669  /* Return distance to outer ring if not inside it */
670  if ( lwgeom_contains_point(poly->rings[0], p) == LW_OUTSIDE )
671  {
672  return lw_dist2d_recursive((LWGEOM*)point, poly->rings[0], dl);
673  }
674 
675  /*
676  * Inside the outer ring.
677  * Scan though each of the inner rings looking to
678  * see if its inside. If not, distance==0.
679  * Otherwise, distance = pt to ring distance
680  */
681  for ( i = 1; i < poly->nrings; i++)
682  {
683  /* Inside a hole. Distance = pt -> ring */
684  if ( lwgeom_contains_point(poly->rings[i], p) != LW_OUTSIDE )
685  {
686  LWDEBUG(3, " inside a hole");
687  return lw_dist2d_recursive((LWGEOM*)point, poly->rings[i], dl);
688  }
689  }
690 
691  LWDEBUG(3, " inside the polygon");
692  if (dl->mode == DIST_MIN)
693  {
694  dl->distance = 0.0;
695  dl->p1.x = dl->p2.x = p->x;
696  dl->p1.y = dl->p2.y = p->y;
697  }
698 
699  return LW_TRUE; /* Is inside the polygon */
700 }
LWGEOM ** rings
Definition: liblwgeom.h:535
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:277
int mode
Definition: measures.h:54
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:83
POINTARRAY * point
Definition: liblwgeom.h:411
POINT2D p1
Definition: measures.h:52
double x
Definition: liblwgeom.h:328
#define DIST_MIN
Definition: measures.h:44
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:373
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:76
POINT2D p2
Definition: measures.h:53
double y
Definition: liblwgeom.h:328
double distance
Definition: measures.h:51
#define DIST_MAX
Definition: measures.h:43
#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
Here is the call graph for this function:
Here is the caller graph for this function: