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/05/26 22:17:29 UTC

svn commit: r1681842 - in /lucene/dev/branches/LUCENE-6481/lucene/sandbox/src/java/org/apache/lucene: search/GeoPointInBBoxQuery.java search/GeoPointInPolygonQuery.java util/GeoUtils.java

Author: mikemccand
Date: Tue May 26 20:17:29 2015
New Revision: 1681842

URL: http://svn.apache.org/r1681842
Log:
LUCENE-6481: make explicit separate methods for the lat vs lon cases

Modified:
    lucene/dev/branches/LUCENE-6481/lucene/sandbox/src/java/org/apache/lucene/search/GeoPointInBBoxQuery.java
    lucene/dev/branches/LUCENE-6481/lucene/sandbox/src/java/org/apache/lucene/search/GeoPointInPolygonQuery.java
    lucene/dev/branches/LUCENE-6481/lucene/sandbox/src/java/org/apache/lucene/util/GeoUtils.java

Modified: lucene/dev/branches/LUCENE-6481/lucene/sandbox/src/java/org/apache/lucene/search/GeoPointInBBoxQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-6481/lucene/sandbox/src/java/org/apache/lucene/search/GeoPointInBBoxQuery.java?rev=1681842&r1=1681841&r2=1681842&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-6481/lucene/sandbox/src/java/org/apache/lucene/search/GeoPointInBBoxQuery.java (original)
+++ lucene/dev/branches/LUCENE-6481/lucene/sandbox/src/java/org/apache/lucene/search/GeoPointInBBoxQuery.java Tue May 26 20:17:29 2015
@@ -178,10 +178,10 @@ public class GeoPointInBBoxQuery extends
      * @param res spatial res represented as a bit shift (MSB is lower res)
      */
     private void relateAndRecurse(final long start, final long end, final short res) {
-      final double minLon = GeoUtils.mortonUnhash(start, true);
-      final double minLat = GeoUtils.mortonUnhash(start, false);
-      final double maxLon = GeoUtils.mortonUnhash(end, true);
-      final double maxLat = GeoUtils.mortonUnhash(end, false);
+      final double minLon = GeoUtils.mortonUnhashLon(start);
+      final double minLat = GeoUtils.mortonUnhashLat(start);
+      final double maxLon = GeoUtils.mortonUnhashLon(end);
+      final double maxLat = GeoUtils.mortonUnhashLat(end);
 
       final short level = (short)(62-res>>>1);
 
@@ -263,8 +263,8 @@ public class GeoPointInBBoxQuery extends
       // final-filter boundary ranges by bounding box
       if (currentRange.boundary) {
         final long val = NumericUtils.prefixCodedToLong(term);
-        final double lon = GeoUtils.mortonUnhash(val, true);
-        final double lat = GeoUtils.mortonUnhash(val, false);
+        final double lon = GeoUtils.mortonUnhashLon(val);
+        final double lat = GeoUtils.mortonUnhashLat(val);
         if (!GeoUtils.bboxContains(lon, lat, minLon, minLat, maxLon, maxLat)) {
           return AcceptStatus.NO;
         }

Modified: lucene/dev/branches/LUCENE-6481/lucene/sandbox/src/java/org/apache/lucene/search/GeoPointInPolygonQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-6481/lucene/sandbox/src/java/org/apache/lucene/search/GeoPointInPolygonQuery.java?rev=1681842&r1=1681841&r2=1681842&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-6481/lucene/sandbox/src/java/org/apache/lucene/search/GeoPointInPolygonQuery.java (original)
+++ lucene/dev/branches/LUCENE-6481/lucene/sandbox/src/java/org/apache/lucene/search/GeoPointInPolygonQuery.java Tue May 26 20:17:29 2015
@@ -190,8 +190,8 @@ public final class GeoPointInPolygonQuer
       }
 
       final long val = NumericUtils.prefixCodedToLong(term);
-      final double lon = GeoUtils.mortonUnhash(val, true);
-      final double lat = GeoUtils.mortonUnhash(val, false);
+      final double lon = GeoUtils.mortonUnhashLon(val);
+      final double lat = GeoUtils.mortonUnhashLat(val);
       // post-filter by point in polygon
       if (!GeoUtils.pointInPolygon(x, y, lat, lon)) {
         return AcceptStatus.NO;

Modified: lucene/dev/branches/LUCENE-6481/lucene/sandbox/src/java/org/apache/lucene/util/GeoUtils.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-6481/lucene/sandbox/src/java/org/apache/lucene/util/GeoUtils.java?rev=1681842&r1=1681841&r2=1681842&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-6481/lucene/sandbox/src/java/org/apache/lucene/util/GeoUtils.java (original)
+++ lucene/dev/branches/LUCENE-6481/lucene/sandbox/src/java/org/apache/lucene/util/GeoUtils.java Tue May 26 20:17:29 2015
@@ -44,19 +44,31 @@ public final class GeoUtils {
   }
 
   public static final Long mortonHash(final double lon, final double lat) {
-    return BitUtil.interleave(scale(lon, true), scale(lat, false));
+    return BitUtil.interleave(scaleLon(lon), scaleLat(lat));
   }
 
-  public static final double mortonUnhash(final long hash, final boolean isLon) {
-    return unscale(BitUtil.deinterleave((isLon) ? hash : hash >>> 1), isLon);
+  public static final double mortonUnhashLon(final long hash) {
+    return unscaleLon(BitUtil.deinterleave(hash));
   }
 
-  private static long scale(final double val, final boolean lon) {
-    return (long) ((lon == true) ? (val-MIN_LON) * LON_SCALE : (val-MIN_LAT) * LAT_SCALE);
+  public static final double mortonUnhashLat(final long hash) {
+    return unscaleLat(BitUtil.deinterleave(hash >>> 1));
   }
 
-  public static double unscale(final long val, final boolean lon) {
-    return (lon == true) ? (val / LON_SCALE) + MIN_LON : (val / LAT_SCALE) + MIN_LAT;
+  private static long scaleLon(final double val) {
+    return (long) ((val-MIN_LON) * LON_SCALE);
+  }
+
+  private static long scaleLat(final double val) {
+    return (long) ((val-MIN_LAT) * LAT_SCALE);
+  }
+
+  private static double unscaleLon(final long val) {
+    return (val / LON_SCALE) + MIN_LON;
+  }
+
+  private static double unscaleLat(final long val) {
+    return (val / LAT_SCALE) + MIN_LAT;
   }
 
   public static final double compare(final double v1, final double v2) {
@@ -249,4 +261,4 @@ public final class GeoUtils {
     return !(!pointInPolygon(shapeX, shapeY, rMinY, rMinX) || !pointInPolygon(shapeX, shapeY, rMinY, rMaxX) ||
         !pointInPolygon(shapeX, shapeY, rMaxY, rMaxX) || !pointInPolygon(shapeX, shapeY, rMaxY, rMinX));
   }
-}
\ No newline at end of file
+}