PostGIS  3.0.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 268 of file measures.c.

269 {
270  int i, j;
271  int n1 = 1;
272  int n2 = 1;
273  LWGEOM *g1 = NULL;
274  LWGEOM *g2 = NULL;
275  LWCOLLECTION *c1 = NULL;
276  LWCOLLECTION *c2 = NULL;
277 
278  LWDEBUGF(2, "lw_dist2d_comp is called with type1=%d, type2=%d", lwg1->type, lwg2->type);
279 
280  if (lw_dist2d_is_collection(lwg1))
281  {
282  LWDEBUG(3, "First geometry is collection");
283  c1 = lwgeom_as_lwcollection(lwg1);
284  n1 = c1->ngeoms;
285  }
286  if (lw_dist2d_is_collection(lwg2))
287  {
288  LWDEBUG(3, "Second geometry is collection");
289  c2 = lwgeom_as_lwcollection(lwg2);
290  n2 = c2->ngeoms;
291  }
292 
293  for (i = 0; i < n1; i++)
294  {
295 
296  if (lw_dist2d_is_collection(lwg1))
297  g1 = c1->geoms[i];
298  else
299  g1 = (LWGEOM *)lwg1;
300 
301  if (lwgeom_is_empty(g1))
302  continue;
303 
304  if (lw_dist2d_is_collection(g1))
305  {
306  LWDEBUG(3, "Found collection inside first geometry collection, recursing");
307  if (!lw_dist2d_recursive(g1, lwg2, dl))
308  return LW_FALSE;
309  continue;
310  }
311  for (j = 0; j < n2; j++)
312  {
313  if (lw_dist2d_is_collection(lwg2))
314  g2 = c2->geoms[j];
315  else
316  g2 = (LWGEOM *)lwg2;
317 
318  if (lw_dist2d_is_collection(g2))
319  {
320  LWDEBUG(3, "Found collection inside second geometry collection, recursing");
321  if (!lw_dist2d_recursive(g1, g2, dl))
322  return LW_FALSE;
323  continue;
324  }
325 
326  if (!g1->bbox)
327  lwgeom_add_bbox(g1);
328 
329  if (!g2->bbox)
330  lwgeom_add_bbox(g2);
331 
332  /* If one of geometries is empty, skip */
333  if (lwgeom_is_empty(g1) || lwgeom_is_empty(g2))
334  continue;
335 
336  if ((dl->mode != DIST_MAX) && (!lw_dist2d_check_overlap(g1, g2)) &&
337  (g1->type == LINETYPE || g1->type == POLYGONTYPE || g1->type == TRIANGLETYPE) &&
338  (g2->type == LINETYPE || g2->type == POLYGONTYPE || g2->type == TRIANGLETYPE))
339  {
340  if (!lw_dist2d_distribute_fast(g1, g2, dl))
341  return LW_FALSE;
342  }
343  else
344  {
345  if (!lw_dist2d_distribute_bruteforce(g1, g2, dl))
346  return LW_FALSE;
347  if (dl->distance <= dl->tolerance && dl->mode == DIST_MIN)
348  return LW_TRUE; /*just a check if the answer is already given*/
349  }
350  }
351  }
352  return LW_TRUE;
353 }
#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:215
#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:677
#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:193
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:268
static int lw_dist2d_is_collection(const LWGEOM *g)
Definition: measures.c:242
int lw_dist2d_distribute_bruteforce(const LWGEOM *lwg1, const LWGEOM *lwg2, DISTPTS *dl)
Definition: measures.c:356
int lw_dist2d_distribute_fast(LWGEOM *lwg1, LWGEOM *lwg2, DISTPTS *dl)
Geometries are distributed for the new faster distance-calculations.
Definition: measures.c:538
int lw_dist2d_check_overlap(LWGEOM *lwg1, LWGEOM *lwg2)
Definition: measures.c:517
#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:566
LWGEOM ** geoms
Definition: liblwgeom.h:561
uint8_t type
Definition: liblwgeom.h:448
GBOX * bbox
Definition: liblwgeom.h:444

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: