PostGIS  3.0.6dev-r@@SVN_REVISION@@

◆ lw_dist2d_curvepoly_curvepoly()

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

Definition at line 1067 of file measures.c.

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

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: