PostGIS  3.0.6dev-r@@SVN_REVISION@@

◆ BOX2D_construct()

Datum BOX2D_construct ( PG_FUNCTION_ARGS  )

Definition at line 533 of file lwgeom_box.c.

534 {
535  GSERIALIZED *pgmin = PG_GETARG_GSERIALIZED_P(0);
536  GSERIALIZED *pgmax = PG_GETARG_GSERIALIZED_P(1);
537  GBOX *result;
538  LWPOINT *minpoint, *maxpoint;
539  double min, max, tmp;
540  gserialized_error_if_srid_mismatch(pgmin, pgmax, __func__);
541 
542  minpoint = (LWPOINT*)lwgeom_from_gserialized(pgmin);
543  maxpoint = (LWPOINT*)lwgeom_from_gserialized(pgmax);
544 
545  if ( (minpoint->type != POINTTYPE) || (maxpoint->type != POINTTYPE) )
546  {
547  elog(ERROR, "BOX2D_construct: arguments must be points");
548  PG_RETURN_NULL();
549  }
550 
551  if (lwpoint_is_empty(minpoint) || lwpoint_is_empty(maxpoint) ){
552  elog(ERROR, "BOX2D_construct: args can not be empty points");
553  PG_RETURN_NULL();
554  }
555 
556  result = gbox_new(lwflags(0, 0, 0));
557 
558  /* Process X min/max */
559  min = lwpoint_get_x(minpoint);
560  max = lwpoint_get_x(maxpoint);
561  if ( min > max )
562  {
563  tmp = min;
564  min = max;
565  max = tmp;
566  }
567  result->xmin = min;
568  result->xmax = max;
569 
570  /* Process Y min/max */
571  min = lwpoint_get_y(minpoint);
572  max = lwpoint_get_y(maxpoint);
573  if ( min > max )
574  {
575  tmp = min;
576  min = max;
577  max = tmp;
578  }
579  result->ymin = min;
580  result->ymax = max;
581 
582  PG_RETURN_POINTER(result);
583 }
GBOX * gbox_new(lwflags_t flags)
Create a new gbox with the dimensionality indicated by the flags.
Definition: gbox.c:32
void gserialized_error_if_srid_mismatch(const GSERIALIZED *g1, const GSERIALIZED *g2, const char *funcname)
Definition: gserialized.c:404
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
Definition: gserialized.c:239
double lwpoint_get_x(const LWPOINT *point)
Definition: lwpoint.c:63
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:116
lwflags_t lwflags(int hasz, int hasm, int geodetic)
Construct a new flags bitmask.
Definition: lwutil.c:471
double lwpoint_get_y(const LWPOINT *point)
Definition: lwpoint.c:76
int lwpoint_is_empty(const LWPOINT *point)
double ymax
Definition: liblwgeom.h:343
double xmax
Definition: liblwgeom.h:341
double ymin
Definition: liblwgeom.h:342
double xmin
Definition: liblwgeom.h:340
uint8_t type
Definition: liblwgeom.h:460

References gbox_new(), gserialized_error_if_srid_mismatch(), lwflags(), lwgeom_from_gserialized(), lwpoint_get_x(), lwpoint_get_y(), lwpoint_is_empty(), POINTTYPE, LWPOINT::type, GBOX::xmax, GBOX::xmin, GBOX::ymax, and GBOX::ymin.

Here is the call graph for this function: