32 # ifdef HAVE_GNU_ISFINITE
35 # define isfinite finite
49 memset(gbox, 0,
sizeof(
GBOX));
55 memcpy(g, gbox,
sizeof(
GBOX));
144 if ( ( ! g1 ) && ( ! g2 ) )
148 memcpy(gout, g2,
sizeof(
GBOX));
153 memcpy(gout, g1,
sizeof(
GBOX));
207 if ( ! isfinite(gbox->
xmin) || isnan(gbox->
xmin) ||
208 ! isfinite(gbox->
xmax) || isnan(gbox->
xmax) )
212 if ( ! isfinite(gbox->
ymin) || isnan(gbox->
ymin) ||
213 ! isfinite(gbox->
ymax) || isnan(gbox->
ymax) )
219 if ( ! isfinite(gbox->
zmin) || isnan(gbox->
zmin) ||
220 ! isfinite(gbox->
zmax) || isnan(gbox->
zmax) )
227 if ( ! isfinite(gbox->
mmin) || isnan(gbox->
mmin) ||
228 ! isfinite(gbox->
mmax) || isnan(gbox->
mmax) )
295 lwerror(
"gbox_overlaps: cannot compare geodetic and non-geodetic boxes");
335 lwerror(
"gbox_overlaps: cannot compare geodetic and non-geodetic boxes");
359 if ( ( g->
xmin <= p->
x ) && ( g->
xmax >= p->
x ) &&
373 const char *ptr = str;
375 char *gbox_start = strstr(str,
"GBOX((");
377 if ( ! gbox_start )
return NULL;
379 gbox->
xmin = strtod(ptr, &nextptr);
380 if ( ptr == nextptr )
return NULL;
382 gbox->
ymin = strtod(ptr, &nextptr);
383 if ( ptr == nextptr )
return NULL;
385 gbox->
zmin = strtod(ptr, &nextptr);
386 if ( ptr == nextptr )
return NULL;
388 gbox->
xmax = strtod(ptr, &nextptr);
389 if ( ptr == nextptr )
return NULL;
391 gbox->
ymax = strtod(ptr, &nextptr);
392 if ( ptr == nextptr )
return NULL;
394 gbox->
zmax = strtod(ptr, &nextptr);
395 if ( ptr == nextptr )
return NULL;
405 return strdup(
"NULL POINTER");
411 snprintf(str, sz,
"GBOX((%.8g,%.8g,%.8g),(%.8g,%.8g,%.8g))", gbox->
xmin, gbox->
ymin, gbox->
zmin, gbox->
xmax, gbox->
ymax, gbox->
zmax);
416 snprintf(str, sz,
"GBOX((%.8g,%.8g,%.8g,%.8g),(%.8g,%.8g,%.8g,%.8g))", gbox->
xmin, gbox->
ymin, gbox->
zmin, gbox->
mmin, gbox->
xmax, gbox->
ymax, gbox->
zmax, gbox->
mmax);
421 snprintf(str, sz,
"GBOX((%.8g,%.8g,%.8g),(%.8g,%.8g,%.8g))", gbox->
xmin, gbox->
ymin, gbox->
zmin, gbox->
xmax, gbox->
ymax, gbox->
zmax);
426 snprintf(str, sz,
"GBOX((%.8g,%.8g,%.8g),(%.8g,%.8g,%.8g))", gbox->
xmin, gbox->
ymin, gbox->
mmin, gbox->
xmax, gbox->
ymax, gbox->
mmax);
429 snprintf(str, sz,
"GBOX((%.8g,%.8g),(%.8g,%.8g))", gbox->
xmin, gbox->
ymin, gbox->
xmax, gbox->
ymax);
436 memcpy(copy, box,
sizeof(
GBOX));
443 memcpy(duplicate, original,
sizeof(
GBOX));
449 return 6 *
sizeof(float);
461 POINT2D xmin, ymin, xmax, ymax;
466 LWDEBUG(2,
"lw_arc_calculate_gbox_cartesian_2d called.");
481 if ( A1->
x == A3->
x && A1->
y == A3->
y )
483 gbox->
xmin = C.
x - radius_A;
484 gbox->
ymin = C.
y - radius_A;
485 gbox->
xmax = C.
x + radius_A;
486 gbox->
ymax = C.
y + radius_A;
497 xmin.
x = C.
x - radius_A;
500 ymin.
y = C.
y - radius_A;
501 xmax.
x = C.
x + radius_A;
504 ymax.
y = C.
y + radius_A;
532 LWDEBUG(2,
"lw_arc_calculate_gbox_cartesian called.");
555 LWDEBUGF(4,
"ptarray_calculate_gbox Z: %d M: %d", has_z, has_m);
565 for ( i = 1 ; i < pa->
npoints; i++ )
650 if ( (coll->
ngeoms == 0) || !gbox)
655 for ( i = 0; i < coll->
ngeoms; i++ )
683 switch (lwgeom->
type)
int gbox_merge(const GBOX *new_box, GBOX *merge_box)
Update the merged GBOX to be large enough to include itself and the new box.
int gbox_same(const GBOX *g1, const GBOX *g2)
Check if 2 given Gbox are the same.
int gbox_union(const GBOX *g1, const GBOX *g2, GBOX *gout)
Update the output GBOX to be large enough to include both inputs.
void gbox_duplicate(const GBOX *original, GBOX *duplicate)
Copy the values of original GBOX into duplicate.
int gbox_same_2d(const GBOX *g1, const GBOX *g2)
Check if 2 given GBOX are the same in x and y.
GBOX * box3d_to_gbox(const BOX3D *b3d)
void gbox_expand(GBOX *g, double d)
Move the box minimums down and the maximums up by the distance provided.
int gbox_contains_point3d(const GBOX *gbox, const POINT3D *pt)
Return true if the point is inside the gbox.
void gbox_float_round(GBOX *gbox)
Round given GBOX to float boundaries.
GBOX * gbox_new(uint8_t flags)
Create a new gbox with the dimensionality indicated by the flags.
static int lwpoint_calculate_gbox_cartesian(LWPOINT *point, GBOX *gbox)
static int lwpoly_calculate_gbox_cartesian(LWPOLY *poly, GBOX *gbox)
static int lwtriangle_calculate_gbox_cartesian(LWTRIANGLE *triangle, GBOX *gbox)
int gbox_merge_point3d(const POINT3D *p, GBOX *gbox)
Update the GBOX to be large enough to include itself and the new point.
BOX3D * box3d_from_gbox(const GBOX *gbox)
int lwgeom_calculate_gbox_cartesian(const LWGEOM *lwgeom, GBOX *gbox)
Calculate the 2-4D bounding box of a geometry.
int gbox_overlaps(const GBOX *g1, const GBOX *g2)
Return LW_TRUE if the GBOX overlaps, LW_FALSE otherwise.
int gbox_overlaps_2d(const GBOX *g1, const GBOX *g2)
Return LW_TRUE if the GBOX overlaps on the 2d plane, LW_FALSE otherwise.
int gbox_contains_point2d(const GBOX *g, const POINT2D *p)
void gbox_init(GBOX *gbox)
Zero out all the entries in the GBOX.
void gbox_expand_xyzm(GBOX *g, double dx, double dy, double dz, double dm)
Move the box minimums down and the maximums up by the distances provided.
GBOX * gbox_copy(const GBOX *box)
Return a copy of the GBOX, based on dimensionality of flags.
static int lwline_calculate_gbox_cartesian(LWLINE *line, GBOX *gbox)
int gbox_init_point3d(const POINT3D *p, GBOX *gbox)
Initialize a GBOX using the values of the point.
size_t gbox_serialized_size(uint8_t flags)
Return the number of bytes necessary to hold a GBOX of this dimension in serialized form.
int ptarray_calculate_gbox_cartesian(const POINTARRAY *pa, GBOX *gbox)
Calculate box (x/y) and add values to gbox.
static int lwcircstring_calculate_gbox_cartesian(LWCIRCSTRING *curve, GBOX *gbox)
GBOX * gbox_from_string(const char *str)
Warning, this function is only good for x/y/z boxes, used in unit testing of geodetic box generation.
static int lwcollection_calculate_gbox_cartesian(LWCOLLECTION *coll, GBOX *gbox)
GBOX * gbox_clone(const GBOX *gbox)
int gbox_same_2d_float(const GBOX *g1, const GBOX *g2)
Check if two given GBOX are the same in x and y, or would round to the same GBOX in x and if serializ...
int gbox_is_valid(const GBOX *gbox)
Return false if any of the dimensions is NaN or infinite.
int gbox_contains_2d(const GBOX *g1, const GBOX *g2)
Return LW_TRUE if the first GBOX contains the second on the 2d plane, LW_FALSE otherwise.
char * gbox_to_string(const GBOX *gbox)
Allocate a string representation of the GBOX, based on dimensionality of flags.
int lw_arc_calculate_gbox_cartesian_2d(const POINT2D *A1, const POINT2D *A2, const POINT2D *A3, GBOX *gbox)
static int lw_arc_calculate_gbox_cartesian(const POINT4D *p1, const POINT4D *p2, const POINT4D *p3, GBOX *gbox)
uint8_t gflags(int hasz, int hasm, int geodetic)
Construct a new flags char.
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
#define FLAGS_GET_Z(flags)
Macros for manipulating the 'flags' byte.
#define FLAGS_NDIMS(flags)
#define POLYHEDRALSURFACETYPE
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
#define FLAGS_GET_M(flags)
int getPoint4d_p(const POINTARRAY *pa, uint32_t n, POINT4D *point)
#define FLAGS_GET_ZM(flags)
void * lwalloc(size_t size)
float next_float_up(double d)
#define LW_TRUE
Return types for functions with status returns.
#define SRID_UNKNOWN
Unknown SRID value.
float next_float_down(double d)
#define FLAGS_GET_GEODETIC(flags)
double lw_arc_center(const POINT2D *p1, const POINT2D *p2, const POINT2D *p3, POINT2D *result)
Determines the center of the circle defined by the three given points.
int lw_segment_side(const POINT2D *p1, const POINT2D *p2, const POINT2D *q)
lw_segment_side()
#define LWDEBUG(level, msg)
#define LWDEBUGF(level, msg,...)
void lwerror(const char *fmt,...)
Write a notice out to the error handler.