PostGIS  3.6.1dev-r@@SVN_REVISION@@

◆ lw_dist2d_curvepoly_curvepoly()

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

Definition at line 1054 of file measures.c.

1055 {
1056  const POINT2D *pt;
1057 
1058  /*1 if we are looking for maxdistance, just check the outer rings.*/
1059  if (dl->mode == DIST_MAX)
1060  return lw_dist2d_recursive(poly1->rings[0], poly2->rings[0], dl);
1061 
1062  /* 2 check if poly1 has first point outside poly2 and vice versa, if so, just check outer rings
1063  here it would be possible to handle the information about which one is inside which one and only search for the
1064  smaller ones in the bigger ones holes.*/
1065  pt = lw_curvering_getfirstpoint2d_cp(poly1->rings[0]);
1066  if (lwgeom_contains_point(poly2->rings[0], pt) == LW_OUTSIDE)
1067  {
1068  pt = lw_curvering_getfirstpoint2d_cp(poly2->rings[0]);
1069  if (lwgeom_contains_point(poly1->rings[0], pt) == LW_OUTSIDE)
1070  return lw_dist2d_recursive(poly1->rings[0], poly2->rings[0], dl);
1071  }
1072 
1073  /*3 check if first point of poly2 is in a hole of poly1. If so check outer ring of poly2 against that hole
1074  * of poly1*/
1075  pt = lw_curvering_getfirstpoint2d_cp(poly2->rings[0]);
1076  for (uint32_t i = 1; i < poly1->nrings; i++)
1077  if (lwgeom_contains_point(poly1->rings[i], pt) != LW_OUTSIDE)
1078  return lw_dist2d_recursive(poly1->rings[i], poly2->rings[0], dl);
1079 
1080  /*4 check if first point of poly1 is in a hole of poly2. If so check outer ring of poly1 against that hole
1081  * of poly2*/
1082  pt = lw_curvering_getfirstpoint2d_cp(poly1->rings[0]);
1083  for (uint32_t i = 1; i < poly2->nrings; i++)
1084  if (lwgeom_contains_point(poly2->rings[i], pt) != LW_OUTSIDE)
1085  return lw_dist2d_recursive(poly1->rings[0], poly2->rings[i], dl);
1086 
1087  /*5 If we have come all the way here we know that the first point of one of them is inside the other ones
1088  * outer ring and not in holes so we check which one is inside.*/
1089  pt = lw_curvering_getfirstpoint2d_cp(poly1->rings[0]);
1090  if (lwgeom_contains_point(poly2->rings[0], pt) != LW_OUTSIDE)
1091  {
1092  lw_dist2d_distpts_set(dl, 0.0, pt, pt);
1093  return LW_TRUE;
1094  }
1095 
1096  pt = lw_curvering_getfirstpoint2d_cp(poly2->rings[0]);
1097  if (lwgeom_contains_point(poly1->rings[0], pt) != LW_OUTSIDE)
1098  {
1099  lw_dist2d_distpts_set(dl, 0.0, pt, pt);
1100  return LW_TRUE;
1101  }
1102 
1103  lwerror("Unspecified error in function lw_dist2d_curvepoly_curvepoly");
1104  return LW_FALSE;
1105 }
#define LW_FALSE
Definition: liblwgeom.h:94
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:93
#define LW_OUTSIDE
int lwgeom_contains_point(const LWGEOM *geom, const POINT2D *pt)
Definition: lwcompound.c:172
void void lwerror(const char *fmt,...) __attribute__((format(printf
Write a notice out to the error handler.
static void lw_dist2d_distpts_set(DISTPTS *dl, double distance, const POINT2D *p1, const POINT2D *p2)
Definition: measures.c:81
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:299
static const POINT2D * lw_curvering_getfirstpoint2d_cp(LWGEOM *geom)
Definition: measures.c:883
#define DIST_MAX
Definition: measures.h:43
int mode
Definition: measures.h:54
LWGEOM ** rings
Definition: liblwgeom.h:603
uint32_t nrings
Definition: liblwgeom.h:608

References DIST_MAX, lw_curvering_getfirstpoint2d_cp(), lw_dist2d_distpts_set(), lw_dist2d_recursive(), LW_FALSE, LW_OUTSIDE, LW_TRUE, lwerror(), lwgeom_contains_point(), DISTPTS::mode, LWCURVEPOLY::nrings, and LWCURVEPOLY::rings.

Referenced by lw_dist2d_distribute_bruteforce(), and lw_dist2d_poly_curvepoly().

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