You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by mi...@apache.org on 2016/04/12 12:08:36 UTC

lucene-solr:branch_6x: LUCENE-7189: improve geo debugging technology

Repository: lucene-solr
Updated Branches:
  refs/heads/branch_6x ace13b572 -> 39d74d86c


LUCENE-7189: improve geo debugging technology


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/39d74d86
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/39d74d86
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/39d74d86

Branch: refs/heads/branch_6x
Commit: 39d74d86cddfed5ec7f0dd9b4dcf0e102384d980
Parents: ace13b5
Author: Mike McCandless <mi...@apache.org>
Authored: Tue Apr 12 06:10:08 2016 -0400
Committer: Mike McCandless <mi...@apache.org>
Committed: Tue Apr 12 06:10:35 2016 -0400

----------------------------------------------------------------------
 .../org/apache/lucene/geo/EarthDebugger.java    | 43 +++++++----
 .../apache/lucene/index/PointsStackTracker.java | 79 ++++++++++++++++++++
 2 files changed, 108 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/39d74d86/lucene/test-framework/src/java/org/apache/lucene/geo/EarthDebugger.java
----------------------------------------------------------------------
diff --git a/lucene/test-framework/src/java/org/apache/lucene/geo/EarthDebugger.java b/lucene/test-framework/src/java/org/apache/lucene/geo/EarthDebugger.java
index 6c06c94..56dde88 100644
--- a/lucene/test-framework/src/java/org/apache/lucene/geo/EarthDebugger.java
+++ b/lucene/test-framework/src/java/org/apache/lucene/geo/EarthDebugger.java
@@ -17,8 +17,6 @@ package org.apache.lucene.geo;
  * limitations under the License.
  */
 
-import org.apache.lucene.geo.Polygon;
-import org.apache.lucene.geo.Rectangle;
 import org.apache.lucene.util.SloppyMath;
 
 /** Draws shapes on the earth surface and renders using the very cool http://www.webglearth.org.
@@ -40,6 +38,16 @@ public class EarthDebugger {
     b.append("        var earth = new WE.map('earth_div');\n");
   }
 
+  public EarthDebugger(double centerLat, double centerLon, double altitudeMeters) {
+    b.append("<!DOCTYPE HTML>\n");
+    b.append("<html>\n");
+    b.append("  <head>\n");
+    b.append("    <script src=\"http://www.webglearth.com/v2/api.js\"></script>\n");
+    b.append("    <script>\n");
+    b.append("      function initialize() {\n");
+    b.append("        var earth = new WE.map('earth_div', {center: [" + centerLat + ", " + centerLon + "], altitude: " + altitudeMeters + "});\n");
+  }
+
   public void addPolygon(Polygon poly) {
     addPolygon(poly, "#00ff00");
   }
@@ -54,29 +62,36 @@ public class EarthDebugger {
     for(int i=0;i<polyLats.length;i++) {
       b.append("          [" + polyLats[i] + ", " + polyLons[i] + "],\n");
     }
-    b.append("        ], {color: '" + color + "'});\n");
+    b.append("        ], {color: '" + color + "', fillColor: \"#000000\", fillOpacity: 0.0001});\n");
     b.append("        " + name + ".addTo(earth);\n");
 
     for (Polygon hole : poly.getHoles()) {
-      addPolygon(poly, "#ffffff");
+      addPolygon(hole, "#ffffff");
     }
   }
 
-  private static double MAX_LAT_LON_PER_STEP = 5.0;
+  private static double MAX_KM_PER_STEP = 100.0;
+
+  // Web GL earth connects dots by tunneling under the earth, so we approximate a great circle by sampling it, to minimize how deep in the
+  // earth each segment tunnels:
+  private int getStepCount(double minLat, double maxLat, double minLon, double maxLon) {
+    double distanceMeters = SloppyMath.haversinMeters(minLat, minLon, maxLat, maxLon);
+    return Math.max(1, (int) Math.round((distanceMeters / 1000.0) / MAX_KM_PER_STEP));
+  }
 
   // first point is inclusive, last point is exclusive!
   private void drawSegment(double minLat, double maxLat, double minLon, double maxLon) {
-    int steps = (int) Math.round(Math.max(Math.abs(maxLat-minLat)/MAX_LAT_LON_PER_STEP, Math.abs(maxLon-minLon)/MAX_LAT_LON_PER_STEP));
-    if (steps < 1) {
-      steps = 1;
-    }
+    int steps = getStepCount(minLat, maxLat, minLon, maxLon);
     for(int i=0;i<steps;i++) {
       b.append("          [" + (minLat + (maxLat - minLat) * i / steps) + ", " + (minLon + (maxLon - minLon) * i / steps) + "],\n");
     }
   }
 
   public void addRect(double minLat, double maxLat, double minLon, double maxLon) {
-    int steps = 20;
+    addRect(minLat, maxLat, minLon, maxLon, "#ff0000");
+  }
+
+  public void addRect(double minLat, double maxLat, double minLon, double maxLon, String color) {
     String name = "rect" + nextShape;
     nextShape++;
 
@@ -97,7 +112,7 @@ public class EarthDebugger {
 
     b.append("          // min lat, min lon\n");
     b.append("          [" + minLat + ", " + minLon + "]\n");
-    b.append("        ], {color: \"#ff0000\", fillColor: \"#ff0000\"});\n");
+    b.append("        ], {color: \"" + color + "\", fillColor: \"" + color + "\"});\n");
     b.append("        " + name + ".addTo(earth);\n");
   }
 
@@ -108,7 +123,7 @@ public class EarthDebugger {
 
     b.append("        var " + name + " = WE.polygon([\n");
     double lon;
-    int steps = 36;
+    int steps = getStepCount(lat, minLon, lat, maxLon);
     for(lon = minLon;lon<=maxLon;lon += (maxLon-minLon)/steps) {
       b.append("          [" + lat + ", " + lon + "],\n");
     }
@@ -128,7 +143,7 @@ public class EarthDebugger {
 
     b.append("        var " + name + " = WE.polygon([\n");
     double lat;
-    int steps = 36;
+    int steps = getStepCount(minLat, lon, maxLat, lon);
     for(lat = minLat;lat<=maxLat;lat += (maxLat-minLat)/steps) {
       b.append("          [" + lat + ", " + lon + "],\n");
     }
@@ -151,7 +166,7 @@ public class EarthDebugger {
     nextShape++;
     b.append("        var " + name + " = WE.polygon([\n");
     inverseHaversin(b, centerLat, centerLon, radiusMeters);
-    b.append("        ], {color: '#00ff00'});\n");
+    b.append("        ], {color: '#00ff00', fillColor: \"#000000\", fillOpacity: 0.0001 });\n");
     b.append("        " + name + ".addTo(earth);\n");
 
     if (alsoAddBBox) {

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/39d74d86/lucene/test-framework/src/java/org/apache/lucene/index/PointsStackTracker.java
----------------------------------------------------------------------
diff --git a/lucene/test-framework/src/java/org/apache/lucene/index/PointsStackTracker.java b/lucene/test-framework/src/java/org/apache/lucene/index/PointsStackTracker.java
new file mode 100644
index 0000000..b439ec4
--- /dev/null
+++ b/lucene/test-framework/src/java/org/apache/lucene/index/PointsStackTracker.java
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.lucene.index;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.lucene.index.PointValues.IntersectVisitor;
+import org.apache.lucene.util.StringHelper;
+
+/** Simple utility class to track the current BKD stack based solely on calls to {@link IntersectVisitor#compare}. */
+public class PointsStackTracker {
+
+  private final int numDims;
+  private final int bytesPerDim;
+
+  public final List<Cell> stack = new ArrayList<>();
+
+  public class Cell {
+    public final byte[] minPackedValue;
+    public final byte[] maxPackedValue;
+
+    public Cell(byte[] minPackedValue, byte[] maxPackedValue) {
+      this.minPackedValue = minPackedValue.clone();
+      this.maxPackedValue = maxPackedValue.clone();
+    }
+
+    public boolean contains(Cell other) {
+      for(int dim=0;dim<numDims;dim++) {
+        int offset = dim * bytesPerDim;
+        // other.min < min?
+        if (StringHelper.compare(bytesPerDim, other.minPackedValue, offset, minPackedValue, offset) < 0) {
+          return false;
+        }
+        // other.max > max?
+        if (StringHelper.compare(bytesPerDim, other.maxPackedValue, offset, maxPackedValue, offset) > 0) {
+          return false;
+        }
+      }
+
+      return true;
+    }
+  }
+
+  public PointsStackTracker(int numDims, int bytesPerDim) {
+    this.numDims = numDims;
+    this.bytesPerDim = bytesPerDim;
+  }
+    
+  public void onCompare(byte[] minPackedValue, byte[] maxPackedValue) {
+    Cell cell = new Cell(minPackedValue, maxPackedValue);
+
+    // Pop stack:
+    while (stack.size() > 0 && stack.get(stack.size()-1).contains(cell) == false) {
+      stack.remove(stack.size()-1);
+      //System.out.println("  pop");
+    }
+
+    // Push stack:
+    stack.add(cell);
+  }
+
+  // TODO: expose other details about the stack...
+}