PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ lw_dist2d_curvepoly_curvepoly()

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

Definition at line 1068 of file measures.c.

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

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: