PostGIS  3.0.6dev-r@@SVN_REVISION@@

◆ lw_dist2d_tri_curvepoly()

int lw_dist2d_tri_curvepoly ( LWTRIANGLE tri,
LWCURVEPOLY poly,
DISTPTS dl 
)

Definition at line 907 of file measures.c.

908 {
909  const POINT2D *pt = getPoint2d_cp(tri->points, 0);
910 
911  /* If we are looking for maxdistance, just check the outer rings.*/
912  if (dl->mode == DIST_MAX)
913  return lw_dist2d_recursive((LWGEOM *)tri, poly->rings[0], dl);
914 
915  /* Line has a pount outside curvepoly. Check distance to outer ring only. */
916  if (lwgeom_contains_point(poly->rings[0], pt) == LW_OUTSIDE)
917  {
918  if (lw_dist2d_recursive((LWGEOM *)tri, poly->rings[0], dl))
919  return LW_TRUE;
920  /* Maybe poly is inside triangle? */
922  {
923  dl->distance = 0.0;
924  dl->p1.x = dl->p2.x = pt->x;
925  dl->p1.y = dl->p2.y = pt->y;
926  return LW_TRUE;
927  }
928  }
929 
930  for (uint32_t i = 1; i < poly->nrings; i++)
931  {
932  if (!lw_dist2d_recursive((LWGEOM *)tri, poly->rings[i], dl))
933  return LW_FALSE;
934 
935  /* just a check if the answer is already given */
936  if (dl->distance <= dl->tolerance && dl->mode == DIST_MIN)
937  return LW_TRUE;
938  }
939 
940  /* It's inside a hole, then distance is actual min distance */
941  for (uint32_t i = 1; i < poly->nrings; i++)
942  if (lwgeom_contains_point(poly->rings[i], pt) != LW_OUTSIDE)
943  return LW_TRUE;
944 
945  /* Not in hole, so inside polygon */
946  dl->distance = 0.0;
947  dl->p1.x = dl->p2.x = pt->x;
948  dl->p1.y = dl->p2.y = pt->y;
949  return LW_TRUE;
950 }
#define LW_FALSE
Definition: liblwgeom.h:108
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:107
#define LW_OUTSIDE
int lwgeom_contains_point(const LWGEOM *geom, const POINT2D *pt)
Definition: lwcompound.c:129
static const POINT2D * getPoint2d_cp(const POINTARRAY *pa, uint32_t n)
Returns a POINT2D pointer into the POINTARRAY serialized_ptlist, suitable for reading from.
Definition: lwinline.h:91
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:268
static const POINT2D * lw_curvering_getfirstpoint2d_cp(LWGEOM *geom)
Definition: measures.c:886
#define DIST_MIN
Definition: measures.h:44
#define DIST_MAX
Definition: measures.h:43
POINT2D p1
Definition: measures.h:52
POINT2D p2
Definition: measures.h:53
double tolerance
Definition: measures.h:56
int mode
Definition: measures.h:54
double distance
Definition: measures.h:51
LWGEOM ** rings
Definition: liblwgeom.h:589
uint32_t nrings
Definition: liblwgeom.h:594
POINTARRAY * points
Definition: liblwgeom.h:481
double y
Definition: liblwgeom.h:376
double x
Definition: liblwgeom.h:376

References DIST_MAX, DIST_MIN, DISTPTS::distance, getPoint2d_cp(), lw_curvering_getfirstpoint2d_cp(), lw_dist2d_recursive(), LW_FALSE, LW_OUTSIDE, LW_TRUE, lwgeom_contains_point(), DISTPTS::mode, LWCURVEPOLY::nrings, DISTPTS::p1, DISTPTS::p2, LWTRIANGLE::points, LWCURVEPOLY::rings, DISTPTS::tolerance, POINT2D::x, and POINT2D::y.

Referenced by lw_dist2d_distribute_bruteforce().

Here is the call graph for this function:
Here is the caller graph for this function: