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 2015/08/19 21:56:37 UTC

svn commit: r1696657 - in /lucene/dev/branches/lucene6699/lucene/spatial3d/src: java/org/apache/lucene/bkdtree3d/ java/org/apache/lucene/geo3d/ test/org/apache/lucene/bkdtree3d/ test/org/apache/lucene/geo3d/

Author: mikemccand
Date: Wed Aug 19 19:56:37 2015
New Revision: 1696657

URL: http://svn.apache.org/r1696657
Log:
LUCENE-6699: fix one bug, add fudge factors, add nocommits

Modified:
    lucene/dev/branches/lucene6699/lucene/spatial3d/src/java/org/apache/lucene/bkdtree3d/Geo3DDocValuesFormat.java
    lucene/dev/branches/lucene6699/lucene/spatial3d/src/java/org/apache/lucene/bkdtree3d/PointInGeo3DShapeQuery.java
    lucene/dev/branches/lucene6699/lucene/spatial3d/src/java/org/apache/lucene/geo3d/Plane.java
    lucene/dev/branches/lucene6699/lucene/spatial3d/src/test/org/apache/lucene/bkdtree3d/TestGeo3DPointField.java
    lucene/dev/branches/lucene6699/lucene/spatial3d/src/test/org/apache/lucene/geo3d/GeoBBoxTest.java
    lucene/dev/branches/lucene6699/lucene/spatial3d/src/test/org/apache/lucene/geo3d/GeoCircleTest.java

Modified: lucene/dev/branches/lucene6699/lucene/spatial3d/src/java/org/apache/lucene/bkdtree3d/Geo3DDocValuesFormat.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6699/lucene/spatial3d/src/java/org/apache/lucene/bkdtree3d/Geo3DDocValuesFormat.java?rev=1696657&r1=1696656&r2=1696657&view=diff
==============================================================================
--- lucene/dev/branches/lucene6699/lucene/spatial3d/src/java/org/apache/lucene/bkdtree3d/Geo3DDocValuesFormat.java (original)
+++ lucene/dev/branches/lucene6699/lucene/spatial3d/src/java/org/apache/lucene/bkdtree3d/Geo3DDocValuesFormat.java Wed Aug 19 19:56:37 2015
@@ -131,6 +131,7 @@ public class Geo3DDocValuesFormat extend
   }
 
   static double decodeValue(int x) {
+    // nocommit make this multiplication instead?
     return x / SCALE;
   }
 

Modified: lucene/dev/branches/lucene6699/lucene/spatial3d/src/java/org/apache/lucene/bkdtree3d/PointInGeo3DShapeQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6699/lucene/spatial3d/src/java/org/apache/lucene/bkdtree3d/PointInGeo3DShapeQuery.java?rev=1696657&r1=1696656&r2=1696657&view=diff
==============================================================================
--- lucene/dev/branches/lucene6699/lucene/spatial3d/src/java/org/apache/lucene/bkdtree3d/PointInGeo3DShapeQuery.java (original)
+++ lucene/dev/branches/lucene6699/lucene/spatial3d/src/java/org/apache/lucene/bkdtree3d/PointInGeo3DShapeQuery.java Wed Aug 19 19:56:37 2015
@@ -103,13 +103,14 @@ public class PointInGeo3DShapeQuery exte
                                                       bounds.getMaximumZ());
 
         assert xyzSolid.getRelationship(shape) == GeoArea.WITHIN || xyzSolid.getRelationship(shape) == GeoArea.OVERLAPS;
-        
-        DocIdSet result = tree.intersect(Geo3DDocValuesFormat.encodeValue(bounds.getMinimumX()),
-                                         Geo3DDocValuesFormat.encodeValue(bounds.getMaximumX()),
-                                         Geo3DDocValuesFormat.encodeValue(bounds.getMinimumY()),
-                                         Geo3DDocValuesFormat.encodeValue(bounds.getMaximumY()),
-                                         Geo3DDocValuesFormat.encodeValue(bounds.getMinimumZ()),
-                                         Geo3DDocValuesFormat.encodeValue(bounds.getMaximumZ()),
+
+        // nocommit explain why we need the +/- 2.0 fudge factor...
+        DocIdSet result = tree.intersect(Geo3DDocValuesFormat.encodeValue(bounds.getMinimumX() - 2.0 * Vector.MINIMUM_RESOLUTION),
+                                         Geo3DDocValuesFormat.encodeValue(bounds.getMaximumX() + 2.0 * Vector.MINIMUM_RESOLUTION),
+                                         Geo3DDocValuesFormat.encodeValue(bounds.getMinimumY() - 2.0 * Vector.MINIMUM_RESOLUTION),
+                                         Geo3DDocValuesFormat.encodeValue(bounds.getMaximumY() + 2.0 * Vector.MINIMUM_RESOLUTION),
+                                         Geo3DDocValuesFormat.encodeValue(bounds.getMinimumZ() - 2.0 * Vector.MINIMUM_RESOLUTION),
+                                         Geo3DDocValuesFormat.encodeValue(bounds.getMaximumZ() + 2.0 * Vector.MINIMUM_RESOLUTION),
                                          new BKD3DTreeReader.ValueFilter() {
                                            @Override
                                            public boolean accept(int docID) {

Modified: lucene/dev/branches/lucene6699/lucene/spatial3d/src/java/org/apache/lucene/geo3d/Plane.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6699/lucene/spatial3d/src/java/org/apache/lucene/geo3d/Plane.java?rev=1696657&r1=1696656&r2=1696657&view=diff
==============================================================================
--- lucene/dev/branches/lucene6699/lucene/spatial3d/src/java/org/apache/lucene/geo3d/Plane.java (original)
+++ lucene/dev/branches/lucene6699/lucene/spatial3d/src/java/org/apache/lucene/geo3d/Plane.java Wed Aug 19 19:56:37 2015
@@ -175,7 +175,7 @@ public class Plane extends Vector {
     if (Math.abs(x) < MINIMUM_RESOLUTION && Math.abs(z) < MINIMUM_RESOLUTION)
       return null;
     final double denom = 1.0 / Math.sqrt(x*x + z*z);
-    return new Plane(z * denom, 0.0, -z * denom, 0.0);
+    return new Plane(z * denom, 0.0, -x * denom, 0.0);
   }
 
   /** Construct a normalized plane through a y-z point and including the X axis.

Modified: lucene/dev/branches/lucene6699/lucene/spatial3d/src/test/org/apache/lucene/bkdtree3d/TestGeo3DPointField.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6699/lucene/spatial3d/src/test/org/apache/lucene/bkdtree3d/TestGeo3DPointField.java?rev=1696657&r1=1696656&r2=1696657&view=diff
==============================================================================
--- lucene/dev/branches/lucene6699/lucene/spatial3d/src/test/org/apache/lucene/bkdtree3d/TestGeo3DPointField.java (original)
+++ lucene/dev/branches/lucene6699/lucene/spatial3d/src/test/org/apache/lucene/bkdtree3d/TestGeo3DPointField.java Wed Aug 19 19:56:37 2015
@@ -65,12 +65,12 @@ import static org.apache.lucene.bkdtree3
 public class TestGeo3DPointField extends LuceneTestCase {
 
   private static boolean smallBBox;
-
+  
   @BeforeClass
   public static void beforeClass() {
     smallBBox = random().nextBoolean();
     if (VERBOSE) {
-      System.out.println("TEST: smallBBox=" + smallBBox);
+      System.err.println("TEST: smallBBox=" + smallBBox);
     }
   }
 
@@ -213,8 +213,8 @@ public class TestGeo3DPointField extends
       }
 
       if (VERBOSE) {
-        System.out.println("  docID=" + docID + " point=" + point);
-        System.out.println("    x=" + encodeValue(point.x) +
+        System.err.println("  docID=" + docID + " point=" + point);
+        System.err.println("    x=" + encodeValue(point.x) +
                            " y=" + encodeValue(point.y) +
                            " z=" + encodeValue(point.z));
       }
@@ -248,7 +248,7 @@ public class TestGeo3DPointField extends
       int zMaxEnc = encodeValue(z.max);
 
       if (VERBOSE) {
-        System.out.println("\nTEST: iter=" + iter + " bbox: x=" + x + " (" + xMinEnc + " TO " + xMaxEnc+ ")" + " y=" + y + " (" + yMinEnc + " TO " + yMaxEnc + ")"  + " z=" + z + " (" + zMinEnc + " TO " + zMaxEnc + ")" );
+        System.err.println("\nTEST: iter=" + iter + " bbox: x=" + x + " (" + xMinEnc + " TO " + xMaxEnc+ ")" + " y=" + y + " (" + yMinEnc + " TO " + yMaxEnc + ")"  + " z=" + z + " (" + zMinEnc + " TO " + zMaxEnc + ")" );
       }
 
       DocIdSet hits = r.intersect(xMinEnc, xMaxEnc,
@@ -314,7 +314,7 @@ public class TestGeo3DPointField extends
         matches.set(nextHit);
       }
       if (VERBOSE) {
-        System.out.println("  total hits: " + matches.cardinality());
+        System.err.println("  total hits: " + matches.cardinality());
       }
 
       for(int docID=0;docID<numPoints;docID++) {
@@ -360,7 +360,7 @@ public class TestGeo3DPointField extends
     int numPoints = atLeast(count);
 
     if (VERBOSE) {
-      System.out.println("TEST: numPoints=" + numPoints);
+      System.err.println("TEST: numPoints=" + numPoints);
     }
 
     double[] lats = new double[numPoints];
@@ -374,7 +374,7 @@ public class TestGeo3DPointField extends
         // Some docs don't have a point:
         lats[docID] = Double.NaN;
         if (VERBOSE) {
-          System.out.println("  doc=" + docID + " is missing");
+          System.err.println("  doc=" + docID + " is missing");
         }
         continue;
       }
@@ -393,14 +393,14 @@ public class TestGeo3DPointField extends
           lats[docID] = lats[oldDocID];
           lons[docID] = toRadians(randomLon());
           if (VERBOSE) {
-            System.out.println("  doc=" + docID + " lat=" + lats[docID] + " lon=" + lons[docID] + " (same lat as doc=" + oldDocID + ")");
+            System.err.println("  doc=" + docID + " lat=" + lats[docID] + " lon=" + lons[docID] + " (same lat as doc=" + oldDocID + ")");
           }
         } else if (x == 1) {
           // Identical lon to old point
           lats[docID] = toRadians(randomLat());
           lons[docID] = lons[oldDocID];
           if (VERBOSE) {
-            System.out.println("  doc=" + docID + " lat=" + lats[docID] + " lon=" + lons[docID] + " (same lon as doc=" + oldDocID + ")");
+            System.err.println("  doc=" + docID + " lat=" + lats[docID] + " lon=" + lons[docID] + " (same lon as doc=" + oldDocID + ")");
           }
         } else {
           assert x == 2;
@@ -408,7 +408,7 @@ public class TestGeo3DPointField extends
           lats[docID] = lats[oldDocID];
           lons[docID] = lons[oldDocID];
           if (VERBOSE) {
-            System.out.println("  doc=" + docID + " lat=" + lats[docID] + " lon=" + lons[docID] + " (same lat/lon as doc=" + oldDocID + ")");
+            System.err.println("  doc=" + docID + " lat=" + lats[docID] + " lon=" + lons[docID] + " (same lat/lon as doc=" + oldDocID + ")");
           }
         }
       } else {
@@ -416,7 +416,7 @@ public class TestGeo3DPointField extends
         lons[docID] = toRadians(randomLon());
         haveRealDoc = true;
         if (VERBOSE) {
-          System.out.println("  doc=" + docID + " lat=" + lats[docID] + " lon=" + lons[docID]);
+          System.err.println("  doc=" + docID + " lat=" + lats[docID] + " lon=" + lons[docID]);
         }
       }
     }
@@ -491,7 +491,7 @@ public class TestGeo3DPointField extends
         w.deleteDocuments(new Term("id", ""+idToDelete));
         deleted.add(idToDelete);
         if (VERBOSE) {
-          System.out.println("  delete id=" + idToDelete);
+          System.err.println("  delete id=" + idToDelete);
         }
       }
     }
@@ -545,12 +545,12 @@ public class TestGeo3DPointField extends
                   angle = random().nextDouble() * Math.PI/2.0;
                 }
 
+                shape = new GeoCircle(planetModel, lat, lon, angle);
+
                 if (VERBOSE) {
-                  System.out.println("\nTEST: iter=" + iter + " shape=GeoCircle lat=" + lat + " lon=" + lon + " angle=" + angle);
+                  System.err.println("\nTEST: iter=" + iter + " shape="+shape);
                 }
 
-                shape = new GeoCircle(planetModel, lat, lon, angle);
-
               } else {
                 double lat0 = toRadians(randomLat());
                 double lat1 = toRadians(randomLat());
@@ -567,17 +567,18 @@ public class TestGeo3DPointField extends
                   lon1 = x;
                 }
 
+                shape = GeoBBoxFactory.makeGeoBBox(planetModel, lat1, lat0, lon0, lon1);
+
                 if (VERBOSE) {
-                  System.out.println("\nTEST: iter=" + iter + " shape=GeoBBox lat0=" + lat0 + " lat1=" + lat1 + " lon0=" + lon0 + " lon1=" + lon1);
+                  System.err.println("\nTEST: iter=" + iter + " shape="+shape);
                 }
 
-                shape = GeoBBoxFactory.makeGeoBBox(planetModel, lat1, lat0, lon0, lon1);
               }
 
               Query query = new PointInGeo3DShapeQuery(planetModel, "point", shape);
 
               if (VERBOSE) {
-                System.out.println("  using query: " + query);
+                System.err.println("  using query: " + query);
               }
 
               final FixedBitSet hits = new FixedBitSet(r.maxDoc());
@@ -603,7 +604,7 @@ public class TestGeo3DPointField extends
                 });
 
               if (VERBOSE) {
-                System.out.println("  hitCount: " + hits.cardinality());
+                System.err.println("  hitCount: " + hits.cardinality());
               }
       
               for(int docID=0;docID<r.maxDoc();docID++) {

Modified: lucene/dev/branches/lucene6699/lucene/spatial3d/src/test/org/apache/lucene/geo3d/GeoBBoxTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6699/lucene/spatial3d/src/test/org/apache/lucene/geo3d/GeoBBoxTest.java?rev=1696657&r1=1696656&r2=1696657&view=diff
==============================================================================
--- lucene/dev/branches/lucene6699/lucene/spatial3d/src/test/org/apache/lucene/geo3d/GeoBBoxTest.java (original)
+++ lucene/dev/branches/lucene6699/lucene/spatial3d/src/test/org/apache/lucene/geo3d/GeoBBoxTest.java Wed Aug 19 19:56:37 2015
@@ -160,6 +160,16 @@ public class GeoBBoxTest {
     assertEquals(0.841471, xyzb.getMaximumY(), 0.000001);
     assertEquals(-0.707107, xyzb.getMinimumZ(), 0.000001);
     assertEquals(0.707107, xyzb.getMaximumZ(), 0.000001);
+    
+    // nocommit explain why we need the +/- 2.0 fudge factor...
+    GeoArea area = GeoAreaFactory.makeGeoArea(PlanetModel.SPHERE,
+      xyzb.getMinimumX() - 2.0 * Vector.MINIMUM_RESOLUTION,
+      xyzb.getMaximumX() + 2.0 * Vector.MINIMUM_RESOLUTION,
+      xyzb.getMinimumY() - 2.0 * Vector.MINIMUM_RESOLUTION,
+      xyzb.getMaximumY() + 2.0 * Vector.MINIMUM_RESOLUTION,
+      xyzb.getMinimumZ() - 2.0 * Vector.MINIMUM_RESOLUTION,
+      xyzb.getMaximumZ() + 2.0 * Vector.MINIMUM_RESOLUTION);
+    assertEquals(GeoArea.WITHIN, area.getRelationship(c));
 
     c = GeoBBoxFactory.makeGeoBBox(PlanetModel.SPHERE, 0.0, -Math.PI * 0.25, -1.0, 1.0);
     b = new LatLonBounds();

Modified: lucene/dev/branches/lucene6699/lucene/spatial3d/src/test/org/apache/lucene/geo3d/GeoCircleTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6699/lucene/spatial3d/src/test/org/apache/lucene/geo3d/GeoCircleTest.java?rev=1696657&r1=1696656&r2=1696657&view=diff
==============================================================================
--- lucene/dev/branches/lucene6699/lucene/spatial3d/src/test/org/apache/lucene/geo3d/GeoCircleTest.java (original)
+++ lucene/dev/branches/lucene6699/lucene/spatial3d/src/test/org/apache/lucene/geo3d/GeoCircleTest.java Wed Aug 19 19:56:37 2015
@@ -25,7 +25,6 @@ import static org.junit.Assert.assertTru
 
 public class GeoCircleTest {
 
-
   @Test
   public void testCircleDistance() {
     GeoCircle c;
@@ -95,8 +94,18 @@ public class GeoCircleTest {
   public void testCircleBounds() {
     GeoCircle c;
     LatLonBounds b;
-
-
+    XYZBounds xyzb;
+    
+    // Test case from BKD
+    c = new GeoCircle(PlanetModel.SPHERE, -0.765816119338, 0.991848766844, 0.8153163226330487);
+    GeoPoint p1 = new GeoPoint(0.7692262265236023, -0.055089298115534646, -0.6365973465711254);
+    assertTrue(c.isWithin(p1));
+    xyzb = new XYZBounds();
+    c.getBounds(xyzb);
+    assertTrue(p1.x >= xyzb.getMinimumX() && p1.x <= xyzb.getMaximumX());
+    assertTrue(p1.y >= xyzb.getMinimumY() && p1.y <= xyzb.getMaximumY());
+    assertTrue(p1.z >= xyzb.getMinimumZ() && p1.z <= xyzb.getMaximumZ());
+    
     // Vertical circle cases
     c = new GeoCircle(PlanetModel.SPHERE, 0.0, -0.5, 0.1);
     b = new LatLonBounds();