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

Definition at line 930 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().

931 {
932  const POINT2D *pt;
933  int i;
934 
935  LWDEBUG(2, "lw_dist2d_curvepoly_curvepoly called");
936 
937  /*1 if we are looking for maxdistance, just check the outer rings.*/
938  if (dl->mode == DIST_MAX)
939  {
940  return lw_dist2d_recursive(poly1->rings[0], poly2->rings[0], dl);
941  }
942 
943 
944  /* 2 check if poly1 has first point outside poly2 and vice versa, if so, just check outer rings
945  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.*/
946  pt = lw_curvering_getfirstpoint2d_cp(poly1->rings[0]);
947  if ( lwgeom_contains_point(poly2->rings[0], pt) == LW_OUTSIDE )
948  {
949  pt = lw_curvering_getfirstpoint2d_cp(poly2->rings[0]);
950  if ( lwgeom_contains_point(poly1->rings[0], pt) == LW_OUTSIDE )
951  {
952  return lw_dist2d_recursive(poly1->rings[0], poly2->rings[0], dl);
953  }
954  }
955 
956  /*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*/
957  pt = lw_curvering_getfirstpoint2d_cp(poly2->rings[0]);
958  for (i = 1; i < poly1->nrings; i++)
959  {
960  /* Inside a hole */
961  if ( lwgeom_contains_point(poly1->rings[i], pt) != LW_OUTSIDE )
962  {
963  return lw_dist2d_recursive(poly1->rings[i], poly2->rings[0], dl);
964  }
965  }
966 
967  /*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*/
968  pt = lw_curvering_getfirstpoint2d_cp(poly1->rings[0]);
969  for (i = 1; i < poly2->nrings; i++)
970  {
971  /* Inside a hole */
972  if ( lwgeom_contains_point(poly2->rings[i], pt) != LW_OUTSIDE )
973  {
974  return lw_dist2d_recursive(poly1->rings[0], poly2->rings[i], dl);
975  }
976  }
977 
978 
979  /*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.*/
980  pt = lw_curvering_getfirstpoint2d_cp(poly1->rings[0]);
981  if ( lwgeom_contains_point(poly2->rings[0], pt) != LW_OUTSIDE )
982  {
983  dl->distance = 0.0;
984  dl->p1.x = dl->p2.x = pt->x;
985  dl->p1.y = dl->p2.y = pt->y;
986  return LW_TRUE;
987  }
988 
989  pt = lw_curvering_getfirstpoint2d_cp(poly2->rings[0]);
990  if ( lwgeom_contains_point(poly1->rings[0], pt) != LW_OUTSIDE )
991  {
992  dl->distance = 0.0;
993  dl->p1.x = dl->p2.x = pt->x;
994  dl->p1.y = dl->p2.y = pt->y;
995  return LW_TRUE;
996  }
997 
998  lwerror("Unspecified error in function lw_dist2d_curvepoly_curvepoly");
999  return LW_FALSE;
1000 }
LWGEOM ** rings
Definition: liblwgeom.h:491
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:237
#define DIST_MAX
int mode
Definition: measures.h:26
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:50
POINT2D p1
Definition: measures.h:24
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:67
double x
Definition: liblwgeom.h:284
#define LW_FALSE
Definition: liblwgeom.h:52
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:51
POINT2D p2
Definition: measures.h:25
double y
Definition: liblwgeom.h:284
double distance
Definition: measures.h:23
static const POINT2D * lw_curvering_getfirstpoint2d_cp(LWGEOM *geom)
Definition: measures.c:909
#define LW_OUTSIDE
int lwgeom_contains_point(const LWGEOM *geom, const POINT2D *pt)
Definition: lwcompound.c:116

Here is the call graph for this function:

Here is the caller graph for this function: