PostGIS  3.0.6dev-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  continue;
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_empty(g2))
535  continue;
536 
537  if (lwgeom_is_collection(g2))
538  {
539  LWDEBUG(3, "Found collection inside second geometry collection, recursing");
540  if (!lw_dist3d_recursive(g1, g2, dl))
541  return LW_FALSE;
542  continue;
543  }
544 
545  /*If one of geometries is empty, return. True here only means continue searching. False would
546  * have stopped the process*/
547  if (lwgeom_is_empty(g1) || lwgeom_is_empty(g2))
548  return LW_TRUE;
549 
550  if (!lw_dist3d_distribute_bruteforce(g1, g2, dl))
551  return LW_FALSE;
552  if (dl->distance <= dl->tolerance && dl->mode == DIST_MIN)
553  return LW_TRUE; /*just a check if the answer is already given*/
554  }
555  }
556  return LW_TRUE;
557 }
#define LW_FALSE
Definition: liblwgeom.h:108
int lwgeom_is_collection(const LWGEOM *lwgeom)
Determine whether a LWGEOM can contain sub-geometries or not.
Definition: lwgeom.c:1079
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
#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_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:564
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:566
LWGEOM ** geoms
Definition: liblwgeom.h:561
uint8_t type
Definition: liblwgeom.h:448

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: