PostGIS  3.7.0dev-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 271 of file measures.c.

272 {
273  int i, j;
274  int n1 = 1;
275  int n2 = 1;
276  LWGEOM *g1 = NULL;
277  LWGEOM *g2 = NULL;
278  LWCOLLECTION *c1 = NULL;
279  LWCOLLECTION *c2 = NULL;
280 
281  LWDEBUGF(2, "lw_dist2d_comp is called with type1=%d, type2=%d", lwg1->type, lwg2->type);
282 
283  if (lw_dist2d_is_collection(lwg1))
284  {
285  LWDEBUG(3, "First geometry is collection");
286  c1 = lwgeom_as_lwcollection(lwg1);
287  n1 = c1->ngeoms;
288  }
289  if (lw_dist2d_is_collection(lwg2))
290  {
291  LWDEBUG(3, "Second geometry is collection");
292  c2 = lwgeom_as_lwcollection(lwg2);
293  n2 = c2->ngeoms;
294  }
295 
296  for (i = 0; i < n1; i++)
297  {
298 
299  if (lw_dist2d_is_collection(lwg1))
300  g1 = c1->geoms[i];
301  else
302  g1 = (LWGEOM *)lwg1;
303 
304  if (lwgeom_is_empty(g1))
305  continue;
306 
307  if (lw_dist2d_is_collection(g1))
308  {
309  LWDEBUG(3, "Found collection inside first geometry collection, recursing");
310  if (!lw_dist2d_recursive(g1, lwg2, dl))
311  return LW_FALSE;
312  continue;
313  }
314  for (j = 0; j < n2; j++)
315  {
316  if (lw_dist2d_is_collection(lwg2))
317  g2 = c2->geoms[j];
318  else
319  g2 = (LWGEOM *)lwg2;
320 
321  if (lw_dist2d_is_collection(g2))
322  {
323  LWDEBUG(3, "Found collection inside second geometry collection, recursing");
324  if (!lw_dist2d_recursive(g1, g2, dl))
325  return LW_FALSE;
326  continue;
327  }
328 
329  if (!g1->bbox)
330  lwgeom_add_bbox(g1);
331 
332  if (!g2->bbox)
333  lwgeom_add_bbox(g2);
334 
335  /* If one of geometries is empty, skip */
336  if (lwgeom_is_empty(g1) || lwgeom_is_empty(g2))
337  continue;
338 
339  if ((dl->mode != DIST_MAX) && (!lw_dist2d_check_overlap(g1, g2)) &&
340  (g1->type == LINETYPE || g1->type == POLYGONTYPE || g1->type == TRIANGLETYPE) &&
341  (g2->type == LINETYPE || g2->type == POLYGONTYPE || g2->type == TRIANGLETYPE))
342  {
343  if (!lw_dist2d_distribute_fast(g1, g2, dl))
344  return LW_FALSE;
345  }
346  else
347  {
348  if (!lw_dist2d_distribute_bruteforce(g1, g2, dl))
349  return LW_FALSE;
350  LWDEBUGF(2, "Distance so far: %.15g (%.15g tolerated)", dl->distance, dl->tolerance);
351  if (dl->distance <= dl->tolerance && dl->mode == DIST_MIN)
352  return LW_TRUE; /*just a check if the answer is already given*/
353  LWDEBUG(2, "Not below tolerance yet");
354  }
355  }
356  }
357  return LW_TRUE;
358 }
#define LW_FALSE
Definition: liblwgeom.h:94
#define LINETYPE
Definition: liblwgeom.h:103
#define POLYGONTYPE
Definition: liblwgeom.h:104
#define TRIANGLETYPE
Definition: liblwgeom.h:115
LWCOLLECTION * lwgeom_as_lwcollection(const LWGEOM *lwgeom)
Definition: lwgeom.c:233
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:93
void lwgeom_add_bbox(LWGEOM *lwgeom)
Compute a bbox if not already computed.
Definition: lwgeom.c:695
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:101
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:106
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:199
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:271
static int lw_dist2d_is_collection(const LWGEOM *g)
Definition: measures.c:245
int lw_dist2d_distribute_bruteforce(const LWGEOM *lwg1, const LWGEOM *lwg2, DISTPTS *dl)
Definition: measures.c:361
int lw_dist2d_distribute_fast(LWGEOM *lwg1, LWGEOM *lwg2, DISTPTS *dl)
Geometries are distributed for the new faster distance-calculations.
Definition: measures.c:543
int lw_dist2d_check_overlap(LWGEOM *lwg1, LWGEOM *lwg2)
Definition: measures.c:522
#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:580
LWGEOM ** geoms
Definition: liblwgeom.h:575
uint8_t type
Definition: liblwgeom.h:462
GBOX * bbox
Definition: liblwgeom.h:458

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: