Apache Solr open-source search software
minor trimming from spatial module's GeoEncodingUtils
nknized896eab989e1
diff --git a/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/search/GeoPointDistanceQuery.java b/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/search/GeoPointDistanceQuery.javaindex 9e90a11af8c..a6cf35cd557 100644--- a/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/search/GeoPointDistanceQuery.java+++ b/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/search/GeoPointDistanceQuery.java@@ -31,9 +31,8 @@ import org.apache.lucene.geo.GeoUtils;* circle. Terms* passing this initial filter are then passed to a secondary {@code postFilter} method that verifies whether the* decoded lat/lon point fall within the specified query distance (see {@link org.apache.lucene.util.SloppyMath#haversinMeters(double, double, double, double)}.- * All morton value comparisons are subject to the same precision tolerance defined in- * {@value org.apache.lucene.spatial.util.GeoEncodingUtils#TOLERANCE} and distance comparisons are subject to the accuracy of the- * haversine formula (from R.W. Sinnott, "Virtues of the Haversine", Sky and Telescope, vol. 68, no. 2, 1984, p. 159)+ * Distance comparisons are subject to the accuracy of the haversine formula+ * (from R.W. Sinnott, "Virtues of the Haversine", Sky and Telescope, vol. 68, no. 2, 1984, p. 159)** <p>Note: This query currently uses haversine which is a sloppy distance calculation (see above reference). For large* queries one can expect upwards of 400m error. Vincenty shrinks this to ~40m error but pays a penalty for computingdiff --git a/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/search/GeoPointInBBoxQuery.java b/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/search/GeoPointInBBoxQuery.javaindex f30950e3125..1634d45d39b 100644--- a/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/search/GeoPointInBBoxQuery.java+++ b/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/search/GeoPointInBBoxQuery.java@@ -31,8 +31,6 @@ import org.apache.lucene.geo.GeoUtils;* range based on the morton codes of the min and max lat/lon pairs. Terms* passing this initial filter are passed to a final check that verifies whether* the decoded lat/lon falls within (or on the boundary) of the query bounding box.- * The value comparisons are subject to a precision tolerance defined in- * {@value org.apache.lucene.spatial.util.GeoEncodingUtils#TOLERANCE}** NOTES:* 1. All latitude/longitude values must be in decimal degrees.diff --git a/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/search/GeoPointInPolygonQuery.java b/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/search/GeoPointInPolygonQuery.javaindex a06bdc07149..26af78e1824 100644--- a/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/search/GeoPointInPolygonQuery.java+++ b/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/search/GeoPointInPolygonQuery.java@@ -33,8 +33,7 @@ import org.apache.lucene.geo.Polygon;* of the min and max lat/lon pairs. Terms passing this initial filter are passed* to a secondary filter that verifies whether the decoded lat/lon point falls within* (or on the boundary) of the bounding box query. Finally, the remaining candidate- * term is passed to the final point in polygon check. All value comparisons are subject- * to the same precision tolerance defined in {@value GeoEncodingUtils#TOLERANCE}+ * term is passed to the final point in polygon check.** @see Polygon* @lucene.experimentaldiff --git a/lucene/spatial/src/java/org/apache/lucene/spatial/util/GeoEncodingUtils.java b/lucene/spatial/src/java/org/apache/lucene/spatial/util/GeoEncodingUtils.javaindex d2141d93c15..95aea2aa322 100644--- a/lucene/spatial/src/java/org/apache/lucene/spatial/util/GeoEncodingUtils.java+++ b/lucene/spatial/src/java/org/apache/lucene/spatial/util/GeoEncodingUtils.java@@ -41,10 +41,7 @@ public final class GeoEncodingUtils {* for encoding <code>geoEncoded</code> values.* @see #geoCodedToPrefixCodedBytes(long, int, BytesRefBuilder)*/- public static final int BUF_SIZE_LONG = 28/8 + 1;-- /** rounding error for quantized latitude and longitude values */- public static final double TOLERANCE = 1E-6;+ private static final int BUF_SIZE_LONG = 28/8 + 1;// No instance:private GeoEncodingUtils() {@@ -91,8 +88,12 @@ public final class GeoEncodingUtils {/** Convert a prefix coded geo term back into the geocoded morton long */public static long prefixCodedToGeoCoded(final BytesRef val) {- final long result = fromBytes((byte)0, (byte)0, (byte)0, (byte)0,- val.bytes[val.offset+0], val.bytes[val.offset+1], val.bytes[val.offset+2], val.bytes[val.offset+3]);+ final long result = 0L+ | (val.bytes[val.offset+0] & 255L) << 24+ | (val.bytes[val.offset+1] & 255L) << 16+ | (val.bytes[val.offset+2] & 255L) << 8+ | val.bytes[val.offset+3] & 255L;+return result << 32;}@@ -130,13 +131,6 @@ public final class GeoEncodingUtils {return shift;}- /** Converts 8 bytes to a long value */- protected static long fromBytes(byte b1, byte b2, byte b3, byte b4, byte b5, byte b6, byte b7, byte b8) {- return ((long)b1 & 255L) << 56 | ((long)b2 & 255L) << 48 | ((long)b3 & 255L) << 40- | ((long)b4 & 255L) << 32 | ((long)b5 & 255L) << 24 | ((long)b6 & 255L) << 16- | ((long)b7 & 255L) << 8 | (long)b8 & 255L;- }-/** Converts a long value into a bit string (useful for debugging) */public static String geoTermToString(long term) {StringBuilder s = new StringBuilder(64);diff --git a/lucene/spatial/src/test/org/apache/lucene/spatial/util/TestGeoEncodingUtils.java b/lucene/spatial/src/test/org/apache/lucene/spatial/util/TestGeoEncodingUtils.javaindex 1a1b2cc5529..aab0de0c608 100644--- a/lucene/spatial/src/test/org/apache/lucene/spatial/util/TestGeoEncodingUtils.java+++ b/lucene/spatial/src/test/org/apache/lucene/spatial/util/TestGeoEncodingUtils.java@@ -61,8 +61,9 @@ public class TestGeoEncodingUtils extends LuceneTestCase {double latEnc = GeoEncodingUtils.mortonUnhashLat(enc);double lonEnc = GeoEncodingUtils.mortonUnhashLon(enc);- assertEquals("lat=" + lat + " latEnc=" + latEnc + " diff=" + (lat - latEnc), lat, latEnc, GeoEncodingUtils.TOLERANCE);- assertEquals("lon=" + lon + " lonEnc=" + lonEnc + " diff=" + (lon - lonEnc), lon, lonEnc, GeoEncodingUtils.TOLERANCE);+ // todo remove tolerance+ assertEquals("lat=" + lat + " latEnc=" + latEnc + " diff=" + (lat - latEnc), lat, latEnc, 1e-6);+ assertEquals("lon=" + lon + " lonEnc=" + lonEnc + " diff=" + (lon - lonEnc), lon, lonEnc, 1e-6);}}