1c223b8f1Sdan /* 2c223b8f1Sdan ** 2010 August 30 3c223b8f1Sdan ** 4c223b8f1Sdan ** The author disclaims copyright to this source code. In place of 5c223b8f1Sdan ** a legal notice, here is a blessing: 6c223b8f1Sdan ** 7c223b8f1Sdan ** May you do good and not evil. 8c223b8f1Sdan ** May you find forgiveness for yourself and forgive others. 9c223b8f1Sdan ** May you share freely, never taking more than you give. 10c223b8f1Sdan ** 11c223b8f1Sdan ************************************************************************* 12c223b8f1Sdan */ 13c223b8f1Sdan 14c223b8f1Sdan #ifndef _SQLITE3RTREE_H_ 15c223b8f1Sdan #define _SQLITE3RTREE_H_ 163b5a7a37Sdan 173b5a7a37Sdan #include <sqlite3.h> 183b5a7a37Sdan 19c223b8f1Sdan #ifdef __cplusplus 20c223b8f1Sdan extern "C" { 21c223b8f1Sdan #endif 223b5a7a37Sdan 23c223b8f1Sdan typedef struct sqlite3_rtree_geometry sqlite3_rtree_geometry; 2465e6b0ddSdrh typedef struct sqlite3_rtree_query_info sqlite3_rtree_query_info; 2565e6b0ddSdrh 2665e6b0ddSdrh /* The double-precision datatype used by RTree depends on the 2765e6b0ddSdrh ** SQLITE_RTREE_INT_ONLY compile-time option. 2865e6b0ddSdrh */ 2965e6b0ddSdrh #ifdef SQLITE_RTREE_INT_ONLY 3065e6b0ddSdrh typedef sqlite3_int64 sqlite3_rtree_dbl; 3165e6b0ddSdrh #else 3265e6b0ddSdrh typedef double sqlite3_rtree_dbl; 3365e6b0ddSdrh #endif 34c223b8f1Sdan 35c223b8f1Sdan /* 36c223b8f1Sdan ** Register a geometry callback named zGeom that can be used as part of an 37c223b8f1Sdan ** R-Tree geometry query as follows: 38c223b8f1Sdan ** 39c223b8f1Sdan ** SELECT ... FROM <rtree> WHERE <rtree col> MATCH $zGeom(... params ...) 40c223b8f1Sdan */ 41c223b8f1Sdan int sqlite3_rtree_geometry_callback( 42c223b8f1Sdan sqlite3 *db, 43c223b8f1Sdan const char *zGeom, 4465e6b0ddSdrh int (*xGeom)(sqlite3_rtree_geometry*, int, sqlite3_rtree_dbl*,int*), 45c223b8f1Sdan void *pContext 46c223b8f1Sdan ); 47c223b8f1Sdan 48c223b8f1Sdan 49c223b8f1Sdan /* 50c223b8f1Sdan ** A pointer to a structure of the following type is passed as the first 51c223b8f1Sdan ** argument to callbacks registered using rtree_geometry_callback(). 52c223b8f1Sdan */ 53c223b8f1Sdan struct sqlite3_rtree_geometry { 543b5a7a37Sdan void *pContext; /* Copy of pContext passed to s_r_g_c() */ 553b5a7a37Sdan int nParam; /* Size of array aParam[] */ 5665e6b0ddSdrh sqlite3_rtree_dbl *aParam; /* Parameters passed to SQL geom function */ 573b5a7a37Sdan void *pUser; /* Callback implementation user data */ 583b5a7a37Sdan void (*xDelUser)(void *); /* Called by SQLite to clean up pUser */ 593b5a7a37Sdan }; 603b5a7a37Sdan 6165e6b0ddSdrh /* 6265e6b0ddSdrh ** Register a 2nd-generation geometry callback named zScore that can be 6365e6b0ddSdrh ** used as part of an R-Tree geometry query as follows: 6465e6b0ddSdrh ** 6565e6b0ddSdrh ** SELECT ... FROM <rtree> WHERE <rtree col> MATCH $zQueryFunc(... params ...) 6665e6b0ddSdrh */ 6765e6b0ddSdrh int sqlite3_rtree_query_callback( 6865e6b0ddSdrh sqlite3 *db, 6965e6b0ddSdrh const char *zQueryFunc, 7065e6b0ddSdrh int (*xQueryFunc)(sqlite3_rtree_query_info*), 7165e6b0ddSdrh void *pContext, 7265e6b0ddSdrh void (*xDestructor)(void*) 7365e6b0ddSdrh ); 7465e6b0ddSdrh 7565e6b0ddSdrh 7665e6b0ddSdrh /* 7765e6b0ddSdrh ** A pointer to a structure of the following type is passed as the 7865e6b0ddSdrh ** argument to scored geometry callback registered using 7965e6b0ddSdrh ** sqlite3_rtree_query_callback(). 8065e6b0ddSdrh ** 8165e6b0ddSdrh ** Note that the first 5 fields of this structure are identical to 8265e6b0ddSdrh ** sqlite3_rtree_geometry. This structure is a subclass of 8365e6b0ddSdrh ** sqlite3_rtree_geometry. 8465e6b0ddSdrh */ 8565e6b0ddSdrh struct sqlite3_rtree_query_info { 8665e6b0ddSdrh void *pContext; /* pContext from when function registered */ 8765e6b0ddSdrh int nParam; /* Number of function parameters */ 8865e6b0ddSdrh sqlite3_rtree_dbl *aParam; /* value of function parameters */ 8965e6b0ddSdrh void *pUser; /* callback can use this, if desired */ 9065e6b0ddSdrh void (*xDelUser)(void*); /* function to free pUser */ 9165e6b0ddSdrh sqlite3_rtree_dbl *aCoord; /* Coordinates of node or entry to check */ 9265e6b0ddSdrh unsigned int *anQueue; /* Number of pending entries in the queue */ 9365e6b0ddSdrh int nCoord; /* Number of coordinates */ 9465e6b0ddSdrh int iLevel; /* Level of current node or entry */ 9565e6b0ddSdrh int mxLevel; /* The largest iLevel value in the tree */ 9665e6b0ddSdrh sqlite3_int64 iRowid; /* Rowid for current entry */ 9765e6b0ddSdrh sqlite3_rtree_dbl rParentScore; /* Score of parent node */ 9865e6b0ddSdrh int eParentWithin; /* Visibility of parent node */ 99*1ba88c7fSdrh int eWithin; /* OUT: Visibility */ 10065e6b0ddSdrh sqlite3_rtree_dbl rScore; /* OUT: Write the score here */ 1014f03f413Sdrh /* The following fields are only available in 3.8.11 and later */ 1024f03f413Sdrh sqlite3_value **apSqlParam; /* Original SQL values of parameters */ 10365e6b0ddSdrh }; 10465e6b0ddSdrh 10565e6b0ddSdrh /* 10665e6b0ddSdrh ** Allowed values for sqlite3_rtree_query.eWithin and .eParentWithin. 10765e6b0ddSdrh */ 10865e6b0ddSdrh #define NOT_WITHIN 0 /* Object completely outside of query region */ 10965e6b0ddSdrh #define PARTLY_WITHIN 1 /* Object partially overlaps query region */ 11065e6b0ddSdrh #define FULLY_WITHIN 2 /* Object fully contained within query region */ 11165e6b0ddSdrh 1123b5a7a37Sdan 113c223b8f1Sdan #ifdef __cplusplus 114c223b8f1Sdan } /* end of the 'extern "C"' block */ 115c223b8f1Sdan #endif 116c223b8f1Sdan 117c223b8f1Sdan #endif /* ifndef _SQLITE3RTREE_H_ */ 118