PostGIS  2.5.0dev-r@@SVN_REVISION@@

◆ lw_dist2d_curvepoly_curvepoly()

int lw_dist2d_curvepoly_curvepoly ( LWCURVEPOLY poly1,
LWCURVEPOLY poly2,
DISTPTS dl 
)

Definition at line 974 of file measures.c.

References DIST_MAX, DISTPTS::distance, lw_curvering_getfirstpoint2d_cp(), lw_dist2d_recursive(), LW_FALSE, LW_OUTSIDE, LW_TRUE, LWDEBUG, lwerror(), lwgeom_contains_point(), DISTPTS::mode, LWCURVEPOLY::nrings, DISTPTS::p1, DISTPTS::p2, LWCURVEPOLY::rings, POINT2D::x, and POINT2D::y.

Referenced by lw_dist2d_distribute_bruteforce(), and lw_dist2d_poly_curvepoly().

975 {
976  const POINT2D *pt;
977  uint32_t i;
978 
979  LWDEBUG(2, "lw_dist2d_curvepoly_curvepoly called");
980 
981  /*1 if we are looking for maxdistance, just check the outer rings.*/
982  if (dl->mode == DIST_MAX)
983  {
984  return lw_dist2d_recursive(poly1->rings[0], poly2->rings[0], dl);
985  }
986 
987 
988  /* 2 check if poly1 has first point outside poly2 and vice versa, if so, just check outer rings
989  here it would be possible to handle the information about which one is inside which one and only search for the smaller ones in the bigger ones holes.*/
990  pt = lw_curvering_getfirstpoint2d_cp(poly1->rings[0]);
991  if ( lwgeom_contains_point(poly2->rings[0], pt) == LW_OUTSIDE )
992  {
993  pt = lw_curvering_getfirstpoint2d_cp(poly2->rings[0]);
994  if ( lwgeom_contains_point(poly1->rings[0], pt) == LW_OUTSIDE )
995  {
996  return lw_dist2d_recursive(poly1->rings[0], poly2->rings[0], dl);
997  }
998  }
999 
1000  /*3 check if first point of poly2 is in a hole of poly1. If so check outer ring of poly2 against that hole of poly1*/
1001  pt = lw_curvering_getfirstpoint2d_cp(poly2->rings[0]);
1002  for (i = 1; i < poly1->nrings; i++)
1003  {
1004  /* Inside a hole */
1005  if ( lwgeom_contains_point(poly1->rings[i], pt) != LW_OUTSIDE )
1006  {
1007  return lw_dist2d_recursive(poly1->rings[i], poly2->rings[0], dl);
1008  }
1009  }
1010 
1011  /*4 check if first point of poly1 is in a hole of poly2. If so check outer ring of poly1 against that hole of poly2*/
1012  pt = lw_curvering_getfirstpoint2d_cp(poly1->rings[0]);
1013  for (i = 1; i < poly2->nrings; i++)
1014  {
1015  /* Inside a hole */
1016  if ( lwgeom_contains_point(poly2->rings[i], pt) != LW_OUTSIDE )
1017  {
1018  return lw_dist2d_recursive(poly1->rings[0], poly2->rings[i], dl);
1019  }
1020  }
1021 
1022 
1023  /*5 If we have come all the way here we know that the first point of one of them is inside the other ones outer ring and not in holes so we check which one is inside.*/
1024  pt = lw_curvering_getfirstpoint2d_cp(poly1->rings[0]);
1025  if ( lwgeom_contains_point(poly2->rings[0], pt) != LW_OUTSIDE )
1026  {
1027  dl->distance = 0.0;
1028  dl->p1.x = dl->p2.x = pt->x;
1029  dl->p1.y = dl->p2.y = pt->y;
1030  return LW_TRUE;
1031  }
1032 
1033  pt = lw_curvering_getfirstpoint2d_cp(poly2->rings[0]);
1034  if ( lwgeom_contains_point(poly1->rings[0], pt) != LW_OUTSIDE )
1035  {
1036  dl->distance = 0.0;
1037  dl->p1.x = dl->p2.x = pt->x;
1038  dl->p1.y = dl->p2.y = pt->y;
1039  return LW_TRUE;
1040  }
1041 
1042  lwerror("Unspecified error in function lw_dist2d_curvepoly_curvepoly");
1043  return LW_FALSE;
1044 }
LWGEOM ** rings
Definition: liblwgeom.h:537
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:277
int mode
Definition: measures.h:51
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:83
POINT2D p1
Definition: measures.h:49
unsigned int uint32_t
Definition: uthash.h:78
double x
Definition: liblwgeom.h:330
#define LW_FALSE
Definition: liblwgeom.h:76
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:75
POINT2D p2
Definition: measures.h:50
double y
Definition: liblwgeom.h:330
double distance
Definition: measures.h:48
#define DIST_MAX
Definition: measures.h:40
static const POINT2D * lw_curvering_getfirstpoint2d_cp(LWGEOM *geom)
Definition: measures.c:953
uint32_t nrings
Definition: liblwgeom.h:535
#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: