PostGIS  3.3.9dev-r@@SVN_REVISION@@

◆ lw_dist2d_curvepoly_curvepoly()

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

Definition at line 1072 of file measures.c.

1073 {
1074  const POINT2D *pt;
1075 
1076  /*1 if we are looking for maxdistance, just check the outer rings.*/
1077  if (dl->mode == DIST_MAX)
1078  return lw_dist2d_recursive(poly1->rings[0], poly2->rings[0], dl);
1079 
1080  /* 2 check if poly1 has first point outside poly2 and vice versa, if so, just check outer rings
1081  here it would be possible to handle the information about which one is inside which one and only search for the
1082  smaller ones in the bigger ones holes.*/
1083  pt = lw_curvering_getfirstpoint2d_cp(poly1->rings[0]);
1084  if (lwgeom_contains_point(poly2->rings[0], pt) == LW_OUTSIDE)
1085  {
1086  pt = lw_curvering_getfirstpoint2d_cp(poly2->rings[0]);
1087  if (lwgeom_contains_point(poly1->rings[0], pt) == LW_OUTSIDE)
1088  return lw_dist2d_recursive(poly1->rings[0], poly2->rings[0], dl);
1089  }
1090 
1091  /*3 check if first point of poly2 is in a hole of poly1. If so check outer ring of poly2 against that hole
1092  * of poly1*/
1093  pt = lw_curvering_getfirstpoint2d_cp(poly2->rings[0]);
1094  for (uint32_t i = 1; i < poly1->nrings; i++)
1095  if (lwgeom_contains_point(poly1->rings[i], pt) != LW_OUTSIDE)
1096  return lw_dist2d_recursive(poly1->rings[i], poly2->rings[0], dl);
1097 
1098  /*4 check if first point of poly1 is in a hole of poly2. If so check outer ring of poly1 against that hole
1099  * of poly2*/
1100  pt = lw_curvering_getfirstpoint2d_cp(poly1->rings[0]);
1101  for (uint32_t i = 1; i < poly2->nrings; i++)
1102  if (lwgeom_contains_point(poly2->rings[i], pt) != LW_OUTSIDE)
1103  return lw_dist2d_recursive(poly1->rings[0], poly2->rings[i], dl);
1104 
1105  /*5 If we have come all the way here we know that the first point of one of them is inside the other ones
1106  * outer ring and not in holes so we check which one is inside.*/
1107  pt = lw_curvering_getfirstpoint2d_cp(poly1->rings[0]);
1108  if (lwgeom_contains_point(poly2->rings[0], pt) != LW_OUTSIDE)
1109  {
1110  dl->distance = 0.0;
1111  dl->p1.x = dl->p2.x = pt->x;
1112  dl->p1.y = dl->p2.y = pt->y;
1113  return LW_TRUE;
1114  }
1115 
1116  pt = lw_curvering_getfirstpoint2d_cp(poly2->rings[0]);
1117  if (lwgeom_contains_point(poly1->rings[0], pt) != LW_OUTSIDE)
1118  {
1119  dl->distance = 0.0;
1120  dl->p1.x = dl->p2.x = pt->x;
1121  dl->p1.y = dl->p2.y = pt->y;
1122  return LW_TRUE;
1123  }
1124 
1125  lwerror("Unspecified error in function lw_dist2d_curvepoly_curvepoly");
1126  return LW_FALSE;
1127 }
#define LW_FALSE
Definition: liblwgeom.h:109
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:108
#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
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:271
static const POINT2D * lw_curvering_getfirstpoint2d_cp(LWGEOM *geom)
Definition: measures.c:891
#define DIST_MAX
Definition: measures.h:43
POINT2D p1
Definition: measures.h:52
POINT2D p2
Definition: measures.h:53
int mode
Definition: measures.h:54
double distance
Definition: measures.h:51
LWGEOM ** rings
Definition: liblwgeom.h:618
uint32_t nrings
Definition: liblwgeom.h:623
double y
Definition: liblwgeom.h:405
double x
Definition: liblwgeom.h:405

References DIST_MAX, DISTPTS::distance, lw_curvering_getfirstpoint2d_cp(), lw_dist2d_recursive(), LW_FALSE, LW_OUTSIDE, LW_TRUE, 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().

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