PostGIS  3.1.6dev-r@@SVN_REVISION@@

◆ lw_dist2d_tri_poly()

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

Definition at line 830 of file measures.c.

831 {
832  POINTARRAY *pa = tri->points;
833  const POINT2D *pt = getPoint2d_cp(pa, 0);
834 
835  /* If we are looking for maxdistance, just check the outer rings.*/
836  if (dl->mode == DIST_MAX)
837  return lw_dist2d_ptarray_ptarray(pa, poly->rings[0], dl);
838 
839  /* Triangle has a point outside poly. Check distance to outer ring only. */
840  if (ptarray_contains_point(poly->rings[0], pt) == LW_OUTSIDE)
841  {
842  if (!lw_dist2d_ptarray_ptarray(pa, poly->rings[0], dl))
843  return LW_FALSE;
844 
845  /* just a check if the answer is already given */
846  if (dl->distance <= dl->tolerance)
847  return LW_TRUE;
848 
849  /* Maybe poly is inside triangle? */
850  const POINT2D *pt2 = getPoint2d_cp(poly->rings[0], 0);
851  if (ptarray_contains_point(pa, pt2) != LW_OUTSIDE)
852  {
853  lw_dist2d_distpts_set(dl, 0.0, pt2, pt2);
854  return LW_TRUE;
855  }
856  }
857 
858  for (uint32_t i = 1; i < poly->nrings; i++)
859  {
860  if (!lw_dist2d_ptarray_ptarray(pa, poly->rings[i], dl))
861  return LW_FALSE;
862 
863  /* just a check if the answer is already given */
864  if (dl->distance <= dl->tolerance && dl->mode == DIST_MIN)
865  return LW_TRUE;
866  }
867 
868  /* It's inside a hole, then the actual distance is the min ring distance */
869  for (uint32_t i = 1; i < poly->nrings; i++)
870  if (ptarray_contains_point(poly->rings[i], pt) != LW_OUTSIDE)
871  return LW_TRUE;
872 
873  /* Not in hole, so inside polygon */
874  lw_dist2d_distpts_set(dl, 0.0, pt, pt);
875  return LW_TRUE;
876 }
#define LW_FALSE
Definition: liblwgeom.h:108
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:107
int ptarray_contains_point(const POINTARRAY *pa, const POINT2D *pt)
Return 1 if the point is inside the POINTARRAY, -1 if it is outside, and 0 if it is on the boundary.
Definition: ptarray.c:740
#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:101
static void lw_dist2d_distpts_set(DISTPTS *dl, double distance, const POINT2D *p1, const POINT2D *p2)
Definition: measures.c:78
int lw_dist2d_ptarray_ptarray(POINTARRAY *l1, POINTARRAY *l2, DISTPTS *dl)
test each segment of l1 against each segment of l2.
Definition: measures.c:1186
#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:533
uint32_t nrings
Definition: liblwgeom.h:538
POINTARRAY * points
Definition: liblwgeom.h:509

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: