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

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

Definition at line 194 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().

195 {
196  int i, j;
197  int n1=1;
198  int n2=1;
199  LWGEOM *g1 = NULL;
200  LWGEOM *g2 = NULL;
201  LWCOLLECTION *c1 = NULL;
202  LWCOLLECTION *c2 = NULL;
203 
204  LWDEBUGF(2, "lw_dist3d_recursive is called with type1=%d, type2=%d", lwg1->type, lwg2->type);
205 
206  if (lwgeom_is_collection(lwg1))
207  {
208  LWDEBUG(3, "First geometry is collection");
209  c1 = lwgeom_as_lwcollection(lwg1);
210  n1 = c1->ngeoms;
211  }
212  if (lwgeom_is_collection(lwg2))
213  {
214  LWDEBUG(3, "Second geometry is collection");
215  c2 = lwgeom_as_lwcollection(lwg2);
216  n2 = c2->ngeoms;
217  }
218 
219  for ( i = 0; i < n1; i++ )
220  {
221 
222  if (lwgeom_is_collection(lwg1))
223  {
224  g1 = c1->geoms[i];
225  }
226  else
227  {
228  g1 = (LWGEOM*)lwg1;
229  }
230 
231  if (lwgeom_is_empty(g1)) return LW_TRUE;
232 
233  if (lwgeom_is_collection(g1))
234  {
235  LWDEBUG(3, "Found collection inside first geometry collection, recursing");
236  if (!lw_dist3d_recursive(g1, lwg2, dl)) return LW_FALSE;
237  continue;
238  }
239  for ( j = 0; j < n2; j++ )
240  {
241  if (lwgeom_is_collection(lwg2))
242  {
243  g2 = c2->geoms[j];
244  }
245  else
246  {
247  g2 = (LWGEOM*)lwg2;
248  }
249  if (lwgeom_is_collection(g2))
250  {
251  LWDEBUG(3, "Found collection inside second geometry collection, recursing");
252  if (!lw_dist3d_recursive(g1, g2, dl)) return LW_FALSE;
253  continue;
254  }
255 
256 
257  /*If one of geometries is empty, return. True here only means continue searching. False would have stoped the process*/
258  if (lwgeom_is_empty(g1)||lwgeom_is_empty(g2)) return LW_TRUE;
259 
260 
261  if (!lw_dist3d_distribute_bruteforce(g1, g2, dl)) return LW_FALSE;
262  if (dl->distance<=dl->tolerance && dl->mode == DIST_MIN) return LW_TRUE; /*just a check if the answer is already given*/
263  }
264  }
265  return LW_TRUE;
266 }
double distance
Definition: measures3d.h:26
int lwgeom_is_collection(const LWGEOM *lwgeom)
Determine whether a LWGEOM can contain sub-geometries or not.
Definition: lwgeom.c:947
#define DIST_MIN
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:50
#define LW_FALSE
Definition: liblwgeom.h:52
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:51
LWGEOM ** geoms
Definition: liblwgeom.h:465
int lw_dist3d_distribute_bruteforce(LWGEOM *lwg1, LWGEOM *lwg2, DISTPTS3D *dl)
This function distributes the brut-force for 3D so far the only type, tasks depending on type...
Definition: measures3d.c:275
int mode
Definition: measures3d.h:29
int lw_dist3d_recursive(const LWGEOM *lwg1, const LWGEOM *lwg2, DISTPTS3D *dl)
This is a recursive function delivering every possible combinatin of subgeometries.
Definition: measures3d.c:194
double tolerance
Definition: measures3d.h:31
LWCOLLECTION * lwgeom_as_lwcollection(const LWGEOM *lwgeom)
Definition: lwgeom.c:143
uint8_t type
Definition: liblwgeom.h:352
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:1229
#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: