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 cc11294e6c2..1ff56a77a6f 100644 --- a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/Geo3DUtil.java +++ b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/Geo3DUtil.java @@ -71,4 +71,17 @@ class Geo3DUtil { assert result > x; return result; } + + /** Returns smallest double that would encode to int x. */ + // NOTE: keep this package private!! + static double decodeValueFloor(int x) { + return x * DECODE; + } + + /** Returns largest double that would encode to int x. */ + // NOTE: keep this package private!! + static double decodeValueCeil(int x) { + assert x < Integer.MAX_VALUE; + return Math.nextDown((x+1) * DECODE); + } } diff --git a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/PointInShapeIntersectVisitor.java b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/PointInShapeIntersectVisitor.java index 25dea721c11..b9d4e70a6c8 100644 --- a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/PointInShapeIntersectVisitor.java +++ b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/PointInShapeIntersectVisitor.java @@ -57,12 +57,12 @@ class PointInShapeIntersectVisitor implements IntersectVisitor { // here are inclusive, we need to extend the bounds to the largest un-quantized values that // could quantize into these bounds. The encoding (Geo3DUtil.encodeValue) does // a Math.round from double to long, so e.g. 1.4 -> 1, and -1.4 -> -1: - double xMin = decodeValueMin(NumericUtils.sortableBytesToInt(minPackedValue, 0)); - double xMax = decodeValueMax(NumericUtils.sortableBytesToInt(maxPackedValue, 0)); - double yMin = decodeValueMin(NumericUtils.sortableBytesToInt(minPackedValue, 1 * Integer.BYTES)); - double yMax = decodeValueMax(NumericUtils.sortableBytesToInt(maxPackedValue, 1 * Integer.BYTES)); - double zMin = decodeValueMin(NumericUtils.sortableBytesToInt(minPackedValue, 2 * Integer.BYTES)); - double zMax = decodeValueMax(NumericUtils.sortableBytesToInt(maxPackedValue, 2 * Integer.BYTES)); + double xMin = Geo3DUtil.decodeValueFloor(NumericUtils.sortableBytesToInt(minPackedValue, 0)); + double xMax = Geo3DUtil.decodeValueCeil(NumericUtils.sortableBytesToInt(maxPackedValue, 0)); + double yMin = Geo3DUtil.decodeValueFloor(NumericUtils.sortableBytesToInt(minPackedValue, 1 * Integer.BYTES)); + double yMax = Geo3DUtil.decodeValueCeil(NumericUtils.sortableBytesToInt(maxPackedValue, 1 * Integer.BYTES)); + double zMin = Geo3DUtil.decodeValueFloor(NumericUtils.sortableBytesToInt(minPackedValue, 2 * Integer.BYTES)); + double zMax = Geo3DUtil.decodeValueCeil(NumericUtils.sortableBytesToInt(maxPackedValue, 2 * Integer.BYTES)); //System.out.println(" compare: x=" + cellXMin + "-" + cellXMax + " y=" + cellYMin + "-" + cellYMax + " z=" + cellZMin + "-" + cellZMax); assert xMin <= xMax; @@ -94,14 +94,4 @@ class PointInShapeIntersectVisitor implements IntersectVisitor { return Relation.CELL_CROSSES_QUERY; } } - - /** More negative decode, at bottom of cell */ - static double decodeValueMin(int x) { - return (((double)x) - 0.5) * Geo3DUtil.DECODE; - } - - /** More positive decode, at top of cell */ - static double decodeValueMax(int x) { - return (((double)x) + 0.5) * Geo3DUtil.DECODE; - } } 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 b751125bced..410618c829e 100644 --- a/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/TestGeo3DPoint.java +++ b/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/TestGeo3DPoint.java @@ -75,7 +75,6 @@ import org.apache.lucene.util.LuceneTestCase; import org.apache.lucene.util.NumericUtils; import org.apache.lucene.util.StringHelper; import org.apache.lucene.util.TestUtil; -import org.junit.Ignore; import com.carrotsearch.randomizedtesting.generators.RandomInts; @@ -266,14 +265,14 @@ public class TestGeo3DPoint extends LuceneTestCase { } else { GeoArea xyzSolid = GeoAreaFactory.makeGeoArea(PlanetModel.WGS84, - PointInShapeIntersectVisitor.decodeValueMin(cell.xMinEnc), PointInShapeIntersectVisitor.decodeValueMax(cell.xMaxEnc), - PointInShapeIntersectVisitor.decodeValueMin(cell.yMinEnc), PointInShapeIntersectVisitor.decodeValueMax(cell.yMaxEnc), - PointInShapeIntersectVisitor.decodeValueMin(cell.zMinEnc), PointInShapeIntersectVisitor.decodeValueMax(cell.zMaxEnc)); + Geo3DUtil.decodeValueFloor(cell.xMinEnc), Geo3DUtil.decodeValueCeil(cell.xMaxEnc), + Geo3DUtil.decodeValueFloor(cell.yMinEnc), Geo3DUtil.decodeValueCeil(cell.yMaxEnc), + Geo3DUtil.decodeValueFloor(cell.zMinEnc), Geo3DUtil.decodeValueCeil(cell.zMaxEnc)); if (VERBOSE) { - log.println(" minx="+PointInShapeIntersectVisitor.decodeValueMin(cell.xMinEnc)+" maxx="+PointInShapeIntersectVisitor.decodeValueMax(cell.xMaxEnc)+ - " miny="+PointInShapeIntersectVisitor.decodeValueMin(cell.yMinEnc)+" maxy="+PointInShapeIntersectVisitor.decodeValueMax(cell.yMaxEnc)+ - " minz="+PointInShapeIntersectVisitor.decodeValueMin(cell.zMinEnc)+" maxz="+PointInShapeIntersectVisitor.decodeValueMax(cell.zMaxEnc)); + log.println(" minx="+Geo3DUtil.decodeValueFloor(cell.xMinEnc)+" maxx="+Geo3DUtil.decodeValueCeil(cell.xMaxEnc)+ + " miny="+Geo3DUtil.decodeValueFloor(cell.yMinEnc)+" maxy="+Geo3DUtil.decodeValueCeil(cell.yMaxEnc)+ + " minz="+Geo3DUtil.decodeValueFloor(cell.zMinEnc)+" maxz="+Geo3DUtil.decodeValueCeil(cell.zMaxEnc)); } switch (xyzSolid.getRelationship(shape)) { @@ -312,9 +311,7 @@ public class TestGeo3DPoint extends LuceneTestCase { log.println(" GeoArea.DISJOINT: drop this cell"); for(int docID=0;docID