PostGIS  3.7.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 519 of file measures3d.c.

520 {
521  int i, j;
522  int n1 = 1;
523  int n2 = 1;
524  LWGEOM *g1 = NULL;
525  LWGEOM *g2 = NULL;
526  LWCOLLECTION *c1 = NULL;
527  LWCOLLECTION *c2 = NULL;
528 
529  LWDEBUGF(2, "lw_dist3d_recursive is called with type1=%d, type2=%d", lwg1->type, lwg2->type);
530 
531  if (lwgeom_is_collection(lwg1))
532  {
533  LWDEBUG(3, "First geometry is collection");
534  c1 = lwgeom_as_lwcollection(lwg1);
535  n1 = c1->ngeoms;
536  }
537  if (lwgeom_is_collection(lwg2))
538  {
539  LWDEBUG(3, "Second geometry is collection");
540  c2 = lwgeom_as_lwcollection(lwg2);
541  n2 = c2->ngeoms;
542  }
543 
544  for (i = 0; i < n1; i++)
545  {
546  if (lwgeom_is_collection(lwg1))
547  g1 = c1->geoms[i];
548  else
549  g1 = (LWGEOM *)lwg1;
550 
551  if (lwgeom_is_empty(g1))
552  continue;
553 
554  if (lwgeom_is_collection(g1))
555  {
556  LWDEBUG(3, "Found collection inside first geometry collection, recursing");
557  if (!lw_dist3d_recursive(g1, lwg2, dl))
558  return LW_FALSE;
559  continue;
560  }
561  for (j = 0; j < n2; j++)
562  {
563  if (lwgeom_is_collection(lwg2))
564  g2 = c2->geoms[j];
565  else
566  g2 = (LWGEOM *)lwg2;
567 
568  if (lwgeom_is_empty(g2))
569  continue;
570 
571  if (lwgeom_is_collection(g2))
572  {
573  LWDEBUG(3, "Found collection inside second geometry collection, recursing");
574  if (!lw_dist3d_recursive(g1, g2, dl))
575  return LW_FALSE;
576  continue;
577  }
578 
579  /*If one of geometries is empty, return. True here only means continue searching. False would
580  * have stopped the process*/
581  if (lwgeom_is_empty(g1) || lwgeom_is_empty(g2))
582  return LW_TRUE;
583 
584  if (!lw_dist3d_distribute_bruteforce(g1, g2, dl))
585  return LW_FALSE;
586  if (dl->distance <= dl->tolerance && dl->mode == DIST_MIN)
587  return LW_TRUE; /*just a check if the answer is already given*/
588  }
589  }
590  return LW_TRUE;
591 }
#define LW_FALSE
Definition: liblwgeom.h:94
int lwgeom_is_collection(const LWGEOM *lwgeom)
Determine whether a LWGEOM contains sub-geometries or not This basically just checks that the struct ...
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: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_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:598
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:519
#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: