Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(66)

Side by Side Diff: third_party/sqlite/sqlite-src-3100200/src/test_rtree.c

Issue 1610543003: [sql] Import reference version of SQLite 3.10.2. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 ** 2010 August 28 2 ** 2010 August 28
3 ** 3 **
4 ** The author disclaims copyright to this source code. In place of 4 ** The author disclaims copyright to this source code. In place of
5 ** a legal notice, here is a blessing: 5 ** a legal notice, here is a blessing:
6 ** 6 **
7 ** May you do good and not evil. 7 ** May you do good and not evil.
8 ** May you find forgiveness for yourself and forgive others. 8 ** May you find forgiveness for yourself and forgive others.
9 ** May you share freely, never taking more than you give. 9 ** May you share freely, never taking more than you give.
10 ** 10 **
11 ************************************************************************* 11 *************************************************************************
12 ** Code for testing all sorts of SQLite interfaces. This code 12 ** Code for testing all sorts of SQLite interfaces. This code
13 ** is not included in the SQLite library. 13 ** is not included in the SQLite library.
14 */ 14 */
15 15
16 #include <sqlite3.h> 16 #include "sqlite3.h"
17 #include <tcl.h> 17 #include <tcl.h>
18 18
19 /* Solely for the UNUSED_PARAMETER() macro. */ 19 /* Solely for the UNUSED_PARAMETER() macro. */
20 #include "sqliteInt.h" 20 #include "sqliteInt.h"
21 21
22 #ifdef SQLITE_ENABLE_RTREE 22 #ifdef SQLITE_ENABLE_RTREE
23 /* 23 /*
24 ** Type used to cache parameter information for the "circle" r-tree geometry 24 ** Type used to cache parameter information for the "circle" r-tree geometry
25 ** callback. 25 ** callback.
26 */ 26 */
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 148
149 /* The specified bounding box does not intersect the circular region. Set 149 /* The specified bounding box does not intersect the circular region. Set
150 ** the output variable to zero and return SQLITE_OK. */ 150 ** the output variable to zero and return SQLITE_OK. */
151 *pRes = 0; 151 *pRes = 0;
152 return SQLITE_OK; 152 return SQLITE_OK;
153 } 153 }
154 154
155 /* 155 /*
156 ** Implementation of "circle" r-tree geometry callback using the 156 ** Implementation of "circle" r-tree geometry callback using the
157 ** 2nd-generation interface that allows scoring. 157 ** 2nd-generation interface that allows scoring.
158 **
159 ** Two calling forms:
160 **
161 ** Qcircle(X,Y,Radius,eType) -- All values are doubles
162 ** Qcircle('x:X y:Y r:R e:ETYPE') -- Single string parameter
158 */ 163 */
159 static int circle_query_func(sqlite3_rtree_query_info *p){ 164 static int circle_query_func(sqlite3_rtree_query_info *p){
160 int i; /* Iterator variable */ 165 int i; /* Iterator variable */
161 Circle *pCircle; /* Structure defining circular region */ 166 Circle *pCircle; /* Structure defining circular region */
162 double xmin, xmax; /* X dimensions of box being tested */ 167 double xmin, xmax; /* X dimensions of box being tested */
163 double ymin, ymax; /* X dimensions of box being tested */ 168 double ymin, ymax; /* X dimensions of box being tested */
164 int nWithin = 0; /* Number of corners inside the circle */ 169 int nWithin = 0; /* Number of corners inside the circle */
165 170
166 xmin = p->aCoord[0]; 171 xmin = p->aCoord[0];
167 xmax = p->aCoord[1]; 172 xmax = p->aCoord[1];
168 ymin = p->aCoord[2]; 173 ymin = p->aCoord[2];
169 ymax = p->aCoord[3]; 174 ymax = p->aCoord[3];
170 pCircle = (Circle *)p->pUser; 175 pCircle = (Circle *)p->pUser;
171 if( pCircle==0 ){ 176 if( pCircle==0 ){
172 /* If pUser is still 0, then the parameter values have not been tested 177 /* If pUser is still 0, then the parameter values have not been tested
173 ** for correctness or stored into a Circle structure yet. Do this now. */ 178 ** for correctness or stored into a Circle structure yet. Do this now. */
174 179
175 /* This geometry callback is for use with a 2-dimensional r-tree table. 180 /* This geometry callback is for use with a 2-dimensional r-tree table.
176 ** Return an error if the table does not have exactly 2 dimensions. */ 181 ** Return an error if the table does not have exactly 2 dimensions. */
177 if( p->nCoord!=4 ) return SQLITE_ERROR; 182 if( p->nCoord!=4 ) return SQLITE_ERROR;
178 183
179 /* Test that the correct number of parameters (4) have been supplied, 184 /* Test that the correct number of parameters (1 or 4) have been supplied.
180 ** and that the parameters are in range (that the radius of the circle 185 */
181 ** radius is greater than zero). */ 186 if( p->nParam!=4 && p->nParam!=1 ) return SQLITE_ERROR;
182 if( p->nParam!=4 || p->aParam[2]<0.0 ) return SQLITE_ERROR;
183 187
184 /* Allocate a structure to cache parameter data in. Return SQLITE_NOMEM 188 /* Allocate a structure to cache parameter data in. Return SQLITE_NOMEM
185 ** if the allocation fails. */ 189 ** if the allocation fails. */
186 pCircle = (Circle *)(p->pUser = sqlite3_malloc(sizeof(Circle))); 190 pCircle = (Circle *)(p->pUser = sqlite3_malloc(sizeof(Circle)));
187 if( !pCircle ) return SQLITE_NOMEM; 191 if( !pCircle ) return SQLITE_NOMEM;
188 p->xDelUser = circle_del; 192 p->xDelUser = circle_del;
189 193
190 /* Record the center and radius of the circular region. One way that 194 /* Record the center and radius of the circular region. One way that
191 ** tested bounding boxes that intersect the circular region are detected 195 ** tested bounding boxes that intersect the circular region are detected
192 ** is by testing if each corner of the bounding box lies within radius 196 ** is by testing if each corner of the bounding box lies within radius
193 ** units of the center of the circle. */ 197 ** units of the center of the circle. */
194 pCircle->centerx = p->aParam[0]; 198 if( p->nParam==4 ){
195 pCircle->centery = p->aParam[1]; 199 pCircle->centerx = p->aParam[0];
196 pCircle->radius = p->aParam[2]; 200 pCircle->centery = p->aParam[1];
197 pCircle->eScoreType = (int)p->aParam[3]; 201 pCircle->radius = p->aParam[2];
202 pCircle->eScoreType = (int)p->aParam[3];
203 }else{
204 const char *z = (const char*)sqlite3_value_text(p->apSqlParam[0]);
205 pCircle->centerx = 0.0;
206 pCircle->centery = 0.0;
207 pCircle->radius = 0.0;
208 pCircle->eScoreType = 0;
209 while( z && z[0] ){
210 if( z[0]=='r' && z[1]==':' ){
211 pCircle->radius = atof(&z[2]);
212 }else if( z[0]=='x' && z[1]==':' ){
213 pCircle->centerx = atof(&z[2]);
214 }else if( z[0]=='y' && z[1]==':' ){
215 pCircle->centery = atof(&z[2]);
216 }else if( z[0]=='e' && z[1]==':' ){
217 pCircle->eScoreType = (int)atof(&z[2]);
218 }else if( z[0]==' ' ){
219 z++;
220 continue;
221 }
222 while( z[0]!=0 && z[0]!=' ' ) z++;
223 while( z[0]==' ' ) z++;
224 }
225 }
226 if( pCircle->radius<0.0 ){
227 sqlite3_free(pCircle);
228 return SQLITE_NOMEM;
229 }
198 230
199 /* Define two bounding box regions. The first, aBox[0], extends to 231 /* Define two bounding box regions. The first, aBox[0], extends to
200 ** infinity in the X dimension. It covers the same range of the Y dimension 232 ** infinity in the X dimension. It covers the same range of the Y dimension
201 ** as the circular region. The second, aBox[1], extends to infinity in 233 ** as the circular region. The second, aBox[1], extends to infinity in
202 ** the Y dimension and is constrained to the range of the circle in the 234 ** the Y dimension and is constrained to the range of the circle in the
203 ** X dimension. 235 ** X dimension.
204 ** 236 **
205 ** Then imagine each box is split in half along its short axis by a line 237 ** Then imagine each box is split in half along its short axis by a line
206 ** that intersects the center of the circular region. A bounding box 238 ** that intersects the center of the circular region. A bounding box
207 ** being tested can be said to intersect the circular region if it contains 239 ** being tested can be said to intersect the circular region if it contains
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 Tcl_SetResult(interp, (char *)sqlite3ErrName(rc), TCL_STATIC); 494 Tcl_SetResult(interp, (char *)sqlite3ErrName(rc), TCL_STATIC);
463 #endif 495 #endif
464 return TCL_OK; 496 return TCL_OK;
465 } 497 }
466 498
467 int Sqlitetestrtree_Init(Tcl_Interp *interp){ 499 int Sqlitetestrtree_Init(Tcl_Interp *interp){
468 Tcl_CreateObjCommand(interp, "register_cube_geom", register_cube_geom, 0, 0); 500 Tcl_CreateObjCommand(interp, "register_cube_geom", register_cube_geom, 0, 0);
469 Tcl_CreateObjCommand(interp, "register_circle_geom",register_circle_geom,0,0); 501 Tcl_CreateObjCommand(interp, "register_circle_geom",register_circle_geom,0,0);
470 return TCL_OK; 502 return TCL_OK;
471 } 503 }
OLDNEW
« no previous file with comments | « third_party/sqlite/sqlite-src-3100200/src/test_quota.c ('k') | third_party/sqlite/sqlite-src-3100200/src/test_schema.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698