PostGIS  3.1.6dev-r@@SVN_REVISION@@

◆ lw_dist2d_recursive()

int lw_dist2d_recursive ( const LWGEOM lwg1,
const LWGEOM lwg2,
DISTPTS dl 
)

This is a recursive function delivering every possible combination of subgeometries.

Definition at line 280 of file measures.c.

281 {
282  int i, j;
283  int n1 = 1;
284  int n2 = 1;
285  LWGEOM *g1 = NULL;
286  LWGEOM *g2 = NULL;
287  LWCOLLECTION *c1 = NULL;
288  LWCOLLECTION *c2 = NULL;
289 
290  LWDEBUGF(2, "lw_dist2d_comp is called with type1=%d, type2=%d", lwg1->type, lwg2->type);
291 
292  if (lw_dist2d_is_collection(lwg1))
293  {
294  LWDEBUG(3, "First geometry is collection");
295  c1 = lwgeom_as_lwcollection(lwg1);
296  n1 = c1->ngeoms;
297  }
298  if (lw_dist2d_is_collection(lwg2))
299  {
300  LWDEBUG(3, "Second geometry is collection");
301  c2 = lwgeom_as_lwcollection(lwg2);
302  n2 = c2->ngeoms;
303  }
304 
305  for (i = 0; i < n1; i++)
306  {
307 
308  if (lw_dist2d_is_collection(lwg1))
309  g1 = c1->geoms[i];
310  else
311  g1 = (LWGEOM *)lwg1;
312 
313  if (lwgeom_is_empty(g1))
314  continue;
315 
316  if (lw_dist2d_is_collection(g1))
317  {
318  LWDEBUG(3, "Found collection inside first geometry collection, recursing");
319  if (!lw_dist2d_recursive(g1, lwg2, dl))
320  return LW_FALSE;
321  continue;
322  }
323  for (j = 0; j < n2; j++)
324  {
325  if (lw_dist2d_is_collection(lwg2))
326  g2 = c2->geoms[j];
327  else
328  g2 = (LWGEOM *)lwg2;
329 
330  if (lw_dist2d_is_collection(g2))
331  {
332  LWDEBUG(3, "Found collection inside second geometry collection, recursing");
333  if (!lw_dist2d_recursive(g1, g2, dl))
334  return LW_FALSE;
335  continue;
336  }
337 
338  if (!g1->bbox)
339  lwgeom_add_bbox(g1);
340 
341  if (!g2->bbox)
342  lwgeom_add_bbox(g2);
343 
344  /* If one of geometries is empty, skip */
345  if (lwgeom_is_empty(g1) || lwgeom_is_empty(g2))
346  continue;
347 
348  if ((dl->mode != DIST_MAX) && (!lw_dist2d_check_overlap(g1, g2)) &&
349  (g1->type == LINETYPE || g1->type == POLYGONTYPE || g1->type == TRIANGLETYPE) &&
350  (g2->type == LINETYPE || g2->type == POLYGONTYPE || g2->type == TRIANGLETYPE))
351  {
352  if (!lw_dist2d_distribute_fast(g1, g2, dl))
353  return LW_FALSE;
354  }
355  else
356  {
357  if (!lw_dist2d_distribute_bruteforce(g1, g2, dl))
358  return LW_FALSE;
359  if (dl->distance <= dl->tolerance && dl->mode == DIST_MIN)
360  return LW_TRUE; /*just a check if the answer is already given*/
361  }
362  }
363  }
364  return LW_TRUE;
365 }
#define LW_FALSE
Definition: liblwgeom.h:108
#define LINETYPE
Definition: liblwgeom.h:117
#define POLYGONTYPE
Definition: liblwgeom.h:118
#define TRIANGLETYPE
Definition: liblwgeom.h:129
LWCOLLECTION * lwgeom_as_lwcollection(const LWGEOM *lwgeom)
Definition: lwgeom.c:216
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:107
void lwgeom_add_bbox(LWGEOM *lwgeom)
Compute a bbox if not already computed.
Definition: lwgeom.c:678
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:83
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:88
static int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members)
Definition: lwinline.h:203
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:280
static int lw_dist2d_is_collection(const LWGEOM *g)
Definition: measures.c:254
int lw_dist2d_distribute_bruteforce(const LWGEOM *lwg1, const LWGEOM *lwg2, DISTPTS *dl)
Definition: measures.c:368
int lw_dist2d_distribute_fast(LWGEOM *lwg1, LWGEOM *lwg2, DISTPTS *dl)
Geometries are distributed for the new faster distance-calculations.
Definition: measures.c:550
int lw_dist2d_check_overlap(LWGEOM *lwg1, LWGEOM *lwg2)
Definition: measures.c:529
#define DIST_MIN
Definition: measures.h:44
#define DIST_MAX
Definition: measures.h:43
double tolerance
Definition: measures.h:56
int mode
Definition: measures.h:54
double distance
Definition: measures.h:51
uint32_t ngeoms
Definition: liblwgeom.h:594
LWGEOM ** geoms
Definition: liblwgeom.h:589
uint8_t type
Definition: liblwgeom.h:476
GBOX * bbox
Definition: liblwgeom.h:472

References LWGEOM::bbox, DIST_MAX, DIST_MIN, DISTPTS::distance, LWCOLLECTION::geoms, LINETYPE, lw_dist2d_check_overlap(), lw_dist2d_distribute_bruteforce(), lw_dist2d_distribute_fast(), lw_dist2d_is_collection(), LW_FALSE, LW_TRUE, LWDEBUG, LWDEBUGF, lwgeom_add_bbox(), lwgeom_as_lwcollection(), lwgeom_is_empty(), DISTPTS::mode, LWCOLLECTION::ngeoms, POLYGONTYPE, DISTPTS::tolerance, TRIANGLETYPE, and LWGEOM::type.

Referenced by lw_dist2d_comp(), lw_dist2d_curvepoly_curvepoly(), lw_dist2d_line_curvepoly(), lw_dist2d_point_curvepoly(), and lw_dist2d_tri_curvepoly().

Here is the call graph for this function:
Here is the caller graph for this function: