PostGIS  3.6.1dev-r@@SVN_REVISION@@

◆ lw_dist2d_tri_poly()

int lw_dist2d_tri_poly ( LWTRIANGLE tri,
LWPOLY poly,
DISTPTS dl 
)

Definition at line 835 of file measures.c.

836 {
837  POINTARRAY *pa = tri->points;
838  const POINT2D *pt = getPoint2d_cp(pa, 0);
839 
840  /* If we are looking for maxdistance, just check the outer rings.*/
841  if (dl->mode == DIST_MAX)
842  return lw_dist2d_ptarray_ptarray(pa, poly->rings[0], dl);
843 
844  /* Triangle has a point outside poly. Check distance to outer ring only. */
845  if (ptarray_contains_point(poly->rings[0], pt) == LW_OUTSIDE)
846  {
847  if (!lw_dist2d_ptarray_ptarray(pa, poly->rings[0], dl))
848  return LW_FALSE;
849 
850  /* just a check if the answer is already given */
851  if (dl->distance <= dl->tolerance)
852  return LW_TRUE;
853 
854  /* Maybe poly is inside triangle? */
855  const POINT2D *pt2 = getPoint2d_cp(poly->rings[0], 0);
856  if (ptarray_contains_point(pa, pt2) != LW_OUTSIDE)
857  {
858  lw_dist2d_distpts_set(dl, 0.0, pt2, pt2);
859  return LW_TRUE;
860  }
861  }
862 
863  for (uint32_t i = 1; i < poly->nrings; i++)
864  {
865  if (!lw_dist2d_ptarray_ptarray(pa, poly->rings[i], dl))
866  return LW_FALSE;
867 
868  /* just a check if the answer is already given */
869  if (dl->distance <= dl->tolerance && dl->mode == DIST_MIN)
870  return LW_TRUE;
871  }
872 
873  /* It's inside a hole, then the actual distance is the min ring distance */
874  for (uint32_t i = 1; i < poly->nrings; i++)
875  if (ptarray_contains_point(poly->rings[i], pt) != LW_OUTSIDE)
876  return LW_TRUE;
877 
878  /* Not in hole, so inside polygon */
879  lw_dist2d_distpts_set(dl, 0.0, pt, pt);
880  return LW_TRUE;
881 }
#define LW_FALSE
Definition: liblwgeom.h:94
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:93
int ptarray_contains_point(const POINTARRAY *pa, const POINT2D *pt)
The following is based on the "Fast Winding Number Inclusion of a Point in a Polygon" algorithm by Da...
Definition: ptarray.c:755
#define LW_OUTSIDE
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:97
static void lw_dist2d_distpts_set(DISTPTS *dl, double distance, const POINT2D *p1, const POINT2D *p2)
Definition: measures.c:81
int lw_dist2d_ptarray_ptarray(POINTARRAY *l1, POINTARRAY *l2, DISTPTS *dl)
test each segment of l1 against each segment of l2.
Definition: measures.c:1197
#define DIST_MIN
Definition: measures.h:44
#define DIST_MAX
Definition: measures.h:43
double tolerance
Definition: measures.h:56
int mode
Definition: measures.h:54
double distance
Definition: measures.h:51
POINTARRAY ** rings
Definition: liblwgeom.h:519
uint32_t nrings
Definition: liblwgeom.h:524
POINTARRAY * points
Definition: liblwgeom.h:495

References DIST_MAX, DIST_MIN, DISTPTS::distance, getPoint2d_cp(), lw_dist2d_distpts_set(), lw_dist2d_ptarray_ptarray(), LW_FALSE, LW_OUTSIDE, LW_TRUE, DISTPTS::mode, LWPOLY::nrings, LWTRIANGLE::points, ptarray_contains_point(), LWPOLY::rings, and DISTPTS::tolerance.

Referenced by lw_dist2d_distribute_bruteforce().

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