PostGIS  3.1.6dev-r@@SVN_REVISION@@

◆ lw_dist2d_curvepoly_curvepoly()

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

Definition at line 1049 of file measures.c.

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

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: