PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ lw_dist2d_curvepoly_curvepoly()

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

Definition at line 970 of file measures.c.

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

971 {
972  const POINT2D *pt;
973  int i;
974 
975  LWDEBUG(2, "lw_dist2d_curvepoly_curvepoly called");
976 
977  /*1 if we are looking for maxdistance, just check the outer rings.*/
978  if (dl->mode == DIST_MAX)
979  {
980  return lw_dist2d_recursive(poly1->rings[0], poly2->rings[0], dl);
981  }
982 
983 
984  /* 2 check if poly1 has first point outside poly2 and vice versa, if so, just check outer rings
985  here it would be possible to handle the information about wich one is inside wich one and only search for the smaller ones in the bigger ones holes.*/
986  pt = lw_curvering_getfirstpoint2d_cp(poly1->rings[0]);
987  if ( lwgeom_contains_point(poly2->rings[0], pt) == LW_OUTSIDE )
988  {
989  pt = lw_curvering_getfirstpoint2d_cp(poly2->rings[0]);
990  if ( lwgeom_contains_point(poly1->rings[0], pt) == LW_OUTSIDE )
991  {
992  return lw_dist2d_recursive(poly1->rings[0], poly2->rings[0], dl);
993  }
994  }
995 
996  /*3 check if first point of poly2 is in a hole of poly1. If so check outer ring of poly2 against that hole of poly1*/
997  pt = lw_curvering_getfirstpoint2d_cp(poly2->rings[0]);
998  for (i = 1; i < poly1->nrings; i++)
999  {
1000  /* Inside a hole */
1001  if ( lwgeom_contains_point(poly1->rings[i], pt) != LW_OUTSIDE )
1002  {
1003  return lw_dist2d_recursive(poly1->rings[i], poly2->rings[0], dl);
1004  }
1005  }
1006 
1007  /*4 check if first point of poly1 is in a hole of poly2. If so check outer ring of poly1 against that hole of poly2*/
1008  pt = lw_curvering_getfirstpoint2d_cp(poly1->rings[0]);
1009  for (i = 1; i < poly2->nrings; i++)
1010  {
1011  /* Inside a hole */
1012  if ( lwgeom_contains_point(poly2->rings[i], pt) != LW_OUTSIDE )
1013  {
1014  return lw_dist2d_recursive(poly1->rings[0], poly2->rings[i], dl);
1015  }
1016  }
1017 
1018 
1019  /*5 If we have come all the way here we know that the first point of one of them is inside the other ones outer ring and not in holes so we check wich one is inside.*/
1020  pt = lw_curvering_getfirstpoint2d_cp(poly1->rings[0]);
1021  if ( lwgeom_contains_point(poly2->rings[0], pt) != LW_OUTSIDE )
1022  {
1023  dl->distance = 0.0;
1024  dl->p1.x = dl->p2.x = pt->x;
1025  dl->p1.y = dl->p2.y = pt->y;
1026  return LW_TRUE;
1027  }
1028 
1029  pt = lw_curvering_getfirstpoint2d_cp(poly2->rings[0]);
1030  if ( lwgeom_contains_point(poly1->rings[0], pt) != LW_OUTSIDE )
1031  {
1032  dl->distance = 0.0;
1033  dl->p1.x = dl->p2.x = pt->x;
1034  dl->p1.y = dl->p2.y = pt->y;
1035  return LW_TRUE;
1036  }
1037 
1038  lwerror("Unspecified error in function lw_dist2d_curvepoly_curvepoly");
1039  return LW_FALSE;
1040 }
LWGEOM ** rings
Definition: liblwgeom.h:535
int lw_dist2d_recursive(const LWGEOM *lwg1, const LWGEOM *lwg2, DISTPTS *dl)
This is a recursive function delivering every possible combinatin of subgeometries.
Definition: measures.c:277
int mode
Definition: measures.h:54
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:83
POINT2D p1
Definition: measures.h:52
double x
Definition: liblwgeom.h:328
#define LW_FALSE
Definition: liblwgeom.h:77
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:76
POINT2D p2
Definition: measures.h:53
double y
Definition: liblwgeom.h:328
double distance
Definition: measures.h:51
#define DIST_MAX
Definition: measures.h:43
static const POINT2D * lw_curvering_getfirstpoint2d_cp(LWGEOM *geom)
Definition: measures.c:949
#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
Here is the call graph for this function:
Here is the caller graph for this function: