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/31 21:39:23 UTC
svn commit: r1700313 - in
/lucene/dev/branches/lucene6699/lucene/spatial3d/src:
java/org/apache/lucene/bkdtree3d/ test/org/apache/lucene/bkdtree3d/
test/org/apache/lucene/geo3d/
Author: mikemccand
Date: Mon Aug 31 19:39:23 2015
New Revision: 1700313
URL: http://svn.apache.org/r1700313
Log:
LUCENE-6699: make encode/decodeValue symmetric
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/Geo3DPointField.java
lucene/dev/branches/lucene6699/lucene/spatial3d/src/java/org/apache/lucene/bkdtree3d/PointInGeo3DShapeQuery.java
lucene/dev/branches/lucene6699/lucene/spatial3d/src/test/org/apache/lucene/bkdtree3d/TestGeo3DPointField.java
lucene/dev/branches/lucene6699/lucene/spatial3d/src/test/org/apache/lucene/geo3d/GeoPolygonTest.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=1700313&r1=1700312&r2=1700313&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 Mon Aug 31 19:39:23 2015
@@ -115,25 +115,23 @@ public class Geo3DDocValuesFormat extend
}
/** Clips the incoming value to the allowed min/max range before encoding, instead of throwing an exception. */
- static int encodeValueLenient(PlanetModel planetModel, double x) {
- double max = planetModel.getMaximumMagnitude();
- if (x > max) {
- x = max;
- } else if (x < -max) {
- x = -max;
+ static int encodeValueLenient(double planetMax, double x) {
+ if (x > planetMax) {
+ x = planetMax;
+ } else if (x < -planetMax) {
+ x = -planetMax;
}
- return encodeValue(planetModel, x);
+ return encodeValue(planetMax, x);
}
- static int encodeValue(PlanetModel planetModel, double x) {
- double max = planetModel.getMaximumMagnitude();
- if (x > max) {
- throw new IllegalArgumentException("value=" + x + " is out-of-bounds (greater than max for PlanetModel=" + planetModel + " " + max);
+ static int encodeValue(double planetMax, double x) {
+ if (x > planetMax) {
+ throw new IllegalArgumentException("value=" + x + " is out-of-bounds (greater than planetMax=" + planetMax + ")");
}
- if (x < -max) {
- throw new IllegalArgumentException("value=" + x + " is out-of-bounds (less than than -max for PlanetModel=" + planetModel + " " + max);
+ if (x < -planetMax) {
+ throw new IllegalArgumentException("value=" + x + " is out-of-bounds (less than than -planetMax=" + -planetMax + ")");
}
- long y = Math.round (x * (Integer.MAX_VALUE / max));
+ long y = Math.round (x * (Integer.MAX_VALUE / planetMax));
assert y >= Integer.MIN_VALUE;
assert y <= Integer.MAX_VALUE;
Modified: lucene/dev/branches/lucene6699/lucene/spatial3d/src/java/org/apache/lucene/bkdtree3d/Geo3DPointField.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6699/lucene/spatial3d/src/java/org/apache/lucene/bkdtree3d/Geo3DPointField.java?rev=1700313&r1=1700312&r2=1700313&view=diff
==============================================================================
--- lucene/dev/branches/lucene6699/lucene/spatial3d/src/java/org/apache/lucene/bkdtree3d/Geo3DPointField.java (original)
+++ lucene/dev/branches/lucene6699/lucene/spatial3d/src/java/org/apache/lucene/bkdtree3d/Geo3DPointField.java Mon Aug 31 19:39:23 2015
@@ -46,7 +46,7 @@ public final class Geo3DPointField exten
super(name, TYPE);
// Translate lat/lon to x,y,z:
final GeoPoint point = new GeoPoint(planetModel, lat, lon);
- fillFieldsData(planetModel, point.x, point.y, point.z);
+ fillFieldsData(planetModel.getMaximumMagnitude(), point.x, point.y, point.z);
}
/**
@@ -56,14 +56,14 @@ public final class Geo3DPointField exten
*/
public Geo3DPointField(String name, PlanetModel planetModel, double x, double y, double z) {
super(name, TYPE);
- fillFieldsData(planetModel, x, y, z);
+ fillFieldsData(planetModel.getMaximumMagnitude(), x, y, z);
}
- private void fillFieldsData(PlanetModel planetModel, double x, double y, double z) {
+ private void fillFieldsData(double planetMax, double x, double y, double z) {
byte[] bytes = new byte[12];
- Geo3DDocValuesFormat.writeInt(Geo3DDocValuesFormat.encodeValue(planetModel, x), bytes, 0);
- Geo3DDocValuesFormat.writeInt(Geo3DDocValuesFormat.encodeValue(planetModel, y), bytes, 4);
- Geo3DDocValuesFormat.writeInt(Geo3DDocValuesFormat.encodeValue(planetModel, z), bytes, 8);
+ Geo3DDocValuesFormat.writeInt(Geo3DDocValuesFormat.encodeValue(planetMax, x), bytes, 0);
+ Geo3DDocValuesFormat.writeInt(Geo3DDocValuesFormat.encodeValue(planetMax, y), bytes, 4);
+ Geo3DDocValuesFormat.writeInt(Geo3DDocValuesFormat.encodeValue(planetMax, z), bytes, 8);
fieldsData = new BytesRef(bytes);
}
}
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=1700313&r1=1700312&r2=1700313&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 Mon Aug 31 19:39:23 2015
@@ -94,8 +94,9 @@ public class PointInGeo3DShapeQuery exte
XYZBounds bounds = new XYZBounds();
shape.getBounds(bounds);
- if (planetModel.getMaximumMagnitude() != treeDV.planetMax) {
- throw new IllegalStateException(planetModel + " is not the same one used during indexing: max=" + planetModel.getMaximumMagnitude() + " vs indexing max=" + treeDV.planetMax);
+ final double planetMax = planetModel.getMaximumMagnitude();
+ if (planetMax != treeDV.planetMax) {
+ throw new IllegalStateException(planetModel + " is not the same one used during indexing: planetMax=" + planetMax + " vs indexing planetMax=" + treeDV.planetMax);
}
/*
@@ -110,21 +111,12 @@ public class PointInGeo3DShapeQuery exte
assert xyzSolid.getRelationship(shape) == GeoArea.WITHIN || xyzSolid.getRelationship(shape) == GeoArea.OVERLAPS: "expected WITHIN (1) or OVERLAPS (2) but got " + xyzSolid.getRelationship(shape) + "; shape="+shape+"; XYZSolid="+xyzSolid;
*/
- // The fudge factor here (+/- 2.0 * MINIMUM_RESOLUTION) is here to ensure that
- // you get a WITHIN rather than an OVERLAPS if you expand the bounding box by
- // an amount sufficient to insure there are no overlaps between the shape and
- // the box. Otherwise according to the (revised) definition of getRelationship(),
- // you could technically get either one.
-
- // nocommit can we also remove this inflate?
- double inflate = 2.0 * Vector.MINIMUM_RESOLUTION;
-
- DocIdSet result = tree.intersect(Geo3DDocValuesFormat.encodeValueLenient(planetModel, bounds.getMinimumX() - inflate),
- Geo3DDocValuesFormat.encodeValueLenient(planetModel, bounds.getMaximumX() + inflate),
- Geo3DDocValuesFormat.encodeValueLenient(planetModel, bounds.getMinimumY() - inflate),
- Geo3DDocValuesFormat.encodeValueLenient(planetModel, bounds.getMaximumY() + inflate),
- Geo3DDocValuesFormat.encodeValueLenient(planetModel, bounds.getMinimumZ() - inflate),
- Geo3DDocValuesFormat.encodeValueLenient(planetModel, bounds.getMaximumZ() + inflate),
+ DocIdSet result = tree.intersect(Geo3DDocValuesFormat.encodeValueLenient(planetMax, bounds.getMinimumX()),
+ Geo3DDocValuesFormat.encodeValueLenient(planetMax, bounds.getMaximumX()),
+ Geo3DDocValuesFormat.encodeValueLenient(planetMax, bounds.getMinimumY()),
+ Geo3DDocValuesFormat.encodeValueLenient(planetMax, bounds.getMaximumY()),
+ Geo3DDocValuesFormat.encodeValueLenient(planetMax, bounds.getMinimumZ()),
+ Geo3DDocValuesFormat.encodeValueLenient(planetMax, bounds.getMaximumZ()),
new BKD3DTreeReader.ValueFilter() {
@Override
public boolean accept(int docID) {
Modified: lucene/dev/branches/lucene6699/lucene/spatial3d/src/test/org/apache/lucene/bkdtree3d/TestGeo3DPointField.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6699/lucene/spatial3d/src/test/org/apache/lucene/bkdtree3d/TestGeo3DPointField.java?rev=1700313&r1=1700312&r2=1700313&view=diff
==============================================================================
--- lucene/dev/branches/lucene6699/lucene/spatial3d/src/test/org/apache/lucene/bkdtree3d/TestGeo3DPointField.java (original)
+++ lucene/dev/branches/lucene6699/lucene/spatial3d/src/test/org/apache/lucene/bkdtree3d/TestGeo3DPointField.java Mon Aug 31 19:39:23 2015
@@ -241,7 +241,8 @@ public class TestGeo3DPointField extends
} else {
planetModel = PlanetModel.SPHERE;
}
-
+ final double planetMax = planetModel.getMaximumMagnitude();
+
BKD3DTreeWriter w = new BKD3DTreeWriter(maxPointsInLeaf, maxPointsSortInHeap);
for(int docID=0;docID<numPoints;docID++) {
Point point;
@@ -256,15 +257,15 @@ public class TestGeo3DPointField extends
if (VERBOSE) {
System.err.println(" docID=" + docID + " point=" + point);
- System.err.println(" x=" + encodeValue(planetModel, point.x) +
- " y=" + encodeValue(planetModel, point.y) +
- " z=" + encodeValue(planetModel, point.z));
+ System.err.println(" x=" + encodeValue(planetMax, point.x) +
+ " y=" + encodeValue(planetMax, point.y) +
+ " z=" + encodeValue(planetMax, point.z));
}
points.add(point);
- w.add(encodeValue(planetModel, point.x),
- encodeValue(planetModel, point.y),
- encodeValue(planetModel, point.z),
+ w.add(encodeValue(planetMax, point.x),
+ encodeValue(planetMax, point.y),
+ encodeValue(planetMax, point.z),
docID);
}
@@ -282,12 +283,12 @@ public class TestGeo3DPointField extends
Range y = randomRange(planetModel);
Range z = randomRange(planetModel);
- int xMinEnc = encodeValue(planetModel, x.min);
- int xMaxEnc = encodeValue(planetModel, x.max);
- int yMinEnc = encodeValue(planetModel, y.min);
- int yMaxEnc = encodeValue(planetModel, y.max);
- int zMinEnc = encodeValue(planetModel, z.min);
- int zMaxEnc = encodeValue(planetModel, z.max);
+ int xMinEnc = encodeValue(planetMax, x.min);
+ int xMaxEnc = encodeValue(planetMax, x.max);
+ int yMinEnc = encodeValue(planetMax, y.min);
+ int yMaxEnc = encodeValue(planetMax, y.max);
+ int zMinEnc = encodeValue(planetMax, z.min);
+ int zMaxEnc = encodeValue(planetMax, z.max);
if (VERBOSE) {
System.err.println("\nTEST: iter=" + iter + " bbox: x=" + x + " (" + xMinEnc + " TO " + xMaxEnc+ ")" + " y=" + y + " (" + yMinEnc + " TO " + yMaxEnc + ")" + " z=" + z + " (" + zMinEnc + " TO " + zMaxEnc + ")" );
@@ -305,9 +306,9 @@ public class TestGeo3DPointField extends
//System.out.println(" accept docID=" + docID + " point=" + point + " (x=" + encodeValue(point.x) + " y=" + encodeValue(point.y) + " z=" + encodeValue(point.z) + ")");
// System.out.println(" accept docID=" + docID + " point: x=" + point.x + " y=" + point.y + " z=" + point.z);
- int xEnc = encodeValue(planetModel, point.x);
- int yEnc = encodeValue(planetModel, point.y);
- int zEnc = encodeValue(planetModel, point.z);
+ int xEnc = encodeValue(planetMax, point.x);
+ int yEnc = encodeValue(planetMax, point.y);
+ int zEnc = encodeValue(planetMax, point.z);
boolean accept = xEnc >= xMinEnc && xEnc <= xMaxEnc &&
yEnc >= yMinEnc && yEnc <= yMaxEnc &&
@@ -365,9 +366,9 @@ public class TestGeo3DPointField extends
boolean actual = matches.get(docID);
// We must quantize exactly as BKD tree does else we'll get false failures
- int xEnc = encodeValue(planetModel, point.x);
- int yEnc = encodeValue(planetModel, point.y);
- int zEnc = encodeValue(planetModel, point.z);
+ int xEnc = encodeValue(planetMax, point.x);
+ int yEnc = encodeValue(planetMax, point.y);
+ int zEnc = encodeValue(planetMax, point.z);
boolean expected = xEnc >= xMinEnc && xEnc <= xMaxEnc &&
yEnc >= yMinEnc && yEnc <= yMaxEnc &&
@@ -412,10 +413,10 @@ public class TestGeo3DPointField extends
}
/** Returns true if the quantized point lies within this cell, inclusive on all bounds. */
- public boolean contains(PlanetModel planetModel, GeoPoint point) {
- int docX = encodeValue(planetModel, point.x);
- int docY = encodeValue(planetModel, point.y);
- int docZ = encodeValue(planetModel, point.z);
+ public boolean contains(double planetMax, GeoPoint point) {
+ int docX = encodeValue(planetMax, point.x);
+ int docY = encodeValue(planetMax, point.y);
+ int docZ = encodeValue(planetMax, point.z);
return docX >= xMinEnc && docX <= xMaxEnc &&
docY >= yMinEnc && docY <= yMaxEnc &&
@@ -430,9 +431,9 @@ public class TestGeo3DPointField extends
private static GeoPoint quantize(PlanetModel planetModel, GeoPoint point) {
double planetMax = planetModel.getMaximumMagnitude();
- return new GeoPoint(decodeValueCenter(planetMax, encodeValue(planetModel, point.x)),
- decodeValueCenter(planetMax, encodeValue(planetModel, point.y)),
- decodeValueCenter(planetMax, encodeValue(planetModel, point.z)));
+ return new GeoPoint(decodeValueCenter(planetMax, encodeValue(planetMax, point.x)),
+ decodeValueCenter(planetMax, encodeValue(planetMax, point.y)),
+ decodeValueCenter(planetMax, encodeValue(planetMax, point.z)));
}
/** Tests consistency of GeoArea.getRelationship vs GeoShape.isWithin */
@@ -478,12 +479,12 @@ public class TestGeo3DPointField extends
// Start with the root cell that fully contains the shape:
Cell root = new Cell(null,
- encodeValueLenient(planetModel, bounds.getMinimumX()),
- encodeValueLenient(planetModel, bounds.getMaximumX()),
- encodeValueLenient(planetModel, bounds.getMinimumY()),
- encodeValueLenient(planetModel, bounds.getMaximumY()),
- encodeValueLenient(planetModel, bounds.getMinimumZ()),
- encodeValueLenient(planetModel, bounds.getMaximumZ()),
+ encodeValueLenient(planetMax, bounds.getMinimumX()),
+ encodeValueLenient(planetMax, bounds.getMaximumX()),
+ encodeValueLenient(planetMax, bounds.getMinimumY()),
+ encodeValueLenient(planetMax, bounds.getMaximumY()),
+ encodeValueLenient(planetMax, bounds.getMinimumZ()),
+ encodeValueLenient(planetMax, bounds.getMaximumZ()),
0);
if (VERBOSE) {
@@ -510,7 +511,7 @@ public class TestGeo3DPointField extends
// Leaf cell: brute force check all docs that fall within this cell:
for(int docID=0;docID<numDocs;docID++) {
GeoPoint point = docs[docID];
- if (cell.contains(planetModel, point)) {
+ if (cell.contains(planetMax, point)) {
if (shape.isWithin(quantize(planetModel, point))) {
if (VERBOSE) {
System.out.println(" check doc=" + docID + ": match!");
@@ -543,7 +544,7 @@ public class TestGeo3DPointField extends
System.out.println(" GeoArea.CONTAINS: now addAll");
}
for(int docID=0;docID<numDocs;docID++) {
- if (cell.contains(planetModel, docs[docID])) {
+ if (cell.contains(planetMax, docs[docID])) {
if (VERBOSE) {
System.out.println(" addAll doc=" + docID);
}
@@ -571,7 +572,7 @@ public class TestGeo3DPointField extends
if (VERBOSE) {
System.out.println(" GeoArea.DISJOINT: drop this cell");
for(int docID=0;docID<numDocs;docID++) {
- if (cell.contains(planetModel, docs[docID])) {
+ if (cell.contains(planetMax, docs[docID])) {
if (VERBOSE) {
System.out.println(" skip doc=" + docID);
}
Modified: lucene/dev/branches/lucene6699/lucene/spatial3d/src/test/org/apache/lucene/geo3d/GeoPolygonTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6699/lucene/spatial3d/src/test/org/apache/lucene/geo3d/GeoPolygonTest.java?rev=1700313&r1=1700312&r2=1700313&view=diff
==============================================================================
--- lucene/dev/branches/lucene6699/lucene/spatial3d/src/test/org/apache/lucene/geo3d/GeoPolygonTest.java (original)
+++ lucene/dev/branches/lucene6699/lucene/spatial3d/src/test/org/apache/lucene/geo3d/GeoPolygonTest.java Mon Aug 31 19:39:23 2015
@@ -123,7 +123,27 @@ public class GeoPolygonTest {
GeoMembershipShape c;
LatLonBounds b;
List<GeoPoint> points;
-
+ XYZBounds xyzb;
+ GeoPoint point;
+ GeoArea area;
+
+ // BKD failure
+ points = new ArrayList<GeoPoint>();
+ points.add(new GeoPoint(PlanetModel.WGS84, -0.36716183577912814, 1.4836349969188696));
+ points.add(new GeoPoint(PlanetModel.WGS84, 0.7846038240742979, -0.02743348424931823));
+ points.add(new GeoPoint(PlanetModel.WGS84, -0.7376479402362607, -0.5072961758807019));
+ points.add(new GeoPoint(PlanetModel.WGS84, -0.3760415907667887, 1.4970455334565513));
+
+ c = GeoPolygonFactory.makeGeoPolygon(PlanetModel.WGS84, points, 1);
+
+ point = new GeoPoint(PlanetModel.WGS84, -0.01580760332365284, -0.03956004622490505);
+ assertTrue(c.isWithin(point));
+ xyzb = new XYZBounds();
+ c.getBounds(xyzb);
+ area = GeoAreaFactory.makeGeoArea(PlanetModel.WGS84,
+ xyzb.getMinimumX(), xyzb.getMaximumX(), xyzb.getMinimumY(), xyzb.getMaximumY(), xyzb.getMinimumZ(), xyzb.getMaximumZ());
+ assertTrue(area.isWithin(point));
+
points = new ArrayList<GeoPoint>();
points.add(new GeoPoint(PlanetModel.SPHERE, -0.1, -0.5));
points.add(new GeoPoint(PlanetModel.SPHERE, 0.0, -0.6));