PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ BOX2D_construct()

Datum BOX2D_construct ( PG_FUNCTION_ARGS  )

Definition at line 534 of file lwgeom_box.c.

535 {
536  GSERIALIZED *pgmin = PG_GETARG_GSERIALIZED_P(0);
537  GSERIALIZED *pgmax = PG_GETARG_GSERIALIZED_P(1);
538  GBOX *result;
539  LWPOINT *minpoint, *maxpoint;
540  double min, max, tmp;
541  gserialized_error_if_srid_mismatch(pgmin, pgmax, __func__);
542 
543  minpoint = (LWPOINT*)lwgeom_from_gserialized(pgmin);
544  maxpoint = (LWPOINT*)lwgeom_from_gserialized(pgmax);
545 
546  if ( (minpoint->type != POINTTYPE) || (maxpoint->type != POINTTYPE) )
547  {
548  elog(ERROR, "BOX2D_construct: arguments must be points");
549  PG_RETURN_NULL();
550  }
551 
552  if (lwpoint_is_empty(minpoint) || lwpoint_is_empty(maxpoint) ){
553  elog(ERROR, "BOX2D_construct: args can not be empty points");
554  PG_RETURN_NULL();
555  }
556 
557  result = gbox_new(lwflags(0, 0, 0));
558 
559  /* Process X min/max */
560  min = lwpoint_get_x(minpoint);
561  max = lwpoint_get_x(maxpoint);
562  if ( min > max )
563  {
564  tmp = min;
565  min = max;
566  max = tmp;
567  }
568  result->xmin = min;
569  result->xmax = max;
570 
571  /* Process Y min/max */
572  min = lwpoint_get_y(minpoint);
573  max = lwpoint_get_y(maxpoint);
574  if ( min > max )
575  {
576  tmp = min;
577  min = max;
578  max = tmp;
579  }
580  result->ymin = min;
581  result->ymax = max;
582 
583  PG_RETURN_POINTER(result);
584 }
char result[OUT_DOUBLE_BUFFER_SIZE]
Definition: cu_print.c:262
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:403
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:102
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)
uint8_t type
Definition: liblwgeom.h:474

References gbox_new(), gserialized_error_if_srid_mismatch(), lwflags(), lwgeom_from_gserialized(), lwpoint_get_x(), lwpoint_get_y(), lwpoint_is_empty(), POINTTYPE, result, and LWPOINT::type.

Here is the call graph for this function: