PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ lw_dist3d_recursive()

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 485 of file measures3d.c.

486 {
487  int i, j;
488  int n1 = 1;
489  int n2 = 1;
490  LWGEOM *g1 = NULL;
491  LWGEOM *g2 = NULL;
492  LWCOLLECTION *c1 = NULL;
493  LWCOLLECTION *c2 = NULL;
494 
495  LWDEBUGF(2, "lw_dist3d_recursive is called with type1=%d, type2=%d", lwg1->type, lwg2->type);
496 
497  if (lwgeom_is_collection(lwg1))
498  {
499  LWDEBUG(3, "First geometry is collection");
500  c1 = lwgeom_as_lwcollection(lwg1);
501  n1 = c1->ngeoms;
502  }
503  if (lwgeom_is_collection(lwg2))
504  {
505  LWDEBUG(3, "Second geometry is collection");
506  c2 = lwgeom_as_lwcollection(lwg2);
507  n2 = c2->ngeoms;
508  }
509 
510  for (i = 0; i < n1; i++)
511  {
512  if (lwgeom_is_collection(lwg1))
513  g1 = c1->geoms[i];
514  else
515  g1 = (LWGEOM *)lwg1;
516 
517  if (lwgeom_is_empty(g1))
518  return LW_TRUE;
519 
520  if (lwgeom_is_collection(g1))
521  {
522  LWDEBUG(3, "Found collection inside first geometry collection, recursing");
523  if (!lw_dist3d_recursive(g1, lwg2, dl))
524  return LW_FALSE;
525  continue;
526  }
527  for (j = 0; j < n2; j++)
528  {
529  if (lwgeom_is_collection(lwg2))
530  g2 = c2->geoms[j];
531  else
532  g2 = (LWGEOM *)lwg2;
533 
534  if (lwgeom_is_collection(g2))
535  {
536  LWDEBUG(3, "Found collection inside second geometry collection, recursing");
537  if (!lw_dist3d_recursive(g1, g2, dl))
538  return LW_FALSE;
539  continue;
540  }
541 
542  /*If one of geometries is empty, return. True here only means continue searching. False would
543  * have stopped the process*/
544  if (lwgeom_is_empty(g1) || lwgeom_is_empty(g2))
545  return LW_TRUE;
546 
547  if (!lw_dist3d_distribute_bruteforce(g1, g2, dl))
548  return LW_FALSE;
549  if (dl->distance <= dl->tolerance && dl->mode == DIST_MIN)
550  return LW_TRUE; /*just a check if the answer is already given*/
551  }
552  }
553  return LW_TRUE;
554 }
#define LW_FALSE
Definition: liblwgeom.h:94
int lwgeom_is_collection(const LWGEOM *lwgeom)
Determine whether a LWGEOM can contain sub-geometries or not.
Definition: lwgeom.c:1097
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
#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_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:561
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:485
#define DIST_MIN
Definition: measures.h:44
double distance
Definition: measures3d.h:40
int mode
Definition: measures3d.h:43
double tolerance
Definition: measures3d.h:47
uint32_t ngeoms
Definition: liblwgeom.h:580
LWGEOM ** geoms
Definition: liblwgeom.h:575
uint8_t type
Definition: liblwgeom.h:462

References DIST_MIN, DISTPTS3D::distance, LWCOLLECTION::geoms, lw_dist3d_distribute_bruteforce(), 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(), lwgeom_maxdistance3d_tolerance(), and lwgeom_mindistance3d_tolerance().

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