SQLite

Check-in [f4e8ff03ea]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment: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.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | rtree-32bit-rounding
Files: files | file ages | folders
SHA1: f4e8ff03eae70334632455a867859cfcc25682be
User & Date: drh 2012-05-28 19:19:25.608
Context
2012-05-28
20:16
Simplification to the coordinate rounding logic in RTree. (check-in: df24072de2 user: drh tags: rtree-32bit-rounding)
19:19
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. (check-in: f4e8ff03ea user: drh tags: rtree-32bit-rounding)
17:51
Updates regarding URI query parameters and shared cache in the documentation derived from comments in sqlite.h.in. No changes to code. (check-in: bcc72d413e user: drh tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to ext/rtree/rtree.c.
2734
2735
2736
2737
2738
2739
2740





































2741
2742
2743
2744
2745
2746
2747
    rc = nodeRelease(pRtree, pRoot);
  }else{
    nodeRelease(pRtree, pRoot);
  }

  return rc;
}






































/*
** The xUpdate method for rtree module virtual tables.
*/
static int rtreeUpdate(
  sqlite3_vtab *pVtab, 
  int nData, 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
    rc = nodeRelease(pRtree, pRoot);
  }else{
    nodeRelease(pRtree, pRoot);
  }

  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( f<d ){
    if( f<0.0 ){
      f -= f/8388608.0;
    }else{
      f += f/8388608.0;
    }
  }
  return f;
#endif
}

/*
** The xUpdate method for rtree module virtual tables.
*/
static int rtreeUpdate(
  sqlite3_vtab *pVtab, 
  int nData, 
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
    int ii;

    /* Populate the cell.aCoord[] array. The first coordinate is azData[3]. */
    assert( nData==(pRtree->nDim*2 + 3) );
#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]);
        if( cell.aCoord[ii].f>cell.aCoord[ii+1].f ){
          rc = SQLITE_CONSTRAINT;
          goto constraint;
        }
      }
    }else
#endif







|
|







2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
    int ii;

    /* Populate the cell.aCoord[] array. The first coordinate is azData[3]. */
    assert( nData==(pRtree->nDim*2 + 3) );
#ifndef SQLITE_RTREE_INT_ONLY
    if( pRtree->eCoordType==RTREE_COORD_REAL32 ){
      for(ii=0; ii<(pRtree->nDim*2); ii+=2){
        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;
        }
      }
    }else
#endif