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

◆ BOX2D_combine()

Datum BOX2D_combine ( PG_FUNCTION_ARGS  )

Definition at line 415 of file lwgeom_box.c.

416{
417 Pointer box2d_ptr = PG_GETARG_POINTER(0);
418 Pointer geom_ptr = PG_GETARG_POINTER(1);
419 GBOX *a,*b;
420 GSERIALIZED *lwgeom;
421 GBOX box, *result;
422
423 if ( (box2d_ptr == NULL) && (geom_ptr == NULL) )
424 {
425 PG_RETURN_NULL(); /* combine_box2d(null,null) => null */
426 }
427
428 result = (GBOX *)palloc(sizeof(GBOX));
429
430 if (box2d_ptr == NULL)
431 {
432 lwgeom = PG_GETARG_GSERIALIZED_P(1);
433 /* empty geom would make getbox2d_p return NULL */
434 if ( ! gserialized_get_gbox_p(lwgeom, &box) ) PG_RETURN_NULL();
435 memcpy(result, &box, sizeof(GBOX));
436 PG_RETURN_POINTER(result);
437 }
438
439 /* combine_bbox(BOX3D, null) => BOX3D */
440 if (geom_ptr == NULL)
441 {
442 memcpy(result, (char *)PG_GETARG_DATUM(0), sizeof(GBOX));
443 PG_RETURN_POINTER(result);
444 }
445
446 /*combine_bbox(BOX3D, geometry) => union(BOX3D, geometry->bvol) */
447
448 lwgeom = PG_GETARG_GSERIALIZED_P(1);
449 if ( ! gserialized_get_gbox_p(lwgeom, &box) )
450 {
451 /* must be the empty geom */
452 memcpy(result, (char *)PG_GETARG_DATUM(0), sizeof(GBOX));
453 PG_RETURN_POINTER(result);
454 }
455
456 a = (GBOX *)PG_GETARG_DATUM(0);
457 b = &box;
458
459 result->xmax = Max(a->xmax, b->xmax);
460 result->ymax = Max(a->ymax, b->ymax);
461 result->xmin = Min(a->xmin, b->xmin);
462 result->ymin = Min(a->ymin, b->ymin);
463
464 PG_RETURN_POINTER(result);
465}
int gserialized_get_gbox_p(const GSERIALIZED *g, GBOX *gbox)
Read the box from the GSERIALIZED or calculate it if necessary.
Definition gserialized.c:65
double ymax
Definition liblwgeom.h:343
double xmax
Definition liblwgeom.h:341
double ymin
Definition liblwgeom.h:342
double xmin
Definition liblwgeom.h:340

References gserialized_get_gbox_p(), GBOX::xmax, GBOX::xmin, GBOX::ymax, and GBOX::ymin.

Here is the call graph for this function: