You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ab...@apache.org on 2018/11/05 18:56:31 UTC

[13/26] lucene-solr:jira/solr-12730: LUCENE-8540: Better handling of min/max values for Geo3d encoding

LUCENE-8540: Better handling of min/max values for Geo3d encoding


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

Branch: refs/heads/jira/solr-12730
Commit: 07b93a97f04ea6738962810d606ef16f0c42d1a8
Parents: 1e0e8d4
Author: iverase <iv...@apache.org>
Authored: Fri Nov 2 07:19:13 2018 +0100
Committer: iverase <iv...@apache.org>
Committed: Fri Nov 2 07:19:13 2018 +0100

----------------------------------------------------------------------
 lucene/CHANGES.txt                              |  4 +++
 .../org/apache/lucene/spatial3d/Geo3DUtil.java  |  9 ++++-
 .../apache/lucene/spatial3d/TestGeo3DPoint.java | 38 ++++++++++++++++++--
 3 files changed, 48 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/07b93a97/lucene/CHANGES.txt
----------------------------------------------------------------------
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 9b0382b..dc1336d 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -236,6 +236,10 @@ Improvements:
   first 4 are index dimensions defining the bounding box of the Triangle and the
   remaining 3 data dimensions define the vertices of the triangle. (Nick Knize)
 
+Bug Fixes:
+
+* LUCENE-8540: Better handling of min/max values for Geo3d encoding. (Ignacio Vera)
+
 Other:
 
 * LUCENE-8523: Correct typo in JapaneseNumberFilterFactory javadocs (Ankush Jhalani

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/07b93a97/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/Geo3DUtil.java
----------------------------------------------------------------------
diff --git a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/Geo3DUtil.java b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/Geo3DUtil.java
index 88537f4..4e1ecb5 100644
--- a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/Geo3DUtil.java
+++ b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/Geo3DUtil.java
@@ -80,6 +80,10 @@ class Geo3DUtil {
   /** Returns smallest double that would encode to int x. */
   // NOTE: keep this package private!!
   static double decodeValueFloor(int x) {
+    assert x <= MAX_ENCODED_VALUE && x >= MIN_ENCODED_VALUE;
+    if (x == MIN_ENCODED_VALUE) {
+      return -MAX_VALUE;
+    }
     return x * DECODE;
   }
   
@@ -105,7 +109,10 @@ class Geo3DUtil {
   /** Returns largest double that would encode to int x. */
   // NOTE: keep this package private!!
   static double decodeValueCeil(int x) {
-    assert x < Integer.MAX_VALUE;
+    assert x <= MAX_ENCODED_VALUE && x >= MIN_ENCODED_VALUE;
+    if (x == MAX_ENCODED_VALUE) {
+      return MAX_VALUE;
+    }
     return Math.nextDown((x+1) * DECODE);
   }
   

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/07b93a97/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/TestGeo3DPoint.java
----------------------------------------------------------------------
diff --git a/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/TestGeo3DPoint.java b/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/TestGeo3DPoint.java
index df67a8d..66fa3cd 100644
--- a/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/TestGeo3DPoint.java
+++ b/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/TestGeo3DPoint.java
@@ -1204,6 +1204,40 @@ public class TestGeo3DPoint extends LuceneTestCase {
     }
   }
 
+  public void testMinValueQuantization(){
+    int encoded = Geo3DUtil.MIN_ENCODED_VALUE;
+    double minValue= -PlanetModel.WGS84.getMaximumMagnitude();
+    //Normal encoding
+    double decoded = Geo3DUtil.decodeValue(encoded);
+    assertEquals(minValue, decoded, 0d);
+    assertEquals(encoded, Geo3DUtil.encodeValue(decoded));
+    //Encoding floor
+    double decodedFloor = Geo3DUtil.decodeValueFloor(encoded);
+    assertEquals(minValue, decodedFloor, 0d);
+    assertEquals(encoded, Geo3DUtil.encodeValue(decodedFloor));
+    //Encoding ceiling
+    double decodedCeiling = Geo3DUtil.decodeValueCeil(encoded);
+    assertTrue(decodedCeiling > minValue);
+    assertEquals(encoded, Geo3DUtil.encodeValue(decodedCeiling));
+  }
+
+  public void testMaxValueQuantization(){
+    int encoded = Geo3DUtil.MAX_ENCODED_VALUE;
+    double maxValue= PlanetModel.WGS84.getMaximumMagnitude();
+    //Normal encoding
+    double decoded = Geo3DUtil.decodeValue(encoded);
+    assertEquals(maxValue, decoded, 0d);
+    assertEquals(encoded, Geo3DUtil.encodeValue(decoded));
+    //Encoding floor
+    double decodedFloor = Geo3DUtil.decodeValueFloor(encoded);
+    assertTrue(decodedFloor <  maxValue);
+    assertEquals(encoded, Geo3DUtil.encodeValue(decodedFloor));
+    //Encoding ceiling
+    double decodedCeiling = Geo3DUtil.decodeValueCeil(encoded);
+    assertEquals(maxValue, decodedCeiling, 0d);
+    assertEquals(encoded, Geo3DUtil.encodeValue(decodedCeiling));
+  }
+
   // poached from TestGeoEncodingUtils.testLatitudeQuantization:
 
   /**
@@ -1215,10 +1249,10 @@ public class TestGeo3DPoint extends LuceneTestCase {
     Random random = random();
     for (int i = 0; i < 10000; i++) {
       int encoded = random.nextInt();
-      if (encoded < Geo3DUtil.MIN_ENCODED_VALUE) {
+      if (encoded <= Geo3DUtil.MIN_ENCODED_VALUE) {
         continue;
       }
-      if (encoded > Geo3DUtil.MAX_ENCODED_VALUE) {
+      if (encoded >= Geo3DUtil.MAX_ENCODED_VALUE) {
         continue;
       }
       double min = encoded * Geo3DUtil.DECODE;