PostGIS  2.2.7dev-r@@SVN_REVISION@@
int lw_dist3d_recursive ( const LWGEOM lwg1,
const LWGEOM lwg2,
DISTPTS3D dl 
)

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

Definition at line 375 of file measures3d.c.

References DIST_MIN, DISTPTS3D::distance, LWCOLLECTION::geoms, lw_dist3d_distribute_bruteforce(), lw_dist3d_recursive(), LW_FALSE, LW_TRUE, LWDEBUG, LWDEBUGF, lwgeom_as_lwcollection(), lwgeom_is_collection(), lwgeom_is_empty(), DISTPTS3D::mode, LWCOLLECTION::ngeoms, DISTPTS3D::tolerance, and LWGEOM::type.

Referenced by lw_dist3d_distanceline(), lw_dist3d_distancepoint(), lw_dist3d_recursive(), lwgeom_maxdistance3d_tolerance(), and lwgeom_mindistance3d_tolerance().

376 {
377  int i, j;
378  int n1=1;
379  int n2=1;
380  LWGEOM *g1 = NULL;
381  LWGEOM *g2 = NULL;
382  LWCOLLECTION *c1 = NULL;
383  LWCOLLECTION *c2 = NULL;
384 
385  LWDEBUGF(2, "lw_dist3d_recursive is called with type1=%d, type2=%d", lwg1->type, lwg2->type);
386 
387  if (lwgeom_is_collection(lwg1))
388  {
389  LWDEBUG(3, "First geometry is collection");
390  c1 = lwgeom_as_lwcollection(lwg1);
391  n1 = c1->ngeoms;
392  }
393  if (lwgeom_is_collection(lwg2))
394  {
395  LWDEBUG(3, "Second geometry is collection");
396  c2 = lwgeom_as_lwcollection(lwg2);
397  n2 = c2->ngeoms;
398  }
399 
400  for ( i = 0; i < n1; i++ )
401  {
402 
403  if (lwgeom_is_collection(lwg1))
404  {
405  g1 = c1->geoms[i];
406  }
407  else
408  {
409  g1 = (LWGEOM*)lwg1;
410  }
411 
412  if (lwgeom_is_empty(g1)) return LW_TRUE;
413 
414  if (lwgeom_is_collection(g1))
415  {
416  LWDEBUG(3, "Found collection inside first geometry collection, recursing");
417  if (!lw_dist3d_recursive(g1, lwg2, dl)) return LW_FALSE;
418  continue;
419  }
420  for ( j = 0; j < n2; j++ )
421  {
422  if (lwgeom_is_collection(lwg2))
423  {
424  g2 = c2->geoms[j];
425  }
426  else
427  {
428  g2 = (LWGEOM*)lwg2;
429  }
430  if (lwgeom_is_collection(g2))
431  {
432  LWDEBUG(3, "Found collection inside second geometry collection, recursing");
433  if (!lw_dist3d_recursive(g1, g2, dl)) return LW_FALSE;
434  continue;
435  }
436 
437 
438  /*If one of geometries is empty, return. True here only means continue searching. False would have stoped the process*/
439  if (lwgeom_is_empty(g1)||lwgeom_is_empty(g2)) return LW_TRUE;
440 
441 
442  if (!lw_dist3d_distribute_bruteforce(g1, g2, dl)) return LW_FALSE;
443  if (dl->distance<=dl->tolerance && dl->mode == DIST_MIN) return LW_TRUE; /*just a check if the answer is already given*/
444  }
445  }
446  return LW_TRUE;
447 }
double distance
Definition: measures3d.h:27
int lwgeom_is_collection(const LWGEOM *lwgeom)
Determine whether a LWGEOM can contain sub-geometries or not.
Definition: lwgeom.c:991
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:50
int lw_dist3d_distribute_bruteforce(const LWGEOM *lwg1, const LWGEOM *lwg2, DISTPTS3D *dl)
This function distributes the brute-force for 3D so far the only type, tasks depending on type...
Definition: measures3d.c:456
#define DIST_MIN
Definition: measures.h:17
#define LW_FALSE
Definition: liblwgeom.h:62
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:61
LWGEOM ** geoms
Definition: liblwgeom.h:493
int mode
Definition: measures3d.h:30
int lw_dist3d_recursive(const LWGEOM *lwg1, const LWGEOM *lwg2, DISTPTS3D *dl)
This is a recursive function delivering every possible combination of subgeometries.
Definition: measures3d.c:375
double tolerance
Definition: measures3d.h:32
LWCOLLECTION * lwgeom_as_lwcollection(const LWGEOM *lwgeom)
Definition: lwgeom.c:143
uint8_t type
Definition: liblwgeom.h:380
int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members) ...
Definition: lwgeom.c:1297
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:55

Here is the call graph for this function:

Here is the caller graph for this function: