#include <stdio.h>
#define SQLITE_HAVE_GEOPLOY 1
+/* Enable -DGEOPOLY_ENABLE_DEBUG for debugging facilities */
+#ifdef GEOPOLY_ENABLE_DEBUG
+ static int geo_debug = 0;
+# define GEODEBUG(X) if(geo_debug)printf X
+#else
+# define GEODEBUG(X)
+#endif
+
#ifndef JSON_NULL /* The following stuff repeats things found in json1 */
/*
** Versions of isspace(), isalnum() and isdigit() to which it is safe
GeoEvent *pThisEvent;
double rX;
int rc = 0;
+ int needSort = 0;
GeoSegment *pActive = 0;
GeoSegment *pSeg;
unsigned char aOverlap[4];
if( pThisEvent->x!=rX ){
GeoSegment *pPrev = 0;
int iMask = 0;
- printf("Distinct X: %g\n", pThisEvent->x);
+ GEODEBUG(("Distinct X: %g\n", pThisEvent->x));
rX = pThisEvent->x;
- pActive = geopolySortSegmentsByYAndC(pActive);
+ if( needSort ){
+ pActive = geopolySortSegmentsByYAndC(pActive);
+ needSort = 0;
+ }
+ for(pSeg=pActive; pSeg; pSeg=pSeg->pNext){
+ if( pPrev ){
+ if( pPrev->y!=pSeg->y ){
+ GEODEBUG(("MASK: %d\n", iMask));
+ aOverlap[iMask] = 1;
+ }
+ }
+ iMask ^= pSeg->side;
+ pPrev = pSeg;
+ }
+ pPrev = 0;
for(pSeg=pActive; pSeg; pSeg=pSeg->pNext){
double y = pSeg->C*rX + pSeg->B;
- printf("Segment %d.%d %g->%g\n", pSeg->side, pSeg->idx, pSeg->y, y);
+ GEODEBUG(("Segment %d.%d %g->%g\n", pSeg->side, pSeg->idx, pSeg->y, y));
pSeg->y = y;
if( pPrev ){
if( pPrev->y>pSeg->y ){
rc = 1;
- printf("Crossing: %d.%d and %d.%d\n",
+ GEODEBUG(("Crossing: %d.%d and %d.%d\n",
pPrev->side, pPrev->idx,
- pSeg->side, pSeg->idx);
+ pSeg->side, pSeg->idx));
goto geopolyOverlapDone;
}else if( pPrev->y!=pSeg->y ){
- printf("MASK: %d\n", iMask);
+ GEODEBUG(("MASK: %d\n", iMask));
aOverlap[iMask] = 1;
}
}
pPrev = pSeg;
}
}
- printf("%s %d.%d C=%g B=%g\n",
+ GEODEBUG(("%s %d.%d C=%g B=%g\n",
pThisEvent->eType ? "RM " : "ADD",
pThisEvent->pSeg->side, pThisEvent->pSeg->idx,
pThisEvent->pSeg->C,
- pThisEvent->pSeg->B);
+ pThisEvent->pSeg->B));
if( pThisEvent->eType==0 ){
/* Add a segment */
pSeg = pThisEvent->pSeg;
pSeg->y = pSeg->C*rX + pSeg->B;
pSeg->pNext = pActive;
pActive = pSeg;
+ needSort = 1;
}else{
/* Remove a segment */
if( pActive==pThisEvent->pSeg ){
sqlite3_free(p2);
}
+/*
+** Enable or disable debugging output
+*/
+static void geopolyDebugFunc(
+ sqlite3_context *context,
+ int argc,
+ sqlite3_value **argv
+){
+#ifdef GEOPOLY_ENABLE_DEBUG
+ geo_debug = sqlite3_value_int(argv[0]);
+#endif
+}
#ifdef _WIN32
__declspec(dllexport)
{ geopolyJsonFunc, 1, "geopoly_json" },
{ geopolyWithinFunc, 3, "geopoly_within" },
{ geopolyOverlapFunc, 2, "geopoly_overlap" },
+ { geopolyDebugFunc, 1, "geopoly_debug" },
};
int i;
SQLITE_EXTENSION_INIT2(pApi);
-C An\sinitial\sattempt\sat\san\soverlap\sfunction\sin\sthe\sgeopoly\sextension.
-D 2018-05-12T16:05:45.598
+C Preliminary\stests\sshow\sgeopoly_overlap()\sis\sworking.
+D 2018-05-12T20:28:51.628
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F Makefile.in bfc40f350586923e0419d2ea4b559c37ec10ee4b6e210e08c14401f8e340f0da
F ext/misc/eval.c 6ea9b22a5fa0dd973b67ca4e53555be177bc0b7b263aadf1024429457c82c0e3
F ext/misc/fileio.c 48c7751c78fc4cdd29d8c862fd2f3f98bbfefa2a3cf1ca1496df4bf02eb8cded
F ext/misc/fuzzer.c 7c64b8197bb77b7d64eff7cac7848870235d4c25
-F ext/misc/geopoly.c 365c99cee9da15bf06d309c869cf21f8320ae2b098458cda4c91d345c961f097
+F ext/misc/geopoly.c 2d3478b322fde9d31d7d02bfe4e3c0cbc43f901991936a7511ecefd0f1770a9b
F ext/misc/ieee754.c f190d0cc5182529acb15babd177781be1ac1718c
F ext/misc/json1.c dbe086615b9546c156bf32b9378fc09383b58bd17513b866cfd24c1e15281984
F ext/misc/memvfs.c ab36f49e02ebcdf85a1e08dc4d8599ea8f343e073ac9e0bca18a98b7e1ec9567
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
-P 927d52a93c82ae408cb1651fd1326772f0be7442b6673e89f20567e633d39af3
-R 455de886ac3d9b55e6292f56ccf91da8
+P c857976efba79bd24befec1bd1597cc967dd2f0a39e66087cc9b1663154a05a8
+R f0e2b517cfea19580d6d720b8d793968
U drh
-Z af4dfbd4d6db4e39fb2f54b97c67d6e1
+Z a98a635ee795f5a445da6c92e9105b9c