PostGIS  2.2.7dev-r@@SVN_REVISION@@
 int lw_dist2d_curvepoly_curvepoly ( LWCURVEPOLY * poly1, LWCURVEPOLY * poly2, DISTPTS * dl )

Definition at line 956 of file measures.c.

Referenced by lw_dist2d_distribute_bruteforce(), and lw_dist2d_poly_curvepoly().

957 {
958  const POINT2D *pt;
959  int i;
960
961  LWDEBUG(2, "lw_dist2d_curvepoly_curvepoly called");
962
963  /*1 if we are looking for maxdistance, just check the outer rings.*/
964  if (dl->mode == DIST_MAX)
965  {
966  return lw_dist2d_recursive(poly1->rings[0], poly2->rings[0], dl);
967  }
968
969
970  /* 2 check if poly1 has first point outside poly2 and vice versa, if so, just check outer rings
971  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.*/
972  pt = lw_curvering_getfirstpoint2d_cp(poly1->rings[0]);
973  if ( lwgeom_contains_point(poly2->rings[0], pt) == LW_OUTSIDE )
974  {
975  pt = lw_curvering_getfirstpoint2d_cp(poly2->rings[0]);
976  if ( lwgeom_contains_point(poly1->rings[0], pt) == LW_OUTSIDE )
977  {
978  return lw_dist2d_recursive(poly1->rings[0], poly2->rings[0], dl);
979  }
980  }
981
982  /*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*/
983  pt = lw_curvering_getfirstpoint2d_cp(poly2->rings[0]);
984  for (i = 1; i < poly1->nrings; i++)
985  {
986  /* Inside a hole */
987  if ( lwgeom_contains_point(poly1->rings[i], pt) != LW_OUTSIDE )
988  {
989  return lw_dist2d_recursive(poly1->rings[i], poly2->rings[0], dl);
990  }
991  }
992
993  /*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*/
994  pt = lw_curvering_getfirstpoint2d_cp(poly1->rings[0]);
995  for (i = 1; i < poly2->nrings; i++)
996  {
997  /* Inside a hole */
998  if ( lwgeom_contains_point(poly2->rings[i], pt) != LW_OUTSIDE )
999  {
1000  return lw_dist2d_recursive(poly1->rings[0], poly2->rings[i], dl);
1001  }
1002  }
1003
1004
1005  /*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.*/
1006  pt = lw_curvering_getfirstpoint2d_cp(poly1->rings[0]);
1007  if ( lwgeom_contains_point(poly2->rings[0], pt) != LW_OUTSIDE )
1008  {
1009  dl->distance = 0.0;
1010  dl->p1.x = dl->p2.x = pt->x;
1011  dl->p1.y = dl->p2.y = pt->y;
1012  return LW_TRUE;
1013  }
1014
1015  pt = lw_curvering_getfirstpoint2d_cp(poly2->rings[0]);
1016  if ( lwgeom_contains_point(poly1->rings[0], pt) != LW_OUTSIDE )
1017  {
1018  dl->distance = 0.0;
1019  dl->p1.x = dl->p2.x = pt->x;
1020  dl->p1.y = dl->p2.y = pt->y;
1021  return LW_TRUE;
1022  }
1023
1024  lwerror("Unspecified error in function lw_dist2d_curvepoly_curvepoly");
1025  return LW_FALSE;
1026 }
LWGEOM ** rings
Definition: liblwgeom.h:519
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:263
int mode
Definition: measures.h:27
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:50
POINT2D p1
Definition: measures.h:25
double x
Definition: liblwgeom.h:312
#define LW_FALSE
Definition: liblwgeom.h:62
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:61
POINT2D p2
Definition: measures.h:26
double y
Definition: liblwgeom.h:312
double distance
Definition: measures.h:24
#define DIST_MAX
Definition: measures.h:16
static const POINT2D * lw_curvering_getfirstpoint2d_cp(LWGEOM *geom)
Definition: measures.c:935
#define LW_OUTSIDE
int lwgeom_contains_point(const LWGEOM *geom, const POINT2D *pt)
Definition: lwcompound.c:116
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:74

Here is the call graph for this function:

Here is the caller graph for this function: