PostGIS  2.1.10dev-r@@SVN_REVISION@@
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 471 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().

472 {
473  int i;
474  POINT4D p;
475  int has_z, has_m;
476 
477  if ( ! pa ) return LW_FAILURE;
478  if ( ! gbox ) return LW_FAILURE;
479  if ( pa->npoints < 1 ) return LW_FAILURE;
480 
481  has_z = FLAGS_GET_Z(pa->flags);
482  has_m = FLAGS_GET_M(pa->flags);
483  gbox->flags = gflags(has_z, has_m, 0);
484  LWDEBUGF(4, "ptarray_calculate_gbox Z: %d M: %d", has_z, has_m);
485 
486  getPoint4d_p(pa, 0, &p);
487  gbox->xmin = gbox->xmax = p.x;
488  gbox->ymin = gbox->ymax = p.y;
489  if ( has_z )
490  gbox->zmin = gbox->zmax = p.z;
491  if ( has_m )
492  gbox->mmin = gbox->mmax = p.m;
493 
494  for ( i = 1 ; i < pa->npoints; i++ )
495  {
496  getPoint4d_p(pa, i, &p);
497  gbox->xmin = FP_MIN(gbox->xmin, p.x);
498  gbox->xmax = FP_MAX(gbox->xmax, p.x);
499  gbox->ymin = FP_MIN(gbox->ymin, p.y);
500  gbox->ymax = FP_MAX(gbox->ymax, p.y);
501  if ( has_z )
502  {
503  gbox->zmin = FP_MIN(gbox->zmin, p.z);
504  gbox->zmax = FP_MAX(gbox->zmax, p.z);
505  }
506  if ( has_m )
507  {
508  gbox->mmin = FP_MIN(gbox->mmin, p.m);
509  gbox->mmax = FP_MAX(gbox->mmax, p.m);
510  }
511  }
512  return LW_SUCCESS;
513 }
double x
Definition: liblwgeom.h:308
double m
Definition: liblwgeom.h:308
int npoints
Definition: liblwgeom.h:327
double xmax
Definition: liblwgeom.h:249
#define LW_SUCCESS
Definition: liblwgeom.h:55
#define FP_MIN(A, B)
#define LW_FAILURE
Definition: liblwgeom.h:54
double zmax
Definition: liblwgeom.h:253
double ymin
Definition: liblwgeom.h:250
double xmin
Definition: liblwgeom.h:248
uint8_t flags
Definition: liblwgeom.h:325
double ymax
Definition: liblwgeom.h:251
#define FLAGS_GET_Z(flags)
Macros for manipulating the 'flags' byte.
Definition: liblwgeom.h:106
double z
Definition: liblwgeom.h:308
uint8_t flags
Definition: liblwgeom.h:247
uint8_t gflags(int hasz, int hasm, int geodetic)
Construct a new flags char.
Definition: g_util.c:131
double mmin
Definition: liblwgeom.h:254
double zmin
Definition: liblwgeom.h:252
#define FLAGS_GET_M(flags)
Definition: liblwgeom.h:107
double mmax
Definition: liblwgeom.h:255
double y
Definition: liblwgeom.h:308
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:55
int getPoint4d_p(const POINTARRAY *pa, int n, POINT4D *point)
Definition: lwgeom_api.c:217
#define FP_MAX(A, B)

Here is the call graph for this function:

Here is the caller graph for this function: