In the RTree module, make sure all double-to-float conversions round in a

direction to increase the size of element bounding boxes.

FossilOrigin-Name: 0abdc2903d8b3f86cad426e1bac2a959d1b1f7dd
This commit is contained in:
drh 2012-05-29 00:39:50 +00:00
commit 51fec64f65
3 changed files with 39 additions and 9 deletions

View File

@ -2739,6 +2739,36 @@ static int rtreeDeleteRowid(Rtree *pRtree, sqlite3_int64 iDelete){
return rc;
}
/*
** Rounding constants for float->double conversion.
*/
#define RNDTOWARDS (1.0 - 1.0/8388608.0) /* Round towards zero */
#define RNDAWAY (1.0 + 1.0/8388608.0) /* Round away from zero */
#if !defined(SQLITE_RTREE_INT_ONLY)
/*
** Convert an sqlite3_value into an RtreeValue (presumably a float)
** while taking care to round toward negative or positive, respectively.
*/
static RtreeValue rtreeValueDown(sqlite3_value *v){
double d = sqlite3_value_double(v);
float f = (float)d;
if( f>d ){
f = (float)(d*(d<0 ? RNDAWAY : RNDTOWARDS));
}
return f;
}
static RtreeValue rtreeValueUp(sqlite3_value *v){
double d = sqlite3_value_double(v);
float f = (float)d;
if( f<d ){
f = (float)(d*(d<0 ? RNDTOWARDS : RNDAWAY));
}
return f;
}
#endif /* !defined(SQLITE_RTREE_INT_ONLY) */
/*
** The xUpdate method for rtree module virtual tables.
*/
@ -2775,8 +2805,8 @@ static int rtreeUpdate(
#ifndef SQLITE_RTREE_INT_ONLY
if( pRtree->eCoordType==RTREE_COORD_REAL32 ){
for(ii=0; ii<(pRtree->nDim*2); ii+=2){
cell.aCoord[ii].f = (RtreeValue)sqlite3_value_double(azData[ii+3]);
cell.aCoord[ii+1].f = (RtreeValue)sqlite3_value_double(azData[ii+4]);
cell.aCoord[ii].f = rtreeValueDown(azData[ii+3]);
cell.aCoord[ii+1].f = rtreeValueUp(azData[ii+4]);
if( cell.aCoord[ii].f>cell.aCoord[ii+1].f ){
rc = SQLITE_CONSTRAINT;
goto constraint;

View File

@ -1,5 +1,5 @@
C Fix\sthe\sMSVC\smakefile\sso\sthat\sit\sworks\swith\sthe\sunicode61\stokenizer.
D 2012-05-28T20:22:16.462
C In\sthe\sRTree\smodule,\smake\ssure\sall\sdouble-to-float\sconversions\sround\sin\sa\ndirection\sto\sincrease\sthe\ssize\sof\selement\sbounding\sboxes.
D 2012-05-29T00:39:50.223
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
F Makefile.in 4f37eb61be9d38643cdd839a74b8e3bad724cfcf
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@ -83,7 +83,7 @@ F ext/icu/README.txt bf8461d8cdc6b8f514c080e4e10dc3b2bbdfefa9
F ext/icu/icu.c eb9ae1d79046bd7871aa97ee6da51eb770134b5a
F ext/icu/sqliteicu.h 728867a802baa5a96de7495e9689a8e01715ef37
F ext/rtree/README 6315c0d73ebf0ec40dedb5aa0e942bc8b54e3761
F ext/rtree/rtree.c 73502e5336162fdc8f5d1c4bdd4ec6b1299c2f2a
F ext/rtree/rtree.c d17aecb7a92762efa7b1f5d5fd7c88fd77d70827
F ext/rtree/rtree.h 834dbcb82dc85b2481cde6a07cdadfddc99e9b9e
F ext/rtree/rtree1.test e474a2b5eff231496dbd073fe67e5fbaf7f444c9
F ext/rtree/rtree2.test acbb3a4ce0f4fbc2c304d2b4b784cfa161856bba
@ -1004,7 +1004,7 @@ F tool/tostr.awk e75472c2f98dd76e06b8c9c1367f4ab07e122d06
F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
F tool/warnings-clang.sh a8a0a3babda96dfb1ff51adda3cbbf3dfb7266c2
F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381
P bcc72d413e8db5fe8b32147ac22d406e2cd6bb60
R 3124713b2110812cfce2d07ccce3e9e9
P 480158143be1256cbe4dba52ef1a5b96e172b38c f607ad27c1ede27af24dbee10ca867c8f7761ee3
R 38bedd0c37f624ccf215394e11ad9336
U drh
Z e96acf301cc5f997fc3e1f3cdf1b6355
Z 4bf39e44bbbf20a271c4dc152544fd6f

View File

@ -1 +1 @@
480158143be1256cbe4dba52ef1a5b96e172b38c
0abdc2903d8b3f86cad426e1bac2a959d1b1f7dd