PostGIS  2.2.8dev-r@@SVN_REVISION@@

◆ ptarray_calculate_gbox_cartesian()

int ptarray_calculate_gbox_cartesian ( const POINTARRAY pa,
GBOX gbox 
)

Calculate box (x/y) and add values to gbox.

Return LW_SUCCESS on success.

Definition at line 512 of file g_box.c.

References GBOX::flags, POINTARRAY::flags, FLAGS_GET_M, FLAGS_GET_Z, FP_MAX, FP_MIN, getPoint4d_p(), gflags(), LW_FAILURE, LW_SUCCESS, LWDEBUGF, POINT4D::m, GBOX::mmax, GBOX::mmin, POINTARRAY::npoints, POINT4D::x, GBOX::xmax, GBOX::xmin, POINT4D::y, GBOX::ymax, GBOX::ymin, POINT4D::z, GBOX::zmax, and GBOX::zmin.

Referenced by LWGEOM_interiorringn_polygon(), lwline_calculate_gbox_cartesian(), lwpoint_calculate_gbox_cartesian(), lwpoly_calculate_gbox_cartesian(), lwtriangle_calculate_gbox_cartesian(), and ptarray_area_spheroid().

513 {
514  int i;
515  POINT4D p;
516  int has_z, has_m;
517 
518  if ( ! pa ) return LW_FAILURE;
519  if ( ! gbox ) return LW_FAILURE;
520  if ( pa->npoints < 1 ) return LW_FAILURE;
521 
522  has_z = FLAGS_GET_Z(pa->flags);
523  has_m = FLAGS_GET_M(pa->flags);
524  gbox->flags = gflags(has_z, has_m, 0);
525  LWDEBUGF(4, "ptarray_calculate_gbox Z: %d M: %d", has_z, has_m);
526 
527  getPoint4d_p(pa, 0, &p);
528  gbox->xmin = gbox->xmax = p.x;
529  gbox->ymin = gbox->ymax = p.y;
530  if ( has_z )
531  gbox->zmin = gbox->zmax = p.z;
532  if ( has_m )
533  gbox->mmin = gbox->mmax = p.m;
534 
535  for ( i = 1 ; i < pa->npoints; i++ )
536  {
537  getPoint4d_p(pa, i, &p);
538  gbox->xmin = FP_MIN(gbox->xmin, p.x);
539  gbox->xmax = FP_MAX(gbox->xmax, p.x);
540  gbox->ymin = FP_MIN(gbox->ymin, p.y);
541  gbox->ymax = FP_MAX(gbox->ymax, p.y);
542  if ( has_z )
543  {
544  gbox->zmin = FP_MIN(gbox->zmin, p.z);
545  gbox->zmax = FP_MAX(gbox->zmax, p.z);
546  }
547  if ( has_m )
548  {
549  gbox->mmin = FP_MIN(gbox->mmin, p.m);
550  gbox->mmax = FP_MAX(gbox->mmax, p.m);
551  }
552  }
553  return LW_SUCCESS;
554 }
double x
Definition: liblwgeom.h:336
double m
Definition: liblwgeom.h:336
int npoints
Definition: liblwgeom.h:355
double xmax
Definition: liblwgeom.h:277
#define LW_SUCCESS
Definition: liblwgeom.h:65
#define FP_MIN(A, B)
#define LW_FAILURE
Definition: liblwgeom.h:64
double zmax
Definition: liblwgeom.h:281
double ymin
Definition: liblwgeom.h:278
double xmin
Definition: liblwgeom.h:276
uint8_t flags
Definition: liblwgeom.h:353
double ymax
Definition: liblwgeom.h:279
#define FLAGS_GET_Z(flags)
Macros for manipulating the &#39;flags&#39; byte.
Definition: liblwgeom.h:124
double z
Definition: liblwgeom.h:336
uint8_t flags
Definition: liblwgeom.h:275
uint8_t gflags(int hasz, int hasm, int geodetic)
Construct a new flags char.
Definition: g_util.c:130
double mmin
Definition: liblwgeom.h:282
double zmin
Definition: liblwgeom.h:280
#define FLAGS_GET_M(flags)
Definition: liblwgeom.h:125
double mmax
Definition: liblwgeom.h:283
double y
Definition: liblwgeom.h:336
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:55
int getPoint4d_p(const POINTARRAY *pa, int n, POINT4D *point)
Definition: lwgeom_api.c:231
#define FP_MAX(A, B)
Here is the call graph for this function:
Here is the caller graph for this function: