PostGIS  3.0.6dev-r@@SVN_REVISION@@

◆ lw_dist2d_tri_poly()

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

Definition at line 834 of file measures.c.

835 {
836  POINTARRAY *pa = tri->points;
837  const POINT2D *pt = getPoint2d_cp(pa, 0);
838 
839  /* If we are looking for maxdistance, just check the outer rings.*/
840  if (dl->mode == DIST_MAX)
841  return lw_dist2d_ptarray_ptarray(pa, poly->rings[0], dl);
842 
843  /* Triangle has a point outside poly. Check distance to outer ring only. */
844  if (ptarray_contains_point(poly->rings[0], pt) == LW_OUTSIDE)
845  {
846  if (!lw_dist2d_ptarray_ptarray(pa, poly->rings[0], dl))
847  return LW_FALSE;
848 
849  /* just a check if the answer is already given */
850  if (dl->distance <= dl->tolerance)
851  return LW_TRUE;
852 
853  /* Maybe poly is inside triangle? */
854  const POINT2D *pt2 = getPoint2d_cp(poly->rings[0], 0);
855  if (ptarray_contains_point(pa, pt2) != LW_OUTSIDE)
856  {
857  dl->distance = 0.0;
858  dl->p1.x = dl->p2.x = pt2->x;
859  dl->p1.y = dl->p2.y = pt2->y;
860  return LW_TRUE;
861  }
862  }
863 
864  for (uint32_t i = 1; i < poly->nrings; i++)
865  {
866  if (!lw_dist2d_ptarray_ptarray(pa, poly->rings[i], dl))
867  return LW_FALSE;
868 
869  /* just a check if the answer is already given */
870  if (dl->distance <= dl->tolerance && dl->mode == DIST_MIN)
871  return LW_TRUE;
872  }
873 
874  /* It's inside a hole, then the actual distance is the min ring distance */
875  for (uint32_t i = 1; i < poly->nrings; i++)
876  if (ptarray_contains_point(poly->rings[i], pt) != LW_OUTSIDE)
877  return LW_TRUE;
878 
879  /* Not in hole, so inside polygon */
880  dl->distance = 0.0;
881  dl->p1.x = dl->p2.x = pt->x;
882  dl->p1.y = dl->p2.y = pt->y;
883  return LW_TRUE;
884 }
#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:732
#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:91
int lw_dist2d_ptarray_ptarray(POINTARRAY *l1, POINTARRAY *l2, DISTPTS *dl)
test each segment of l1 against each segment of l2.
Definition: measures.c:1208
#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
POINTARRAY ** rings
Definition: liblwgeom.h:505
uint32_t nrings
Definition: liblwgeom.h:510
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_dist2d_ptarray_ptarray(), LW_FALSE, LW_OUTSIDE, LW_TRUE, DISTPTS::mode, LWPOLY::nrings, DISTPTS::p1, DISTPTS::p2, LWTRIANGLE::points, ptarray_contains_point(), LWPOLY::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: