PostGIS  2.4.9dev-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 547 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().

548 {
549  int i;
550  POINT4D p;
551  int has_z, has_m;
552 
553  if ( ! pa ) return LW_FAILURE;
554  if ( ! gbox ) return LW_FAILURE;
555  if ( pa->npoints < 1 ) return LW_FAILURE;
556 
557  has_z = FLAGS_GET_Z(pa->flags);
558  has_m = FLAGS_GET_M(pa->flags);
559  gbox->flags = gflags(has_z, has_m, 0);
560  LWDEBUGF(4, "ptarray_calculate_gbox Z: %d M: %d", has_z, has_m);
561 
562  getPoint4d_p(pa, 0, &p);
563  gbox->xmin = gbox->xmax = p.x;
564  gbox->ymin = gbox->ymax = p.y;
565  if ( has_z )
566  gbox->zmin = gbox->zmax = p.z;
567  if ( has_m )
568  gbox->mmin = gbox->mmax = p.m;
569 
570  for ( i = 1 ; i < pa->npoints; i++ )
571  {
572  getPoint4d_p(pa, i, &p);
573  gbox->xmin = FP_MIN(gbox->xmin, p.x);
574  gbox->xmax = FP_MAX(gbox->xmax, p.x);
575  gbox->ymin = FP_MIN(gbox->ymin, p.y);
576  gbox->ymax = FP_MAX(gbox->ymax, p.y);
577  if ( has_z )
578  {
579  gbox->zmin = FP_MIN(gbox->zmin, p.z);
580  gbox->zmax = FP_MAX(gbox->zmax, p.z);
581  }
582  if ( has_m )
583  {
584  gbox->mmin = FP_MIN(gbox->mmin, p.m);
585  gbox->mmax = FP_MAX(gbox->mmax, p.m);
586  }
587  }
588  return LW_SUCCESS;
589 }
double x
Definition: liblwgeom.h:352
double m
Definition: liblwgeom.h:352
int npoints
Definition: liblwgeom.h:371
double xmax
Definition: liblwgeom.h:293
#define LW_SUCCESS
Definition: liblwgeom.h:80
#define FP_MIN(A, B)
#define LW_FAILURE
Definition: liblwgeom.h:79
double zmax
Definition: liblwgeom.h:297
double ymin
Definition: liblwgeom.h:294
double xmin
Definition: liblwgeom.h:292
uint8_t flags
Definition: liblwgeom.h:369
double ymax
Definition: liblwgeom.h:295
#define FLAGS_GET_Z(flags)
Macros for manipulating the &#39;flags&#39; byte.
Definition: liblwgeom.h:140
double z
Definition: liblwgeom.h:352
uint8_t flags
Definition: liblwgeom.h:291
uint8_t gflags(int hasz, int hasm, int geodetic)
Construct a new flags char.
Definition: g_util.c:145
double mmin
Definition: liblwgeom.h:298
double zmin
Definition: liblwgeom.h:296
#define FLAGS_GET_M(flags)
Definition: liblwgeom.h:141
double mmax
Definition: liblwgeom.h:299
double y
Definition: liblwgeom.h:352
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:88
int getPoint4d_p(const POINTARRAY *pa, int n, POINT4D *point)
Definition: lwgeom_api.c:122
#define FP_MAX(A, B)
Here is the call graph for this function:
Here is the caller graph for this function: