PostGIS 3.0.6dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ lw_dist2d_recursive()

int lw_dist2d_recursive ( const LWGEOM lwg1,
const LWGEOM lwg2,
DISTPTS dl 
)

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

Definition at line 284 of file measures.c.

285{
286 int i, j;
287 int n1 = 1;
288 int n2 = 1;
289 LWGEOM *g1 = NULL;
290 LWGEOM *g2 = NULL;
291 LWCOLLECTION *c1 = NULL;
292 LWCOLLECTION *c2 = NULL;
293
294 LWDEBUGF(2, "lw_dist2d_comp is called with type1=%d, type2=%d", lwg1->type, lwg2->type);
295
296 if (lw_dist2d_is_collection(lwg1))
297 {
298 LWDEBUG(3, "First geometry is collection");
299 c1 = lwgeom_as_lwcollection(lwg1);
300 n1 = c1->ngeoms;
301 }
302 if (lw_dist2d_is_collection(lwg2))
303 {
304 LWDEBUG(3, "Second geometry is collection");
305 c2 = lwgeom_as_lwcollection(lwg2);
306 n2 = c2->ngeoms;
307 }
308
309 for (i = 0; i < n1; i++)
310 {
311
312 if (lw_dist2d_is_collection(lwg1))
313 g1 = c1->geoms[i];
314 else
315 g1 = (LWGEOM *)lwg1;
316
317 if (!g1) continue;
318
319 if (lwgeom_is_empty(g1))
320 continue;
321
323 {
324 LWDEBUG(3, "Found collection inside first geometry collection, recursing");
325 if (!lw_dist2d_recursive(g1, lwg2, dl))
326 return LW_FALSE;
327 continue;
328 }
329 for (j = 0; j < n2; j++)
330 {
331 if (lw_dist2d_is_collection(lwg2))
332 g2 = c2->geoms[j];
333 else
334 g2 = (LWGEOM *)lwg2;
335
336 if (!g2) continue;
337
339 {
340 LWDEBUG(3, "Found collection inside second geometry collection, recursing");
341 if (!lw_dist2d_recursive(g1, g2, dl))
342 return LW_FALSE;
343 continue;
344 }
345
346 if (!g1->bbox)
347 lwgeom_add_bbox(g1);
348
349 if (!g2->bbox)
350 lwgeom_add_bbox(g2);
351
352 /* If one of geometries is empty, skip */
353 if (lwgeom_is_empty(g1) || lwgeom_is_empty(g2))
354 continue;
355
356 if ((dl->mode != DIST_MAX) && (!lw_dist2d_check_overlap(g1, g2)) &&
357 (g1->type == LINETYPE || g1->type == POLYGONTYPE || g1->type == TRIANGLETYPE) &&
358 (g2->type == LINETYPE || g2->type == POLYGONTYPE || g2->type == TRIANGLETYPE))
359 {
360 if (!lw_dist2d_distribute_fast(g1, g2, dl))
361 return LW_FALSE;
362 }
363 else
364 {
365 if (!lw_dist2d_distribute_bruteforce(g1, g2, dl))
366 return LW_FALSE;
367 if (dl->distance <= dl->tolerance && dl->mode == DIST_MIN)
368 return LW_TRUE; /*just a check if the answer is already given*/
369 }
370 }
371 }
372 return LW_TRUE;
373}
#define LW_FALSE
Definition liblwgeom.h:108
#define LINETYPE
Definition liblwgeom.h:117
LWCOLLECTION * lwgeom_as_lwcollection(const LWGEOM *lwgeom)
Definition lwgeom.c:215
#define POLYGONTYPE
Definition liblwgeom.h:118
#define TRIANGLETYPE
Definition liblwgeom.h:129
#define LW_TRUE
Return types for functions with status returns.
Definition liblwgeom.h:107
void lwgeom_add_bbox(LWGEOM *lwgeom)
Compute a bbox if not already computed.
Definition lwgeom.c:677
#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
static int lw_dist2d_check_overlap(const LWGEOM *lwg1, const LWGEOM *lwg2)
Definition measures.c:267
int lw_dist2d_recursive(const LWGEOM *lwg1, const LWGEOM *lwg2, DISTPTS *dl)
This is a recursive function delivering every possible combination of subgeometries.
Definition measures.c:284
static int lw_dist2d_is_collection(const LWGEOM *g)
Definition measures.c:242
int lw_dist2d_distribute_bruteforce(const LWGEOM *lwg1, const LWGEOM *lwg2, DISTPTS *dl)
Definition measures.c:376
int lw_dist2d_distribute_fast(LWGEOM *lwg1, LWGEOM *lwg2, DISTPTS *dl)
Geometries are distributed for the new faster distance-calculations.
Definition measures.c:538
#define DIST_MIN
Definition measures.h:44
#define DIST_MAX
Definition measures.h:43
double tolerance
Definition measures.h:56
int mode
Definition measures.h:54
double distance
Definition measures.h:51
uint32_t ngeoms
Definition liblwgeom.h:566
LWGEOM ** geoms
Definition liblwgeom.h:561
uint8_t type
Definition liblwgeom.h:448
GBOX * bbox
Definition liblwgeom.h:444

References LWGEOM::bbox, DIST_MAX, DIST_MIN, DISTPTS::distance, LWCOLLECTION::geoms, LINETYPE, lw_dist2d_check_overlap(), lw_dist2d_distribute_bruteforce(), lw_dist2d_distribute_fast(), lw_dist2d_is_collection(), lw_dist2d_recursive(), LW_FALSE, LW_TRUE, LWDEBUG, LWDEBUGF, lwgeom_add_bbox(), lwgeom_as_lwcollection(), lwgeom_is_empty(), DISTPTS::mode, LWCOLLECTION::ngeoms, POLYGONTYPE, DISTPTS::tolerance, TRIANGLETYPE, and LWGEOM::type.

Referenced by lw_dist2d_comp(), lw_dist2d_curvepoly_curvepoly(), lw_dist2d_line_curvepoly(), lw_dist2d_point_curvepoly(), lw_dist2d_recursive(), and lw_dist2d_tri_curvepoly().

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