From: drh Date: Mon, 28 May 2012 19:19:25 +0000 (+0000) Subject: When converting 64-bit floating point coordinates to 32-bit in RTree, take X-Git-Tag: version-3.7.13~20^2~2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7923863602be76f0146745eb82c7edccb376a37d;p=thirdparty%2Fsqlite.git When converting 64-bit floating point coordinates to 32-bit in RTree, take care to round the values such that the size of the bounding box is enlarged. FossilOrigin-Name: f4e8ff03eae70334632455a867859cfcc25682be --- diff --git a/ext/rtree/rtree.c b/ext/rtree/rtree.c index d6cdde9fc4..4bca5d1af9 100644 --- a/ext/rtree/rtree.c +++ b/ext/rtree/rtree.c @@ -2739,6 +2739,43 @@ static int rtreeDeleteRowid(Rtree *pRtree, sqlite3_int64 iDelete){ return rc; } +/* +** 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){ +#ifdef SQLITE_RTREE_INT_ONLY + return (RtreeValue)sqlite3_value_double(v); +#else + double d = sqlite3_value_double(v); + float f = (float)d; + if( f>d ){ + if( f<0.0 ){ + f += f/8388608.0; + }else{ + f -= f/8388608.0; + } + } + return f; +#endif +} +static RtreeValue rtreeValueUp(sqlite3_value *v){ +#ifdef SQLITE_RTREE_INT_ONLY + return (RtreeValue)sqlite3_value_double(v); +#else + double d = sqlite3_value_double(v); + float f = (float)d; + if( feCoordType==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; diff --git a/manifest b/manifest index 190c862922..dcb03c1932 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Updates\sregarding\sURI\squery\sparameters\sand\sshared\scache\sin\sthe\sdocumentation\nderived\sfrom\scomments\sin\ssqlite.h.in.\s\sNo\schanges\sto\scode. -D 2012-05-28T17:51:53.434 +C When\sconverting\s64-bit\sfloating\spoint\scoordinates\sto\s32-bit\sin\sRTree,\stake\ncare\sto\sround\sthe\svalues\ssuch\sthat\sthe\ssize\sof\sthe\sbounding\sbox\sis\senlarged. +D 2012-05-28T19:19:25.608 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 b8d6cb9273fa39ec722c3d4b624ddfc3aef0d12a F ext/rtree/rtree.h 834dbcb82dc85b2481cde6a07cdadfddc99e9b9e F ext/rtree/rtree1.test e474a2b5eff231496dbd073fe67e5fbaf7f444c9 F ext/rtree/rtree2.test acbb3a4ce0f4fbc2c304d2b4b784cfa161856bba @@ -1004,7 +1004,10 @@ F tool/tostr.awk e75472c2f98dd76e06b8c9c1367f4ab07e122d06 F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f F tool/warnings-clang.sh a8a0a3babda96dfb1ff51adda3cbbf3dfb7266c2 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 -P b8720d0416b8d4af7d131f1ddc3d280d196a9eda -R 348c03cfec043fa2accf5b24f56b9e07 +P bcc72d413e8db5fe8b32147ac22d406e2cd6bb60 +R 7a42d74c66db2417ce1792aea469c273 +T *branch * rtree-32bit-rounding +T *sym-rtree-32bit-rounding * +T -sym-trunk * U drh -Z 4dd2c323458ec95fb0cf85be25b240a2 +Z 73d8e377047fc0765362a5432157fce8 diff --git a/manifest.uuid b/manifest.uuid index a78e9235fb..bc9b568048 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -bcc72d413e8db5fe8b32147ac22d406e2cd6bb60 \ No newline at end of file +f4e8ff03eae70334632455a867859cfcc25682be \ No newline at end of file