]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Preliminary tests show geopoly_overlap() is working.
authordrh <drh@noemail.net>
Sat, 12 May 2018 20:28:51 +0000 (20:28 +0000)
committerdrh <drh@noemail.net>
Sat, 12 May 2018 20:28:51 +0000 (20:28 +0000)
FossilOrigin-Name: 77bb7b7d7278725e4e02935d485c3540bb41f4fc29ca8da679b2a380ebc38d7d

ext/misc/geopoly.c
manifest
manifest.uuid

index 63e8be2694a79183dbc8e5702111312aa79d7151..daa9f449b0d25e460a1a72b4880620f17bebee5e 100644 (file)
@@ -21,6 +21,14 @@ SQLITE_EXTENSION_INIT1
 #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
@@ -639,6 +647,7 @@ static int geopolyOverlap(GeoPoly *p1, GeoPoly *p2){
   GeoEvent *pThisEvent;
   double rX;
   int rc = 0;
+  int needSort = 0;
   GeoSegment *pActive = 0;
   GeoSegment *pSeg;
   unsigned char aOverlap[4];
@@ -660,22 +669,36 @@ static int geopolyOverlap(GeoPoly *p1, GeoPoly *p2){
     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;
           }
         }
@@ -683,17 +706,18 @@ static int geopolyOverlap(GeoPoly *p1, GeoPoly *p2){
         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 ){
@@ -757,6 +781,18 @@ static void geopolyOverlapFunc(
   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)
@@ -777,6 +813,7 @@ int sqlite3_geopoly_init(
      { geopolyJsonFunc,          1,    "geopoly_json"     },
      { geopolyWithinFunc,        3,    "geopoly_within"   },
      { geopolyOverlapFunc,       2,    "geopoly_overlap"  },
+     { geopolyDebugFunc,         1,    "geopoly_debug"    },
   };
   int i;
   SQLITE_EXTENSION_INIT2(pApi);
index 3340f9e55b41980997af0736e01269033475265b..f923ef59d9ffa22477e083b67c033331a069de4d 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-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
@@ -279,7 +279,7 @@ F ext/misc/dbdump.c 69ef1be5b210538f77dfcc6fcb55b4b5f5e98b1e0bcfd67d818711e10761
 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
@@ -1729,7 +1729,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
 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
index e091f9a29b838150a1e672c2d4077078e03be221..ae3995d75339708e5fc436c300f830b4a110928e 100644 (file)
@@ -1 +1 @@
-c857976efba79bd24befec1bd1597cc967dd2f0a39e66087cc9b1663154a05a8
\ No newline at end of file
+77bb7b7d7278725e4e02935d485c3540bb41f4fc29ca8da679b2a380ebc38d7d
\ No newline at end of file