You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by rm...@apache.org on 2016/04/01 14:33:22 UTC
lucene-solr:master: LUCENE-7160: LatLonPoint quantization should use
the same rounding mode as GeoPointField
Repository: lucene-solr
Updated Branches:
refs/heads/master cf7967cc4 -> c071a3a8b
LUCENE-7160: LatLonPoint quantization should use the same rounding mode as GeoPointField
Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/c071a3a8
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/c071a3a8
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/c071a3a8
Branch: refs/heads/master
Commit: c071a3a8b57f9a46ef1d236bd70233c0ae4224c7
Parents: cf7967c
Author: Robert Muir <rm...@apache.org>
Authored: Fri Apr 1 08:32:16 2016 -0400
Committer: Robert Muir <rm...@apache.org>
Committed: Fri Apr 1 08:32:16 2016 -0400
----------------------------------------------------------------------
.../org/apache/lucene/document/LatLonPoint.java | 4 ++--
.../apache/lucene/document/TestLatLonPoint.java | 19 ++++++++++++++++---
.../document/TestLatLonPointDistanceSort.java | 10 +++++-----
.../apache/lucene/spatial/util/TestGeoUtils.java | 15 +++++++++++++++
4 files changed, 38 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/c071a3a8/lucene/sandbox/src/java/org/apache/lucene/document/LatLonPoint.java
----------------------------------------------------------------------
diff --git a/lucene/sandbox/src/java/org/apache/lucene/document/LatLonPoint.java b/lucene/sandbox/src/java/org/apache/lucene/document/LatLonPoint.java
index 6e9e715..70149b6 100644
--- a/lucene/sandbox/src/java/org/apache/lucene/document/LatLonPoint.java
+++ b/lucene/sandbox/src/java/org/apache/lucene/document/LatLonPoint.java
@@ -143,7 +143,7 @@ public class LatLonPoint extends Field {
if (latitude == 90.0D) {
latitude = Math.nextDown(latitude);
}
- return Math.toIntExact((long) (latitude * LATITUDE_ENCODE));
+ return (int) Math.floor(latitude * LATITUDE_ENCODE);
}
/**
@@ -158,7 +158,7 @@ public class LatLonPoint extends Field {
if (longitude == 180.0D) {
longitude = Math.nextDown(longitude);
}
- return Math.toIntExact((long) (longitude * LONGITUDE_ENCODE));
+ return (int) Math.floor(longitude * LONGITUDE_ENCODE);
}
/**
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/c071a3a8/lucene/sandbox/src/test/org/apache/lucene/document/TestLatLonPoint.java
----------------------------------------------------------------------
diff --git a/lucene/sandbox/src/test/org/apache/lucene/document/TestLatLonPoint.java b/lucene/sandbox/src/test/org/apache/lucene/document/TestLatLonPoint.java
index 55c8062..045f8ba 100644
--- a/lucene/sandbox/src/test/org/apache/lucene/document/TestLatLonPoint.java
+++ b/lucene/sandbox/src/test/org/apache/lucene/document/TestLatLonPoint.java
@@ -23,10 +23,10 @@ public class TestLatLonPoint extends LuceneTestCase {
public void testToString() throws Exception {
// looks crazy due to lossiness
- assertEquals("LatLonPoint <field:18.313693958334625,-65.22744392976165>",(new LatLonPoint("field", 18.313694, -65.227444)).toString());
+ assertEquals("LatLonPoint <field:18.313693958334625,-65.22744401358068>",(new LatLonPoint("field", 18.313694, -65.227444)).toString());
// looks crazy due to lossiness
- assertEquals("field:[17.99999997485429 TO 18.999999999068677],[-65.9999999217689 TO -64.99999998137355]", LatLonPoint.newBoxQuery("field", 18, 19, -66, -65).toString());
+ assertEquals("field:[17.99999997485429 TO 18.999999999068677],[-66.00000000558794 TO -65.00000006519258]", LatLonPoint.newBoxQuery("field", 18, 19, -66, -65).toString());
// distance query does not quantize inputs
assertEquals("field:18.0,19.0 +/- 25.0 meters", LatLonPoint.newDistanceQuery("field", 18, 19, 25).toString());
@@ -84,5 +84,18 @@ public class TestLatLonPoint extends LuceneTestCase {
assertEquals(latEnc, latEnc2, 0.0);
assertEquals(lonEnc, lonEnc2, 0.0);
}
- }
+ }
+
+ /** make sure values always go down: this is important for edge case consistency */
+ public void testEncodeDecodeRoundsDown() throws Exception {
+ int iters = atLeast(1000);
+ for(int iter=0;iter<iters;iter++) {
+ double lat = -90 + 180.0 * random().nextDouble();
+ double lon = -180 + 360.0 * random().nextDouble();
+ double latEnc = LatLonPoint.decodeLatitude(LatLonPoint.encodeLatitude(lat));
+ double lonEnc = LatLonPoint.decodeLongitude(LatLonPoint.encodeLongitude(lon));
+ assertTrue(latEnc <= lat);
+ assertTrue(lonEnc <= lon);
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/c071a3a8/lucene/sandbox/src/test/org/apache/lucene/document/TestLatLonPointDistanceSort.java
----------------------------------------------------------------------
diff --git a/lucene/sandbox/src/test/org/apache/lucene/document/TestLatLonPointDistanceSort.java b/lucene/sandbox/src/test/org/apache/lucene/document/TestLatLonPointDistanceSort.java
index 904532d..43d3a26 100644
--- a/lucene/sandbox/src/test/org/apache/lucene/document/TestLatLonPointDistanceSort.java
+++ b/lucene/sandbox/src/test/org/apache/lucene/document/TestLatLonPointDistanceSort.java
@@ -62,13 +62,13 @@ public class TestLatLonPointDistanceSort extends LuceneTestCase {
TopDocs td = searcher.search(new MatchAllDocsQuery(), 3, sort);
FieldDoc d = (FieldDoc) td.scoreDocs[0];
- assertEquals(462.1004647449412, (Double)d.fields[0], 0.0D);
+ assertEquals(462.1028401330432, (Double)d.fields[0], 0.0D);
d = (FieldDoc) td.scoreDocs[1];
- assertEquals(1054.9826700985088, (Double)d.fields[0], 0.0D);
+ assertEquals(1054.9842850974826, (Double)d.fields[0], 0.0D);
d = (FieldDoc) td.scoreDocs[2];
- assertEquals(5285.883948830351, (Double)d.fields[0], 0.0D);
+ assertEquals(5285.881528419706, (Double)d.fields[0], 0.0D);
reader.close();
dir.close();
@@ -99,10 +99,10 @@ public class TestLatLonPointDistanceSort extends LuceneTestCase {
TopDocs td = searcher.search(new MatchAllDocsQuery(), 3, sort);
FieldDoc d = (FieldDoc) td.scoreDocs[0];
- assertEquals(462.1004647449412D, (Double)d.fields[0], 0.0D);
+ assertEquals(462.1028401330432D, (Double)d.fields[0], 0.0D);
d = (FieldDoc) td.scoreDocs[1];
- assertEquals(1054.9826700985088, (Double)d.fields[0], 0.0D);
+ assertEquals(1054.9842850974826, (Double)d.fields[0], 0.0D);
d = (FieldDoc) td.scoreDocs[2];
assertEquals(Double.POSITIVE_INFINITY, (Double)d.fields[0], 0.0D);
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/c071a3a8/lucene/spatial/src/test/org/apache/lucene/spatial/util/TestGeoUtils.java
----------------------------------------------------------------------
diff --git a/lucene/spatial/src/test/org/apache/lucene/spatial/util/TestGeoUtils.java b/lucene/spatial/src/test/org/apache/lucene/spatial/util/TestGeoUtils.java
index 5cb9fc9..7bd3fed 100644
--- a/lucene/spatial/src/test/org/apache/lucene/spatial/util/TestGeoUtils.java
+++ b/lucene/spatial/src/test/org/apache/lucene/spatial/util/TestGeoUtils.java
@@ -99,6 +99,21 @@ public class TestGeoUtils extends LuceneTestCase {
assertEquals("lon=" + lon + " lonEnc=" + lonEnc + " diff=" + (lon - lonEnc), lon, lonEnc, GeoEncodingUtils.TOLERANCE);
}
}
+
+ /** make sure values always go down: this is important for edge case consistency */
+ public void testEncodeDecodeRoundsDown() throws Exception {
+ int iters = atLeast(1000);
+ for(int iter=0;iter<iters;iter++) {
+ double lat = -90 + 180.0 * random().nextDouble();
+ double lon = -180 + 360.0 * random().nextDouble();
+
+ long enc = GeoEncodingUtils.mortonHash(lat, lon);
+ double latEnc = GeoEncodingUtils.mortonUnhashLat(enc);
+ double lonEnc = GeoEncodingUtils.mortonUnhashLon(enc);
+ assertTrue(latEnc <= lat);
+ assertTrue(lonEnc <= lon);
+ }
+ }
public void testScaleUnscaleIsStable() throws Exception {
int iters = atLeast(1000);