- Timestamp:
- 11/24/11 14:04:15 (6 months ago)
- Location:
- spike/pramsey/doublebox
- Files:
-
- 15 modified
-
liblwgeom/cunit/cu_geodetic.c (modified) (2 diffs)
-
liblwgeom/cunit/cu_libgeom.c (modified) (1 diff)
-
liblwgeom/g_box.c (modified) (2 diffs)
-
liblwgeom/g_serialized.c (modified) (8 diffs)
-
liblwgeom/liblwgeom.h.in (modified) (1 diff)
-
liblwgeom/lwgeom.c (modified) (1 diff)
-
libpgcommon/gserialized_gist.c (modified) (7 diffs)
-
libpgcommon/gserialized_gist.h (modified) (2 diffs)
-
libpgcommon/lwgeom_pg.h (modified) (1 diff)
-
postgis/geography_measurement.c (modified) (1 diff)
-
postgis/gserialized_gist_2d.c (modified) (2 diffs)
-
postgis/gserialized_gist_nd.c (modified) (2 diffs)
-
postgis/lwgeom_functions_basic.c (modified) (1 diff)
-
postgis/lwgeom_inout.c (modified) (2 diffs)
-
regress/lwgeom_regress_expected (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
spike/pramsey/doublebox/liblwgeom/cunit/cu_geodetic.c
r8029 r8240 582 582 type = gserialized_get_type(g); 583 583 CU_ASSERT_EQUAL( type, POLYGONTYPE ); 584 inspect = (double*)g; 585 CU_ASSERT_EQUAL(inspect[9], 2.5); 584 /* data + box size + type + nrings + npoints1 + npoints2 */ 585 inspect = (double*)(g->data + gbox_serialized_size(g->flags) + 4 + 4 + 4 + 4); 586 CU_ASSERT_EQUAL(inspect[3], 2.5); 586 587 lwgeom_free(geom); 587 588 lwfree(g); … … 592 593 type = gserialized_get_type(g); 593 594 CU_ASSERT_EQUAL( type, MULTILINETYPE ); 594 inspect = (double*)g; 595 CU_ASSERT_EQUAL(inspect[12], 0.1); 595 /* data + box size + type + ngeoms + subtype + npoints + 2 points + type + npoints */ 596 inspect = (double*)(g->data + gbox_serialized_size(g->flags) + 4 + 4 + 4 + 4 + 8*4 + 4 + 4); 597 CU_ASSERT_EQUAL(inspect[1], 0.1); 596 598 lwgeom_free(geom); 597 599 lwfree(g); -
spike/pramsey/doublebox/liblwgeom/cunit/cu_libgeom.c
r8200 r8240 172 172 { 173 173 uint8_t flags = gflags(0, 0, 0); 174 CU_ASSERT_EQUAL(gbox_serialized_size(flags), 16);174 CU_ASSERT_EQUAL(gbox_serialized_size(flags),32); 175 175 FLAGS_SET_BBOX(flags, 1); 176 CU_ASSERT_EQUAL(gbox_serialized_size(flags), 16);176 CU_ASSERT_EQUAL(gbox_serialized_size(flags),32); 177 177 FLAGS_SET_Z(flags, 1); 178 CU_ASSERT_EQUAL(gbox_serialized_size(flags), 24);178 CU_ASSERT_EQUAL(gbox_serialized_size(flags),48); 179 179 FLAGS_SET_M(flags, 1); 180 CU_ASSERT_EQUAL(gbox_serialized_size(flags), 32);180 CU_ASSERT_EQUAL(gbox_serialized_size(flags),64); 181 181 FLAGS_SET_GEODETIC(flags, 1); 182 CU_ASSERT_EQUAL(gbox_serialized_size(flags), 24);182 CU_ASSERT_EQUAL(gbox_serialized_size(flags),48); 183 183 184 184 } -
spike/pramsey/doublebox/liblwgeom/g_box.c
r8053 r8240 78 78 g->ymin -= d; 79 79 g->ymax += d; 80 if ( FLAGS_GET_ Z(g->flags) )80 if ( FLAGS_GET_GEODETIC(g->flags) ) 81 81 { 82 82 g->zmin -= d; 83 83 g->zmax += d; 84 84 } 85 if ( FLAGS_GET_M(g->flags) ) 86 { 87 g->mmin -= d; 88 g->mmax += d; 85 else 86 { 87 if ( FLAGS_GET_Z(g->flags) ) 88 { 89 g->zmin -= d; 90 g->zmax += d; 91 } 92 if ( FLAGS_GET_M(g->flags) ) 93 { 94 g->mmin -= d; 95 g->mmax += d; 96 } 89 97 } 90 98 } … … 296 304 { 297 305 if ( FLAGS_GET_GEODETIC(flags) ) 298 return 6 * sizeof( float);306 return 6 * sizeof(double); 299 307 else 300 return 2 * FLAGS_NDIMS(flags) * sizeof( float);308 return 2 * FLAGS_NDIMS(flags) * sizeof(double); 301 309 } 302 310 -
spike/pramsey/doublebox/liblwgeom/g_serialized.c
r8204 r8240 156 156 { 157 157 int i = 0; 158 float *fbox = (float*)(g->data);158 double *fbox = (double*)(g->data); 159 159 gbox->xmin = fbox[i++]; 160 160 gbox->xmax = fbox[i++]; … … 202 202 gbox->mmin = gbox->mmax = dptr[i++]; 203 203 } 204 gbox_float_round(gbox);204 // gbox_float_round(gbox); 205 205 return LW_SUCCESS; 206 206 } … … 242 242 gbox->zmax = FP_MAX(dptr[i], dptr[i+ndims]); 243 243 } 244 gbox_float_round(gbox);244 // gbox_float_round(gbox); 245 245 return LW_SUCCESS; 246 246 } … … 251 251 return LW_FAILURE; 252 252 } 253 /* We could also do single-entry two-point multi-linestrings */ 254 else if ( type == MULTILINETYPE ) 255 { 256 /* TODO: Make this actually happen */ 257 return LW_FAILURE; 258 } 253 259 } 254 260 return LW_FAILURE; … … 268 274 lwgeom = lwgeom_from_gserialized(geom); 269 275 ret = lwgeom_calculate_gbox(lwgeom, box); 270 gbox_float_round(box);276 // gbox_float_round(box); 271 277 lwgeom_free(lwgeom); 272 278 } … … 716 722 } 717 723 718 static size_t gserialized_from_gbox(const GBOX *gbox, uint8_t *buf) 719 { 720 uint8_t *loc = buf; 721 float f; 724 size_t gserialized_from_gbox(const GBOX *gbox, uint8_t *buf) 725 { 726 double* loc = (double*)buf; 722 727 size_t return_size; 723 728 724 729 assert(buf); 725 730 726 f = next_float_down(gbox->xmin); 727 memcpy(loc, &f, sizeof(float)); 728 loc += sizeof(float); 729 730 f = next_float_up(gbox->xmax); 731 memcpy(loc, &f, sizeof(float)); 732 loc += sizeof(float); 733 734 f = next_float_down(gbox->ymin); 735 memcpy(loc, &f, sizeof(float)); 736 loc += sizeof(float); 737 738 f = next_float_up(gbox->ymax); 739 memcpy(loc, &f, sizeof(float)); 740 loc += sizeof(float); 731 *loc = gbox->xmin; loc++; 732 *loc = gbox->xmax; loc++; 733 *loc = gbox->ymin; loc++; 734 *loc = gbox->ymax; loc++; 741 735 742 736 if ( FLAGS_GET_GEODETIC(gbox->flags) ) 743 737 { 744 f = next_float_down(gbox->zmin); 745 memcpy(loc, &f, sizeof(float)); 746 loc += sizeof(float); 747 748 f = next_float_up(gbox->zmax); 749 memcpy(loc, &f, sizeof(float)); 750 loc += sizeof(float); 751 752 return_size = (size_t)(loc - buf); 738 *loc = gbox->zmin; loc++; 739 *loc = gbox->zmax; loc++; 740 741 return_size = (size_t)(((uint8_t*)loc) - buf); 753 742 LWDEBUGF(4, "returning size %d", return_size); 754 743 return return_size; … … 757 746 if ( FLAGS_GET_Z(gbox->flags) ) 758 747 { 759 f = next_float_down(gbox->zmin); 760 memcpy(loc, &f, sizeof(float)); 761 loc += sizeof(float); 762 763 f = next_float_up(gbox->zmax); 764 memcpy(loc, &f, sizeof(float)); 765 loc += sizeof(float); 766 748 *loc = gbox->zmin; loc++; 749 *loc = gbox->zmax; loc++; 767 750 } 768 751 769 752 if ( FLAGS_GET_M(gbox->flags) ) 770 753 { 771 f = next_float_down(gbox->mmin); 772 memcpy(loc, &f, sizeof(float)); 773 loc += sizeof(float); 774 775 f = next_float_up(gbox->mmax); 776 memcpy(loc, &f, sizeof(float)); 777 loc += sizeof(float); 778 } 779 return_size = (size_t)(loc - buf); 754 *loc = gbox->mmin; loc++; 755 *loc = gbox->mmax; loc++; 756 } 757 return_size = (size_t)(((uint8_t*)loc) - buf); 780 758 LWDEBUGF(4, "returning size %d", return_size); 781 759 return return_size; … … 796 774 ** See if we need a bounding box, add one if we don't have one. 797 775 */ 798 if ( (! geom->bbox) && lwgeom_needs_bbox(geom) && (!lwgeom_is_empty(geom)) ) 799 { 776 if ( lwgeom_needs_bbox(geom) ) 800 777 lwgeom_add_bbox(geom); 801 } 778 // else 779 // lwgeom_drop_bbox(geom); 802 780 803 781 /* -
spike/pramsey/doublebox/liblwgeom/liblwgeom.h.in
r8229 r8240 1384 1384 1385 1385 /** 1386 * Write a serialized box into a byte buffer and return the size of 1387 * the segment written. 1388 */ 1389 extern size_t gserialized_from_gbox(const GBOX *gbox, uint8_t *buf); 1390 1391 /** 1386 1392 * Return a copy of the input serialized geometry. 1387 1393 */ -
spike/pramsey/doublebox/liblwgeom/lwgeom.c
r8046 r8240 912 912 { 913 913 assert(geom); 914 if ( geom->type == POINTTYPE )914 if ( geom->type == POINTTYPE || lwgeom_is_empty(geom) ) 915 915 { 916 916 return LW_FALSE; 917 917 } 918 918 919 return LW_TRUE; 919 920 } -
spike/pramsey/doublebox/libpgcommon/gserialized_gist.c
r7786 r8240 49 49 #endif 50 50 51 /** 52 * How many dimensions should a bounding box for this flag set have? 53 * Geodetic objects always have 3D boxes. Other objects have boxes 54 * with the same dimensionality as their coordinates. 55 */ 56 static inline int 57 gbox_ndims(uint8_t flags) 58 { 59 return FLAGS_GET_GEODETIC(flags) ? 3 : FLAGS_NDIMS(flags); 60 } 51 61 52 62 /** 53 63 * Given a #GSERIALIZED datum, as quickly as possible (peaking into the top 54 64 * of the memory) return the gbox extents. Does not deserialize the geometry, 55 * but <em>WARNING</em> returns a slightly larger bounding box than actually 56 * encompasses the objects. For geography objects returns geocentric bounding 65 * For geography objects returns geocentric bounding 57 66 * box, for geometry objects returns cartesian bounding box. 58 67 */ … … 60 69 gserialized_datum_get_gbox_p(Datum gsdatum, GBOX *gbox) 61 70 { 62 char gboxmem[GIDX_MAX_SIZE]; 63 GIDX *gidx = (GIDX*)gboxmem; 71 GSERIALIZED *gpart; 72 int result = LW_SUCCESS; 73 74 POSTGIS_DEBUG(4, "entered function"); 75 76 /* 77 ** The most info we need is the 8 bytes of serialized header plus the 64 bytes 78 ** of floats necessary to hold the 8 floats of the largest XYZM index 79 ** bounding box, so 72 bytes. 80 */ 81 gpart = (GSERIALIZED*)PG_DETOAST_DATUM_SLICE(gsdatum, 0, 72); 82 83 POSTGIS_DEBUGF(4, "got flags %d", gpart->flags); 84 85 /* Do we even have a serialized bounding box? */ 86 if ( FLAGS_GET_BBOX(gpart->flags) ) 87 { 88 /* Yes! Copy it out into the GBOX! */ 89 double *d = (double*)(gpart->data); 90 gbox->flags = gpart->flags; 91 gbox->xmin = *d; d++; 92 gbox->xmax = *d; d++; 93 gbox->ymin = *d; d++; 94 gbox->ymax = *d; d++; 95 96 if ( FLAGS_GET_GEODETIC(gpart->flags) ) 97 { 98 gbox->zmin = *d; d++; 99 gbox->zmax = *d; d++; 100 return LW_SUCCESS; 101 } 102 if ( FLAGS_GET_Z(gpart->flags) ) 103 { 104 gbox->zmin = *d; d++; 105 gbox->zmax = *d; d++; 106 } 107 if ( FLAGS_GET_M(gpart->flags) ) 108 { 109 gbox->mmin = *d; d++; 110 gbox->mmax = *d; d++; 111 } 112 result = LW_SUCCESS; 113 114 } 115 else 116 { 117 /* No, we need to calculate it from the full object. */ 118 GSERIALIZED *g = (GSERIALIZED*)PG_DETOAST_DATUM(gsdatum); 119 LWGEOM *lwgeom = lwgeom_from_gserialized(g); 120 if ( lwgeom_calculate_gbox(lwgeom, gbox) == LW_FAILURE ) 121 { 122 POSTGIS_DEBUG(4, "could not calculate bbox, returning failure"); 123 lwgeom_free(lwgeom); 124 return LW_FAILURE; 125 } 126 lwgeom_free(lwgeom); 127 result = LW_SUCCESS; 128 } 64 129 65 if ( LW_FAILURE == gserialized_datum_get_gidx_p(gsdatum, gidx))66 return LW_FAILURE;67 68 gbox_from_gidx(gidx, gbox);69 return LW_SUCCESS; 70 } 71 130 if ( result == LW_SUCCESS ) 131 { 132 POSTGIS_DEBUGF(4, "got gbox %s", gbox_to_string(gidx)); 133 } 134 135 return result; 136 } 72 137 73 138 /** … … 79 144 * like mismatched dimensions. 80 145 */ 81 GSERIALIZED* gserialized_set_g idx(GSERIALIZED *g, GIDX *gidx)82 { 83 int g_ndims = (FLAGS_GET_GEODETIC(g->flags) ? 3 : FLAGS_NDIMS(g->flags));84 int box_ndims = GIDX_NDIMS(gidx);146 GSERIALIZED* gserialized_set_gbox(GSERIALIZED *g, GBOX *gbox) 147 { 148 int g_ndims = gbox_ndims(g->flags); 149 int box_ndims = gbox_ndims(gbox->flags); 85 150 GSERIALIZED *g_out = NULL; 86 size_t box_size = 2 * g_ndims * sizeof(float); 151 size_t box_size = gbox_serialized_size(g->flags); 152 size_t write_size; 87 153 88 154 /* The dimensionality of the inputs has to match or we are SOL. */ … … 117 183 118 184 /* Now write the gidx values into the memory segement */ 119 memcpy(g_out->data, gidx->c, box_size); 185 write_size = gserialized_from_gbox(gbox, (uint8_t*)g_out->data); 186 187 /* Write length should match memory segment length */ 188 if ( write_size != box_size ) 189 { 190 return NULL; 191 } 120 192 121 193 return g_out; 122 194 } 123 124 195 125 196 /** … … 127 198 * allocated #GSERIALIZED every time. 128 199 */ 129 GSERIALIZED* gserialized_drop_gidx(GSERIALIZED *g) 130 { 131 int g_ndims = (FLAGS_GET_GEODETIC(g->flags) ? 3 : FLAGS_NDIMS(g->flags)); 132 size_t box_size = 2 * g_ndims * sizeof(float); 200 GSERIALIZED* gserialized_drop_gbox(GSERIALIZED *g) 201 { 202 size_t box_size = gbox_serialized_size(g->flags);; 133 203 size_t g_out_size = VARSIZE(g) - box_size; 134 204 GSERIALIZED *g_out = palloc(g_out_size); … … 158 228 159 229 160 /* Convert a double-based GBOX into a float-based GIDX, 161 ensuring the float box is larger than the double box */ 162 static int gidx_from_gbox_p(GBOX box, GIDX *a) 163 { 164 int ndims; 165 166 ndims = (FLAGS_GET_GEODETIC(box.flags) ? 3 : FLAGS_NDIMS(box.flags)); 230 /** 231 * Convert a double-based GBOX into a float-based GIDX, 232 * ensuring the float box is larger than the double box 233 */ 234 static int 235 gidx_from_gbox(const GBOX *box, GIDX *a) 236 { 237 int ndims = gbox_ndims(box->flags); 238 167 239 SET_VARSIZE(a, VARHDRSZ + ndims * 2 * sizeof(float)); 168 240 169 GIDX_SET_MIN(a,0,next_float_down(box .xmin));170 GIDX_SET_MAX(a,0,next_float_up(box .xmax));171 GIDX_SET_MIN(a,1,next_float_down(box .ymin));172 GIDX_SET_MAX(a,1,next_float_up(box .ymax));241 GIDX_SET_MIN(a,0,next_float_down(box->xmin)); 242 GIDX_SET_MAX(a,0,next_float_up(box->xmax)); 243 GIDX_SET_MIN(a,1,next_float_down(box->ymin)); 244 GIDX_SET_MAX(a,1,next_float_up(box->ymax)); 173 245 174 246 /* Geodetic indexes are always 3d, geocentric x/y/z */ 175 if ( FLAGS_GET_GEODETIC(box .flags) )176 { 177 GIDX_SET_MIN(a,2,next_float_down(box .zmin));178 GIDX_SET_MAX(a,2,next_float_up(box .zmax));247 if ( FLAGS_GET_GEODETIC(box->flags) ) 248 { 249 GIDX_SET_MIN(a,2,next_float_down(box->zmin)); 250 GIDX_SET_MAX(a,2,next_float_up(box->zmax)); 179 251 } 180 252 else 181 253 { 182 254 /* Cartesian with Z implies Z is third dimension */ 183 if ( FLAGS_GET_Z(box .flags) )184 { 185 GIDX_SET_MIN(a,2,next_float_down(box .zmin));186 GIDX_SET_MAX(a,2,next_float_up(box .zmax));187 if ( FLAGS_GET_M(box .flags) )255 if ( FLAGS_GET_Z(box->flags) ) 256 { 257 GIDX_SET_MIN(a,2,next_float_down(box->zmin)); 258 GIDX_SET_MAX(a,2,next_float_up(box->zmax)); 259 if ( FLAGS_GET_M(box->flags) ) 188 260 { 189 GIDX_SET_MIN(a,3,next_float_down(box .mmin));190 GIDX_SET_MAX(a,3,next_float_up(box .mmax));261 GIDX_SET_MIN(a,3,next_float_down(box->mmin)); 262 GIDX_SET_MAX(a,3,next_float_up(box->mmax)); 191 263 } 192 264 } 193 265 /* Unless there's no Z, in which case M is third dimension */ 194 else if ( FLAGS_GET_M(box .flags) )195 { 196 GIDX_SET_MIN(a,2,next_float_down(box .mmin));197 GIDX_SET_MAX(a,2,next_float_up(box .mmax));198 } 199 } 200 201 POSTGIS_DEBUGF(5, "converted %s to %s", gbox_to_string( &box), gidx_to_string(a));266 else if ( FLAGS_GET_M(box->flags) ) 267 { 268 GIDX_SET_MIN(a,2,next_float_down(box->mmin)); 269 GIDX_SET_MAX(a,2,next_float_up(box->mmax)); 270 } 271 } 272 273 POSTGIS_DEBUGF(5, "converted %s to %s", gbox_to_string(box), gidx_to_string(a)); 202 274 203 275 return LW_SUCCESS; 204 }205 206 207 GIDX* gidx_from_gbox(GBOX box)208 {209 int ndims;210 GIDX *a;211 212 ndims = (FLAGS_GET_GEODETIC(box.flags) ? 3 : FLAGS_NDIMS(box.flags));213 a = gidx_new(ndims);214 gidx_from_gbox_p(box, a);215 return a;216 276 } 217 277 … … 236 296 gserialized_datum_get_gidx_p(Datum gsdatum, GIDX *gidx) 237 297 { 238 GSERIALIZED *gpart; 239 int result = LW_SUCCESS; 240 241 POSTGIS_DEBUG(4, "entered function"); 242 243 /* 244 ** The most info we need is the 8 bytes of serialized header plus the 32 bytes 245 ** of floats necessary to hold the 8 floats of the largest XYZM index 246 ** bounding box, so 40 bytes. 247 */ 248 gpart = (GSERIALIZED*)PG_DETOAST_DATUM_SLICE(gsdatum, 0, 40); 249 250 POSTGIS_DEBUGF(4, "got flags %d", gpart->flags); 251 252 /* Do we even have a serialized bounding box? */ 253 if ( FLAGS_GET_BBOX(gpart->flags) ) 254 { 255 /* Yes! Copy it out into the GIDX! */ 256 const size_t size = gbox_serialized_size(gpart->flags); 257 POSTGIS_DEBUG(4, "copying box out of serialization"); 258 memcpy(gidx->c, gpart->data, size); 259 SET_VARSIZE(gidx, VARHDRSZ + size); 260 result = LW_SUCCESS; 261 } 262 else 263 { 264 /* No, we need to calculate it from the full object. */ 265 GSERIALIZED *g = (GSERIALIZED*)PG_DETOAST_DATUM(gsdatum); 266 LWGEOM *lwgeom = lwgeom_from_gserialized(g); 267 GBOX gbox; 268 if ( lwgeom_calculate_gbox(lwgeom, &gbox) == LW_FAILURE ) 269 { 270 POSTGIS_DEBUG(4, "could not calculate bbox, returning failure"); 271 lwgeom_free(lwgeom); 272 return LW_FAILURE; 273 } 274 lwgeom_free(lwgeom); 275 result = gidx_from_gbox_p(gbox, gidx); 276 } 277 278 if ( result == LW_SUCCESS ) 279 { 280 POSTGIS_DEBUGF(4, "got gidx %s", gidx_to_string(gidx)); 281 } 282 283 return result; 284 } 285 286 287 /* 288 ** Peak into a geography to find the bounding box. If the 289 ** box is there, copy it out and return it. If not, calculate the box from the 290 ** full geography and return the box based on that. If no box is available, 291 ** return LW_FAILURE, otherwise LW_SUCCESS. 292 */ 293 int gserialized_get_gidx_p(GSERIALIZED *g, GIDX *gidx) 294 { 295 int result = LW_SUCCESS; 296 297 POSTGIS_DEBUG(4, "entered function"); 298 299 POSTGIS_DEBUGF(4, "got flags %d", g->flags); 300 301 if ( FLAGS_GET_BBOX(g->flags) ) 302 { 303 int ndims = FLAGS_NDIMS_BOX(g->flags); 304 const size_t size = 2 * ndims * sizeof(float); 305 POSTGIS_DEBUG(4, "copying box out of serialization"); 306 memcpy(gidx->c, g->data, size); 307 SET_VARSIZE(gidx, VARHDRSZ + size); 308 } 309 else 310 { 311 /* No, we need to calculate it from the full object. */ 312 LWGEOM *lwgeom = lwgeom_from_gserialized(g); 313 GBOX gbox; 314 if ( lwgeom_calculate_gbox(lwgeom, &gbox) == LW_FAILURE ) 315 { 316 POSTGIS_DEBUG(4, "could not calculate bbox, returning failure"); 317 lwgeom_free(lwgeom); 318 return LW_FAILURE; 319 } 320 lwgeom_free(lwgeom); 321 result = gidx_from_gbox_p(gbox, gidx); 322 } 323 if ( result == LW_SUCCESS ) 324 { 325 POSTGIS_DEBUGF(4, "got gidx %s", gidx_to_string(gidx)); 326 } 327 328 return result; 298 GBOX gbox; 299 300 if ( (gserialized_datum_get_gbox_p(gsdatum, &gbox) == LW_SUCCESS) && 301 (gidx_from_gbox(&gbox, gidx) == LW_SUCCESS) ) 302 { 303 return LW_SUCCESS; 304 } 305 return LW_FAILURE; 329 306 } 330 307 -
spike/pramsey/doublebox/libpgcommon/gserialized_gist.h
r7786 r8240 54 54 /* Convert a gidx to a gbox */ 55 55 void gbox_from_gidx(GIDX *gidx, GBOX *gbox); 56 /* Convert a gbox to a new gidx */57 GIDX* gidx_from_gbox(GBOX box);58 56 /* Increase the size of a GIDX */ 59 57 void gidx_expand(GIDX *a, float d); … … 88 86 int gserialized_datum_get_gidx_p(Datum gserialized_datum, GIDX *gidx); 89 87 90 /* Pull out the gidx bounding box from an already de-toasted geography */91 int gserialized_get_gidx_p(GSERIALIZED *g, GIDX *gidx);92 88 /* Copy a new bounding box into an existing gserialized */ 93 GSERIALIZED* gserialized_set_g idx(GSERIALIZED *g, GIDX *gidx);89 GSERIALIZED* gserialized_set_gbox(GSERIALIZED *g, GBOX *gbox); 94 90 95 91 /* Pull out a gbox bounding box as fast as possible. */ 96 92 int gserialized_datum_get_gbox_p(Datum gsdatum, GBOX *gbox); 97 /* Given two datums, do they overlap? Computed very fast using embedded boxes. */ 98 /* int gserialized_datum_overlaps(Datum gs1, Datum gs2); */ 93 99 94 /* Remove the box from a disk serialization */ 100 GSERIALIZED* gserialized_drop_g idx(GSERIALIZED *g);95 GSERIALIZED* gserialized_drop_gbox(GSERIALIZED *g); 101 96 102 97 -
spike/pramsey/doublebox/libpgcommon/lwgeom_pg.h
r8067 r8240 87 87 */ 88 88 89 /** 90 * Remove the embedded bounding box89 /** 90 * Remove the box from a disk serialization 91 91 */ 92 GSERIALIZED* gserialized_drop_g idx(GSERIALIZED *g);92 GSERIALIZED* gserialized_drop_gbox(GSERIALIZED *g); 93 93 94 94 /** -
spike/pramsey/doublebox/postgis/geography_measurement.c
r8066 r8240 186 186 g_out = gserialized_expand(g, distance); 187 187 188 /* If the expansion fails, the return our input */188 /* If the expansion fails, then return our input */ 189 189 if ( g_out == NULL ) 190 190 { -
spike/pramsey/doublebox/postgis/gserialized_gist_2d.c
r7910 r8240 203 203 /* Convert a double-based GBOX into a float-based BOX2DF, 204 204 ensuring the float box is larger than the double box */ 205 static inline int box2df_from_gbox_p( GBOX *box, BOX2DF *a)205 static inline int box2df_from_gbox_p(const GBOX *box, BOX2DF *a) 206 206 { 207 207 a->xmin = next_float_down(box->xmin); … … 479 479 gserialized_datum_get_box2df_p(Datum gsdatum, BOX2DF *box2df) 480 480 { 481 GSERIALIZED *gpart; 482 uint8_t flags; 483 int result = LW_SUCCESS; 484 485 POSTGIS_DEBUG(4, "entered function"); 486 487 /* 488 ** The most info we need is the 8 bytes of serialized header plus the 489 ** of floats necessary to hold the bounding box. 490 */ 491 gpart = (GSERIALIZED*)PG_DETOAST_DATUM_SLICE(gsdatum, 0, 8 + sizeof(BOX2DF)); 492 flags = gpart->flags; 493 494 POSTGIS_DEBUGF(4, "got flags %d", gpart->flags); 495 496 /* Do we even have a serialized bounding box? */ 497 if ( FLAGS_GET_BBOX(flags) ) 498 { 499 /* Yes! Copy it out into the box! */ 500 POSTGIS_DEBUG(4, "copying box out of serialization"); 501 memcpy(box2df, gpart->data, sizeof(BOX2DF)); 502 result = LW_SUCCESS; 503 } 504 else 505 { 506 /* No, we need to calculate it from the full object. */ 507 GBOX gbox; 508 GSERIALIZED *g = (GSERIALIZED*)PG_DETOAST_DATUM(gsdatum); 509 LWGEOM *lwgeom = lwgeom_from_gserialized(g); 510 if ( lwgeom_calculate_gbox(lwgeom, &gbox) == LW_FAILURE ) 511 { 512 POSTGIS_DEBUG(4, "could not calculate bbox, returning failure"); 513 lwgeom_free(lwgeom); 514 return LW_FAILURE; 515 } 516 lwgeom_free(lwgeom); 517 result = box2df_from_gbox_p(&gbox, box2df); 518 } 519 520 if ( result == LW_SUCCESS ) 521 { 522 POSTGIS_DEBUGF(4, "got box2df %s", box2df_to_string(box2df)); 523 } 524 525 return result; 526 } 481 GBOX gbox; 482 483 if ( (gserialized_datum_get_gbox_p(gsdatum, &gbox) == LW_SUCCESS) && 484 (box2df_from_gbox_p(&gbox, box2df) == LW_SUCCESS) ) 485 { 486 return LW_SUCCESS; 487 } 488 return LW_FAILURE; 489 } 527 490 528 491 -
spike/pramsey/doublebox/postgis/gserialized_gist_nd.c
r7786 r8240 400 400 gserialized_expand(GSERIALIZED *g, double distance) 401 401 { 402 char boxmem[GIDX_MAX_SIZE]; 403 GIDX *gidx = (GIDX*)boxmem; 404 float fdistance = (float)distance; 402 GBOX gbox; 405 403 406 404 /* Get our bounding box out of the geography, return right away if 407 405 input is an EMPTY geometry. */ 408 if ( gserialized_get_g idx_p(g, gidx) == LW_FAILURE )406 if ( gserialized_get_gbox_p(g, &gbox) == LW_FAILURE ) 409 407 { 410 408 return g; 411 409 } 412 410 413 g idx_expand(gidx, fdistance);414 415 return gserialized_set_g idx(g, gidx);411 gbox_expand(&gbox, distance); 412 413 return gserialized_set_gbox(g, &gbox); 416 414 } 417 415 … … 422 420 /* 423 421 ** '~' and operator function. Based on two serialized return true if 424 ** the first is contained by the second.422 ** the second is contained by the first. 425 423 */ 426 424 PG_FUNCTION_INFO_V1(gserialized_within); -
spike/pramsey/doublebox/postgis/lwgeom_functions_basic.c
r8065 r8240 2044 2044 /* Pull only a small amount of the tuple, enough to get the type. */ 2045 2045 /* header + srid/flags + bbox? + type number */ 2046 size = VARHDRSZ + 8 + 32+ 4;2046 size = VARHDRSZ + 8 + 64 + 4; 2047 2047 2048 2048 geom = (GSERIALIZED*)PG_DETOAST_DATUM_SLICE(PG_GETARG_DATUM(0), 0, size); -
spike/pramsey/doublebox/postgis/lwgeom_inout.c
r8051 r8240 390 390 lwgeom_add_bbox(lwgeom); 391 391 result = geometry_serialize(lwgeom); 392 lwgeom_free(lwgeom); 392 393 393 394 PG_FREE_IF_COPY(geom, 0); … … 405 406 PG_RETURN_POINTER(geom); 406 407 407 PG_RETURN_POINTER(gserialized_drop_g idx(geom));408 PG_RETURN_POINTER(gserialized_drop_gbox(geom)); 408 409 } 409 410 -
spike/pramsey/doublebox/regress/lwgeom_regress_expected
r7389 r8240 1 1 BOX(0 0.1,11 12) 2 2 BOX3D(0 0.1 -55,11 12 12) 3 11 1844 158 245 204 646 158 247 11 1843 11200 4 15848 5 20496 6 15848 7 11200
