36 # ifdef HAVE_GNU_ISFINITE 39 # define isfinite finite 53 memset(gbox, 0,
sizeof(
GBOX));
59 memcpy(g, gbox,
sizeof(
GBOX));
148 if ( ( ! g1 ) && ( ! g2 ) )
153 memcpy(gout, g2,
sizeof(
GBOX));
158 memcpy(gout, g1,
sizeof(
GBOX));
212 if ( ! isfinite(gbox->
xmin) || isnan(gbox->
xmin) ||
213 ! isfinite(gbox->
xmax) || isnan(gbox->
xmax) )
217 if ( ! isfinite(gbox->
ymin) || isnan(gbox->
ymin) ||
218 ! isfinite(gbox->
ymax) || isnan(gbox->
ymax) )
224 if ( ! isfinite(gbox->
zmin) || isnan(gbox->
zmin) ||
225 ! isfinite(gbox->
zmax) || isnan(gbox->
zmax) )
232 if ( ! isfinite(gbox->
mmin) || isnan(gbox->
mmin) ||
233 ! isfinite(gbox->
mmax) || isnan(gbox->
mmax) )
300 lwerror(
"gbox_overlaps: cannot compare geodetic and non-geodetic boxes");
340 lwerror(
"gbox_overlaps: cannot compare geodetic and non-geodetic boxes");
364 if ( ( g->
xmin <= p->
x ) && ( g->
xmax >= p->
x ) &&
378 const char *ptr = str;
380 char *gbox_start = strstr(str,
"GBOX((");
382 if ( ! gbox_start )
return NULL;
384 gbox->
xmin = strtod(ptr, &nextptr);
385 if ( ptr == nextptr )
return NULL;
387 gbox->
ymin = strtod(ptr, &nextptr);
388 if ( ptr == nextptr )
return NULL;
390 gbox->
zmin = strtod(ptr, &nextptr);
391 if ( ptr == nextptr )
return NULL;
393 gbox->
xmax = strtod(ptr, &nextptr);
394 if ( ptr == nextptr )
return NULL;
396 gbox->
ymax = strtod(ptr, &nextptr);
397 if ( ptr == nextptr )
return NULL;
399 gbox->
zmax = strtod(ptr, &nextptr);
400 if ( ptr == nextptr )
return NULL;
410 return strdup(
"NULL POINTER");
416 snprintf(str, sz,
"GBOX((%.8g,%.8g,%.8g),(%.8g,%.8g,%.8g))", gbox->
xmin, gbox->
ymin, gbox->
zmin, gbox->
xmax, gbox->
ymax, gbox->
zmax);
421 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);
426 snprintf(str, sz,
"GBOX((%.8g,%.8g,%.8g),(%.8g,%.8g,%.8g))", gbox->
xmin, gbox->
ymin, gbox->
zmin, gbox->
xmax, gbox->
ymax, gbox->
zmax);
431 snprintf(str, sz,
"GBOX((%.8g,%.8g,%.8g),(%.8g,%.8g,%.8g))", gbox->
xmin, gbox->
ymin, gbox->
mmin, gbox->
xmax, gbox->
ymax, gbox->
mmax);
434 snprintf(str, sz,
"GBOX((%.8g,%.8g),(%.8g,%.8g))", gbox->
xmin, gbox->
ymin, gbox->
xmax, gbox->
ymax);
441 memcpy(copy, box,
sizeof(
GBOX));
448 memcpy(duplicate, original,
sizeof(
GBOX));
454 return 6 *
sizeof(float);
466 POINT2D xmin, ymin, xmax, ymax;
471 LWDEBUG(2,
"lw_arc_calculate_gbox_cartesian_2d called.");
486 if ( A1->
x == A3->
x && A1->
y == A3->
y )
488 gbox->
xmin = C.
x - radius_A;
489 gbox->
ymin = C.
y - radius_A;
490 gbox->
xmax = C.
x + radius_A;
491 gbox->
ymax = C.
y + radius_A;
502 xmin.
x = C.
x - radius_A;
505 ymin.
y = C.
y - radius_A;
506 xmax.
x = C.
x + radius_A;
509 ymax.
y = C.
y + radius_A;
537 LWDEBUG(2,
"lw_arc_calculate_gbox_cartesian called.");
560 LWDEBUGF(4,
"ptarray_calculate_gbox Z: %d M: %d", has_z, has_m);
570 for ( i = 1 ; i < pa->
npoints; i++ )
655 if ( (coll->
ngeoms == 0) || !gbox)
660 for ( i = 0; i < coll->
ngeoms; i++ )
688 switch (lwgeom->
type)
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 ptarray_calculate_gbox_cartesian(const POINTARRAY *pa, GBOX *gbox)
Calculate box (x/y) and add values to gbox.
GBOX * gbox_copy(const GBOX *box)
Return a copy of the GBOX, based on dimensionality of flags.
GBOX * gbox_new(uint8_t flags)
Create a new gbox with the dimensionality indicated by the flags.
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.
void gbox_duplicate(const GBOX *original, GBOX *duplicate)
Copy the values of original GBOX into duplicate.
int gbox_is_valid(const GBOX *gbox)
Return false if any of the dimensions is NaN or infinite.
static int lwpoint_calculate_gbox_cartesian(LWPOINT *point, GBOX *gbox)
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)
void gbox_expand(GBOX *g, double d)
Move the box minimums down and the maximums up by the distance provided.
static int lw_arc_calculate_gbox_cartesian(const POINT4D *p1, const POINT4D *p2, const POINT4D *p3, GBOX *gbox)
#define FLAGS_GET_GEODETIC(flags)
int gbox_contains_point3d(const GBOX *gbox, const POINT3D *pt)
Return true if the point is inside the gbox.
static int lwpoly_calculate_gbox_cartesian(LWPOLY *poly, GBOX *gbox)
#define FLAGS_GET_ZM(flags)
#define LWDEBUG(level, msg)
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.
#define POLYHEDRALSURFACETYPE
int gbox_init_point3d(const POINT3D *p, GBOX *gbox)
Initialize a GBOX using the values of the point.
float next_float_down(double d)
static int lwcollection_calculate_gbox_cartesian(LWCOLLECTION *coll, GBOX *gbox)
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.
float next_float_up(double d)
void gbox_float_round(GBOX *gbox)
Round given GBOX to float boundaries.
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
void gbox_init(GBOX *gbox)
Zero out all the entries in the GBOX.
#define LW_TRUE
Return types for functions with status returns.
#define SRID_UNKNOWN
Unknown SRID value.
int gbox_merge_point3d(const POINT3D *p, GBOX *gbox)
Update the GBOX to be large enough to include itself and the new point.
#define FLAGS_GET_Z(flags)
Macros for manipulating the 'flags' byte.
int gbox_same_2d(const GBOX *g1, const GBOX *g2)
Check if 2 given GBOX are the same in x and y.
int gbox_union(const GBOX *g1, const GBOX *g2, GBOX *gout)
Update the output GBOX to be large enough to include both inputs.
uint8_t gflags(int hasz, int hasm, int geodetic)
Construct a new flags char.
GBOX * box3d_to_gbox(const BOX3D *b3d)
static int lwcircstring_calculate_gbox_cartesian(LWCIRCSTRING *curve, GBOX *gbox)
BOX3D * box3d_from_gbox(const GBOX *gbox)
int gbox_overlaps_2d(const GBOX *g1, const GBOX *g2)
Return LW_TRUE if the GBOX overlaps on the 2d plane, LW_FALSE otherwise.
static int lwline_calculate_gbox_cartesian(LWLINE *line, GBOX *gbox)
static int lwtriangle_calculate_gbox_cartesian(LWTRIANGLE *triangle, GBOX *gbox)
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
#define FLAGS_GET_M(flags)
int gbox_overlaps(const GBOX *g1, const GBOX *g2)
Return LW_TRUE if the GBOX overlaps, LW_FALSE otherwise.
GBOX * gbox_clone(const GBOX *gbox)
void * lwalloc(size_t size)
int lw_segment_side(const POINT2D *p1, const POINT2D *p2, const POINT2D *q)
lw_segment_side()
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...
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...
#define LWDEBUGF(level, msg,...)
#define FLAGS_NDIMS(flags)
int gbox_same(const GBOX *g1, const GBOX *g2)
Check if 2 given Gbox are the same.
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
int gbox_contains_point2d(const GBOX *g, const POINT2D *p)
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 getPoint4d_p(const POINTARRAY *pa, int n, POINT4D *point)
int lwgeom_calculate_gbox_cartesian(const LWGEOM *lwgeom, GBOX *gbox)
Calculate the 2-4D bounding box of a geometry.