From: David Blasby Date: Thu, 29 Apr 2004 18:44:36 +0000 (+0000) Subject: Noted diff between inf and Infinity on Solaris/Intel machines X-Git-Tag: pgis_0_8_2~17 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=61c3c1e1928961012763379c45e4ae43861b4e1a;p=postgis Noted diff between inf and Infinity on Solaris/Intel machines git-svn-id: http://svn.osgeo.org/postgis/trunk@542 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/lwgeom/lwgeom_api.c b/lwgeom/lwgeom_api.c index 4a6b66c48..93ff710ae 100644 --- a/lwgeom/lwgeom_api.c +++ b/lwgeom/lwgeom_api.c @@ -1,4 +1,3 @@ - #include "postgres.h" #include @@ -18,6 +17,11 @@ #include "lwgeom.h" +// This is an implementation of the functions defined in lwgeom.h + + +//forward decs + extern float nextDown_f(double d); extern float nextUp_f(double d); extern double nextDown_d(float d); @@ -74,6 +78,8 @@ do { \ } while (0) +// returns the next smaller or next larger float +// from x (in direction of y). float nextafterf_custom(float x, float y) { int32_tt hx,hy,ix,iy; @@ -170,6 +176,8 @@ double nextUp_d(float d) } + +//Connvert BOX3D to BOX2D BOX2DFLOAT4 *box3d_to_box2df(BOX3D *box) { BOX2DFLOAT4 *result = (BOX2DFLOAT4*) palloc(sizeof(BOX2DFLOAT4)); @@ -187,6 +195,7 @@ BOX2DFLOAT4 *box3d_to_box2df(BOX3D *box) } +//convert postgresql BOX to BOX2D BOX2DFLOAT4 *box_to_box2df(BOX *box) { BOX2DFLOAT4 *result = (BOX2DFLOAT4*) palloc(sizeof(BOX2DFLOAT4)); @@ -203,6 +212,7 @@ BOX2DFLOAT4 *box_to_box2df(BOX *box) return result; } +// convert BOX2D to BOX3D BOX3D box2df_to_box3d(BOX2DFLOAT4 *box) { BOX3D result; @@ -219,6 +229,8 @@ BOX3D box2df_to_box3d(BOX2DFLOAT4 *box) return result; } + +// convert BOX2D to postgresql BOX BOX box2df_to_box(BOX2DFLOAT4 *box) { BOX result; @@ -235,6 +247,11 @@ BOX box2df_to_box(BOX2DFLOAT4 *box) return result; } + +// returns a BOX3D that encloses b1 and b2 +// combine_boxes(NULL,A) --> A +// combine_boxes(A,NULL) --> A +// combine_boxes(A,B) --> A union B BOX3D *combine_boxes(BOX3D *b1, BOX3D *b2) { BOX3D *result; @@ -324,6 +341,8 @@ BOX2DFLOAT4 getbox2d(char *serialized_form) return result; } + +// same as getbox2d, but modifies box instead of returning result on the stack void getbox2d_p(char *serialized_form, BOX2DFLOAT4 *box) { int type = (unsigned char) serialized_form[0]; @@ -597,21 +616,27 @@ int pointArray_ptsize(POINTARRAY *pa) // basic type handling +// returns true if this type says it has an SRID (S bit set) bool lwgeom_hasSRID(unsigned char type) { return (type & 0x40); } +// returns either 2,3, or 4 -- 2=2D, 3=3D, 4=4D int lwgeom_ndims(unsigned char type) { return ( (type & 0x30) >>4) +2; } + +// get base type (ie. POLYGONTYPE) int lwgeom_getType(unsigned char type) { return (type & 0x0F); } + +//construct a type (hasBOX=false) unsigned char lwgeom_makeType(int ndims, char hasSRID, int type) { unsigned char result = type; @@ -626,6 +651,7 @@ unsigned char lwgeom_makeType(int ndims, char hasSRID, int type) return result; } +//construct a type unsigned char lwgeom_makeType_full(int ndims, char hasSRID, int type, bool hasBBOX) { unsigned char result = type; @@ -642,6 +668,7 @@ unsigned char lwgeom_makeType_full(int ndims, char hasSRID, int type, bool hasBB return result; } +//returns true if there's a bbox in this LWGEOM (B bit set) bool lwgeom_hasBBOX(unsigned char type) { return (type & 0x80); @@ -1020,6 +1047,7 @@ POINT2D lwpoint_getPoint2d(LWPOINT *point) return getPoint2d(point->point,0); } +// convenience functions to hide the POINTARRAY POINT3D lwpoint_getPoint3d(LWPOINT *point) { POINT3D result; @@ -1447,6 +1475,10 @@ LWPOINT *lwgeom_getpoint(char *serialized_form, int geom_number) return lwpoint_deserialize(sub_geom); } +// 1st geometry has geom_number = 0 +// if the actual sub-geometry isnt a POINT, null is returned (see _gettype()). +// if there arent enough geometries, return null. +// this is fine to call on a point (with geom_num=0), multipoint or geometrycollection LWPOINT *lwgeom_getpoint_inspected(LWGEOM_INSPECTED *inspected, int geom_number) { char *sub_geom; @@ -1494,6 +1526,10 @@ LWLINE *lwgeom_getline(char *serialized_form, int geom_number) return lwline_deserialize(sub_geom); } +// 1st geometry has geom_number = 0 +// if the actual geometry isnt a LINE, null is returned (see _gettype()). +// if there arent enough geometries, return null. +// this is fine to call on a line, multiline or geometrycollection LWLINE *lwgeom_getline_inspected(LWGEOM_INSPECTED *inspected, int geom_number) { char *sub_geom; @@ -1543,6 +1579,10 @@ LWPOLY *lwgeom_getpoly(char *serialized_form, int geom_number) return lwpoly_deserialize(sub_geom); } +// 1st geometry has geom_number = 0 +// if the actual geometry isnt a POLYGON, null is returned (see _gettype()). +// if there arent enough geometries, return null. +// this is fine to call on a polygon, multipolygon or geometrycollection LWPOLY *lwgeom_getpoly_inspected(LWGEOM_INSPECTED *inspected, int geom_number) { char *sub_geom; @@ -1646,6 +1686,8 @@ int lwgeom_getnumgeometries(char *serialized_form) return get_uint32(loc); } +// how many sub-geometries are there? +// for point,line,polygon will return 1. int lwgeom_getnumgeometries_inspected(LWGEOM_INSPECTED *inspected) { return inspected->ngeometries; @@ -1859,7 +1901,7 @@ int lwgeom_seralizedformlength_inspected(LWGEOM_INSPECTED *inspected, int geom_n //get bounding box of LWGEOM (automatically calls the sub-geometries bbox generators) -//dont forget to pfree() +//dont forget to pfree() result BOX3D *lw_geom_getBB(char *serialized_form) { LWGEOM_INSPECTED *inspected = lwgeom_inspect(serialized_form); @@ -1870,6 +1912,7 @@ BOX3D *lw_geom_getBB(char *serialized_form) return result; } +//dont forget to pfree() result BOX3D *lw_geom_getBB_simple(char *serialized_form) { char type = lwgeom_getType((unsigned char) serialized_form[0]); @@ -1928,7 +1971,7 @@ BOX3D *lw_geom_getBB_simple(char *serialized_form) loc +=4; result = NULL; - + // each sub-type for (t=0;ta) diff --git a/lwgeom/lwgeom_gist.c b/lwgeom/lwgeom_gist.c index 0fcc57d90..820e80aa2 100644 --- a/lwgeom/lwgeom_gist.c +++ b/lwgeom/lwgeom_gist.c @@ -17,6 +17,8 @@ #include "lwgeom.h" #include "stringBuffer.h" +// implementation GiST support and basic LWGEOM operations (like &&) + //#define DEBUG //#define DEBUG_GIST @@ -44,7 +46,7 @@ static bool lwgeom_rtree_leaf_consistent(BOX2DFLOAT4 *key,BOX2DFLOAT4 *query, St - +// for debugging int counter_leaf = 0; int counter_intern = 0; @@ -297,7 +299,7 @@ Datum gist_lwgeom_compress(PG_FUNCTION_ARGS) if (lwgeom_getnumgeometries(in+4) ==0) // this is the EMPTY geometry { -elog(NOTICE,"found an empty geometry"); +//elog(NOTICE,"found an empty geometry"); // dont bother adding this to the index PG_RETURN_POINTER(entry); } @@ -375,7 +377,7 @@ Datum gist_lwgeom_consistent(PG_FUNCTION_ARGS) //pfree(box3d); //convert_box3d_to_box_p( &(query->bvol) , &thebox); //thebox = getBOX2D_cache(query); - getbox2d_p(query+4, &box); + getbox2d_p(query+4, &box); if (GIST_LEAF(entry)) result = lwgeom_rtree_leaf_consistent((BOX2DFLOAT4 *) DatumGetPointer(entry->key), &box, strategy ); @@ -418,6 +420,7 @@ static bool lwgeom_rtree_internal_consistent(BOX2DFLOAT4 *key, #ifdef DEBUG_GIST5 +//keep track and report info about how many times this is called if (counter_intern == 0) { elog(NOTICE,"search bounding box is: <%.16g %.16g,%.16g %.16g> - size box2d= %i", @@ -480,6 +483,8 @@ static bool lwgeom_rtree_leaf_consistent(BOX2DFLOAT4 *key, ((query->ymax>= key->ymax) && (query->ymin<= key->ymax))); #ifdef DEBUG_GIST5 +//keep track and report info about how many times this is called + elog(NOTICE,"%i:gist test (leaf) <%.6g %.6g,%.6g %.6g> && <%.6g %.6g,%.6g %.6g> --> %i",counter_leaf,key->xmin,key->ymin,key->xmax,key->ymax, query->xmin,query->ymin,query->xmax,query->ymax, (int) retval); #endif @@ -569,6 +574,10 @@ Datum lwgeom_box_union(PG_FUNCTION_ARGS) PG_RETURN_POINTER(pageunion); } + +// size of a box is width*height +// we do this in double precision because width and height can be very very small +// and it gives screwy results static float size_box2d(Datum box2d) { @@ -596,6 +605,10 @@ static float size_box2d(Datum box2d) return result; } +// size of a box is width*height +// we do this in double precision because width and height can be very very small +// and it gives screwy results +// this version returns a double static double size_box2d_double(Datum box2d); static double size_box2d_double(Datum box2d) { @@ -1020,12 +1033,15 @@ elog(NOTICE,aaa); PG_RETURN_POINTER(v); } -Datum report_lwgeom_gist_activity(PG_FUNCTION_ARGS); +// debug function +Datum report_lwgeom_gist_activity(PG_FUNCTION_ARGS); PG_FUNCTION_INFO_V1(report_lwgeom_gist_activity); Datum report_lwgeom_gist_activity(PG_FUNCTION_ARGS) { elog(NOTICE,"lwgeom gist activity - internal consistency= %i, leaf consistency = %i",counter_intern,counter_leaf); + counter_intern =0; //reset + counter_leaf = 0; PG_RETURN_NULL(); } diff --git a/lwgeom/lwgeom_inout.c b/lwgeom/lwgeom_inout.c index 7a975ccfe..5b7736c28 100644 --- a/lwgeom/lwgeom_inout.c +++ b/lwgeom/lwgeom_inout.c @@ -18,7 +18,7 @@ #include "stringBuffer.h" -#define DEBUG +//#define DEBUG #include "wktparse.h" @@ -56,6 +56,8 @@ Datum LWGEOM_getBBOX(PG_FUNCTION_ARGS); Datum parse_WKT_lwgeom(PG_FUNCTION_ARGS); + +// included here so we can be independent from postgis // WKB structure -- exactly the same as TEXT typedef struct Well_known_bin { int32 size; // total size of this structure @@ -92,6 +94,8 @@ Datum LWGEOM_in(PG_FUNCTION_ARGS) start =semicolonLoc[1]; // one in } + // this is included just for redundancy (new parser can handle wkt and wkb) + if ( ( (start >= '0') && (start <= '9') ) || ( (start >= 'A') && (start <= 'F') ) @@ -474,7 +478,7 @@ unsigned char parse_hex(char *str) } - +// for the parser/unparser -- it needs memory management functions void *palloc_fn2(size_t size) { void * result; @@ -494,7 +498,7 @@ void free_fn(void *ptr) - +//convert LWGEOM to wkt (in TEXT format) PG_FUNCTION_INFO_V1(LWGEOM_asText); Datum LWGEOM_asText(PG_FUNCTION_ARGS) { @@ -567,6 +571,7 @@ Datum LWGEOM_addBBOX(PG_FUNCTION_ARGS) } +//for the wkt parser void elog_ERROR(const char* string) { @@ -581,6 +586,9 @@ void *palloc_fn(size_t size) return result; } + +// parse WKT input +// parse_WKT_lwgeom(TEXT) -> LWGEOM PG_FUNCTION_INFO_V1(parse_WKT_lwgeom); Datum parse_WKT_lwgeom(PG_FUNCTION_ARGS) { diff --git a/lwgeom/regress/run_regress2 b/lwgeom/regress/run_regress2 index 9b2b3776c..50736746b 100755 --- a/lwgeom/regress/run_regress2 +++ b/lwgeom/regress/run_regress2 @@ -7,6 +7,8 @@ echo "Building a database for testing (lwgeom_reg) on port 5432." echo "Building postgis and lwgeom support in it." echo "" echo "there shouldnt be any real output produced after this line." +echo "NOTE: on solaris machines you will get reports involving 'Inf' and 'Infinity'" +echo " this isnt a problem" echo "" createdb lwgeom_reg createlang plpgsql lwgeom_reg