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/08/28 14:41:51 UTC
svn commit: r1698321 - in
/lucene/dev/branches/lucene6699/lucene/spatial3d/src/java/org/apache/lucene/bkdtree3d:
Geo3DDocValuesFormat.java PointInGeo3DShapeQuery.java
Author: mikemccand
Date: Fri Aug 28 12:41:51 2015
New Revision: 1698321
URL: http://svn.apache.org/r1698321
Log:
LUCENE-6699: fix encode to round instead of truncate to reduce quantization error; fix quantixed bbox decode
Modified:
lucene/dev/branches/lucene6699/lucene/spatial3d/src/java/org/apache/lucene/bkdtree3d/Geo3DDocValuesFormat.java
lucene/dev/branches/lucene6699/lucene/spatial3d/src/java/org/apache/lucene/bkdtree3d/PointInGeo3DShapeQuery.java
Modified: lucene/dev/branches/lucene6699/lucene/spatial3d/src/java/org/apache/lucene/bkdtree3d/Geo3DDocValuesFormat.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6699/lucene/spatial3d/src/java/org/apache/lucene/bkdtree3d/Geo3DDocValuesFormat.java?rev=1698321&r1=1698320&r2=1698321&view=diff
==============================================================================
--- lucene/dev/branches/lucene6699/lucene/spatial3d/src/java/org/apache/lucene/bkdtree3d/Geo3DDocValuesFormat.java (original)
+++ lucene/dev/branches/lucene6699/lucene/spatial3d/src/java/org/apache/lucene/bkdtree3d/Geo3DDocValuesFormat.java Fri Aug 28 12:41:51 2015
@@ -133,17 +133,29 @@ public class Geo3DDocValuesFormat extend
if (x < -max) {
throw new IllegalArgumentException("value=" + x + " is out-of-bounds (less than than -max for PlanetModel=" + planetModel + " " + max);
}
- long y = (long) (x * (Integer.MAX_VALUE / max));
+ long y = Math.round (x * (Integer.MAX_VALUE / max));
assert y >= Integer.MIN_VALUE;
assert y <= Integer.MAX_VALUE;
return (int) y;
}
+ /** Center decode */
static double decodeValue(double planetMax, int x) {
return x * (planetMax / Integer.MAX_VALUE);
}
+ /** More negative decode, at bottom of cell */
+ static double decodeValueMin(double planetMax, int x) {
+ return (((double)x) - 0.5) * (planetMax / Integer.MAX_VALUE);
+ }
+
+ /** More positive decode, at top of cell */
+ static double decodeValueMax(double planetMax, int x) {
+ return (((double)x) + 0.5) * (planetMax / Integer.MAX_VALUE);
+ }
+
+
static int readInt(byte[] bytes, int offset) {
return ((bytes[offset] & 0xFF) << 24) | ((bytes[offset+1] & 0xFF) << 16)
| ((bytes[offset+2] & 0xFF) << 8) | (bytes[offset+3] & 0xFF);
Modified: lucene/dev/branches/lucene6699/lucene/spatial3d/src/java/org/apache/lucene/bkdtree3d/PointInGeo3DShapeQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6699/lucene/spatial3d/src/java/org/apache/lucene/bkdtree3d/PointInGeo3DShapeQuery.java?rev=1698321&r1=1698320&r2=1698321&view=diff
==============================================================================
--- lucene/dev/branches/lucene6699/lucene/spatial3d/src/java/org/apache/lucene/bkdtree3d/PointInGeo3DShapeQuery.java (original)
+++ lucene/dev/branches/lucene6699/lucene/spatial3d/src/java/org/apache/lucene/bkdtree3d/PointInGeo3DShapeQuery.java Fri Aug 28 12:41:51 2015
@@ -145,22 +145,6 @@ public class PointInGeo3DShapeQuery exte
return shape.isWithin(x, y, z);
}
- private int roundUp(int x) {
- if (x >=0 && x < Integer.MAX_VALUE) {
- return x+1;
- } else {
- return x;
- }
- }
-
- private int roundDown(int x) {
- if (x < 0 && x > Integer.MIN_VALUE) {
- return x-1;
- } else {
- return x;
- }
- }
-
@Override
public BKD3DTreeReader.Relation compare(int cellXMinEnc, int cellXMaxEnc, int cellYMinEnc, int cellYMaxEnc, int cellZMinEnc, int cellZMaxEnc) {
assert cellXMinEnc <= cellXMaxEnc;
@@ -170,22 +154,13 @@ public class PointInGeo3DShapeQuery exte
// Because the BKD tree operates in quantized (64 bit -> 32 bit) space, and the cell bounds
// here are inclusive, we need to extend the bounds to the largest un-quantized values that
// could quantize into these bounds. The encoding (Geo3DDocValuesFormat.encodeValue) does
- // a simple truncation from double to long, so e.g. 1.4 -> 1, and -1.4 -> -1:
-
- cellXMaxEnc = roundUp(cellXMaxEnc);
- cellYMaxEnc = roundUp(cellYMaxEnc);
- cellZMaxEnc = roundUp(cellZMaxEnc);
-
- cellXMinEnc = roundDown(cellXMinEnc);
- cellYMinEnc = roundDown(cellYMinEnc);
- cellZMinEnc = roundDown(cellZMinEnc);
-
- double cellXMin = Geo3DDocValuesFormat.decodeValue(treeDV.planetMax, cellXMinEnc);
- double cellXMax = Geo3DDocValuesFormat.decodeValue(treeDV.planetMax, cellXMaxEnc);
- double cellYMin = Geo3DDocValuesFormat.decodeValue(treeDV.planetMax, cellYMinEnc);
- double cellYMax = Geo3DDocValuesFormat.decodeValue(treeDV.planetMax, cellYMaxEnc);
- double cellZMin = Geo3DDocValuesFormat.decodeValue(treeDV.planetMax, cellZMinEnc);
- double cellZMax = Geo3DDocValuesFormat.decodeValue(treeDV.planetMax, cellZMaxEnc);
+ // a Math.round from double to long, so e.g. 1.4 -> 1, and -1.4 -> -1:
+ double cellXMin = Geo3DDocValuesFormat.decodeValueMin(treeDV.planetMax, cellXMinEnc);
+ double cellXMax = Geo3DDocValuesFormat.decodeValueMax(treeDV.planetMax, cellXMaxEnc);
+ double cellYMin = Geo3DDocValuesFormat.decodeValueMin(treeDV.planetMax, cellYMinEnc);
+ double cellYMax = Geo3DDocValuesFormat.decodeValueMax(treeDV.planetMax, cellYMaxEnc);
+ double cellZMin = Geo3DDocValuesFormat.decodeValueMin(treeDV.planetMax, cellZMinEnc);
+ double cellZMax = Geo3DDocValuesFormat.decodeValueMax(treeDV.planetMax, cellZMaxEnc);
//System.out.println(" compare: x=" + cellXMin + "-" + cellXMax + " y=" + cellYMin + "-" + cellYMax + " z=" + cellZMin + "-" + cellZMax);
GeoArea xyzSolid = GeoAreaFactory.makeGeoArea(planetModel, cellXMin, cellXMax, cellYMin, cellYMax, cellZMin, cellZMax);