Apache Lucene open-source search software
LUCENE-6475: Fix Geo3d bug RE minimum error resolution
David Wayne Smiley29490437c5f9
diff --git a/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/Plane.java b/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/Plane.javaindex 1481e2300c5..b25e5c9fd55 100755--- a/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/Plane.java+++ b/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/Plane.java@@ -808,11 +808,6 @@ public class Plane extends Vector {//System.err.println("E = " + E + " F = " + F + " G = " + G + " H = "+ H + " I = " + I + " J = " + J);- double trialX = 2.0;- double trialY = 2.0;-- //System.err.println("Trial point evaluates to: "+(E*trialX*trialX + F*trialY*trialY + G*trialX*trialY + H*trialX + I*trialY + J));-// Check if the origin is within, by substituting x = 0, y = 0 and seeing if less than zeroif (Math.abs(J) >= MINIMUM_RESOLUTION && J > 0.0) {// The derivative of the curve above is:@@ -867,7 +862,7 @@ public class Plane extends Vector {double sqrtClause = b * b - 4.0 * a * c;//System.out.println("sqrtClause="+sqrtClause);- if (Math.abs(sqrtClause) < MINIMUM_RESOLUTION_SQUARED) {+ if (Math.abs(sqrtClause) < MINIMUM_RESOLUTION_CUBED) {//System.err.println(" One solution");double y0 = -b / (2.0 * a);double x0 = (-2.0 * J - I * y0) / H;@@ -918,7 +913,7 @@ public class Plane extends Vector {//System.out.println("a="+a+" b="+b+" c="+c);double sqrtClause = b * b - 4.0 * a * c;//System.out.println("sqrtClause="+sqrtClause);- if (Math.abs(sqrtClause) < MINIMUM_RESOLUTION_SQUARED) {+ if (Math.abs(sqrtClause) < MINIMUM_RESOLUTION_CUBED) {//System.err.println(" One solution; sqrt clause was "+sqrtClause);double x0 = -b / (2.0 * a);double y0 = (-2.0 * J - H * x0) / I;diff --git a/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/Vector.java b/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/Vector.javaindex 69fd2bdf10b..4ea58120ac9 100755--- a/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/Vector.java+++ b/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/Vector.java@@ -34,6 +34,8 @@ public class Vector {*/public static final double MINIMUM_RESOLUTION_SQUARED = MINIMUM_RESOLUTION * MINIMUM_RESOLUTION;+ public static final double MINIMUM_RESOLUTION_CUBED = MINIMUM_RESOLUTION_SQUARED * MINIMUM_RESOLUTION;+public final double x;public final double y;public final double z;diff --git a/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/Geo3dShapeRectRelationTest.java b/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/Geo3dShapeRectRelationTest.javaindex 5649cb48107..b67383b4247 100644--- a/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/Geo3dShapeRectRelationTest.java+++ b/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/Geo3dShapeRectRelationTest.java@@ -25,6 +25,7 @@ import com.carrotsearch.randomizedtesting.RandomizedContext;import com.spatial4j.core.context.SpatialContext;import com.spatial4j.core.distance.DistanceUtils;import com.spatial4j.core.shape.Point;+import com.spatial4j.core.shape.Rectangle;import org.apache.lucene.spatial.spatial4j.geo3d.Bounds;import org.apache.lucene.spatial.spatial4j.geo3d.GeoArea;import org.apache.lucene.spatial.spatial4j.geo3d.GeoBBox;@@ -52,28 +53,6 @@ public class Geo3dShapeRectRelationTest extends RandomizedShapeTestCase {}protected final static double RADIANS_PER_DEGREE = Math.PI/180.0;-- @Test- public void testFailure1() {- final GeoBBox rect = GeoBBoxFactory.makeGeoBBox(88 * RADIANS_PER_DEGREE, 30 * RADIANS_PER_DEGREE, -30 * RADIANS_PER_DEGREE, 62 * RADIANS_PER_DEGREE);- final List<GeoPoint> points = new ArrayList<GeoPoint>();- points.add(new GeoPoint(66.2465299717 * RADIANS_PER_DEGREE, -29.1786158537 * RADIANS_PER_DEGREE));- points.add(new GeoPoint(43.684447915 * RADIANS_PER_DEGREE, 46.2210986329 * RADIANS_PER_DEGREE));- points.add(new GeoPoint(30.4579218227 * RADIANS_PER_DEGREE, 14.5238410082 * RADIANS_PER_DEGREE));- final GeoShape path = GeoPolygonFactory.makeGeoPolygon(points,0);-- final GeoPoint point = new GeoPoint(34.2730264413182 * RADIANS_PER_DEGREE, 82.75500168892472 * RADIANS_PER_DEGREE);-- // Apparently the rectangle thinks the polygon is completely within it... "shape inside rectangle"- assertTrue(GeoArea.WITHIN == rect.getRelationship(path));-- // Point is within path? Apparently not...- assertFalse(path.isWithin(point));-- // If it is within the path, it must be within the rectangle, and similarly visa versa- assertFalse(rect.isWithin(point));-- }protected static GeoBBox getBoundingBox(final GeoShape path) {Bounds bounds = path.getBounds(null);@@ -260,4 +239,37 @@ public class Geo3dShapeRectRelationTest extends RandomizedShapeTestCase {geoPoint.y * DistanceUtils.RADIANS_TO_DEGREES);}+ @Test+ public void testFailure1() {+ final GeoBBox rect = GeoBBoxFactory.makeGeoBBox(88 * RADIANS_PER_DEGREE, 30 * RADIANS_PER_DEGREE, -30 * RADIANS_PER_DEGREE, 62 * RADIANS_PER_DEGREE);+ final List<GeoPoint> points = new ArrayList<GeoPoint>();+ points.add(new GeoPoint(66.2465299717 * RADIANS_PER_DEGREE, -29.1786158537 * RADIANS_PER_DEGREE));+ points.add(new GeoPoint(43.684447915 * RADIANS_PER_DEGREE, 46.2210986329 * RADIANS_PER_DEGREE));+ points.add(new GeoPoint(30.4579218227 * RADIANS_PER_DEGREE, 14.5238410082 * RADIANS_PER_DEGREE));+ final GeoShape path = GeoPolygonFactory.makeGeoPolygon(points,0);++ final GeoPoint point = new GeoPoint(34.2730264413182 * RADIANS_PER_DEGREE, 82.75500168892472 * RADIANS_PER_DEGREE);++ // Apparently the rectangle thinks the polygon is completely within it... "shape inside rectangle"+ assertTrue(GeoArea.WITHIN == rect.getRelationship(path));++ // Point is within path? Apparently not...+ assertFalse(path.isWithin(point));++ // If it is within the path, it must be within the rectangle, and similarly visa versa+ assertFalse(rect.isWithin(point));++ }++ @Test+ public void testFailure2_LUCENE6475() {+ GeoShape geo3dCircle = new GeoCircle(1.6282053147165243E-4 * RADIANS_PER_DEGREE,+ -70.1600629789353 * RADIANS_PER_DEGREE, 86 * RADIANS_PER_DEGREE);+ Geo3dShape geo3dShape = new Geo3dShape(geo3dCircle, ctx);+ Rectangle rect = ctx.makeRectangle(-118, -114, -2.0, 32.0);+ assertTrue(geo3dShape.relate(rect).intersects());+ // thus the bounding box must intersect too+ assertTrue(geo3dShape.getBoundingBox().relate(rect).intersects());++ }}diff --git a/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/RectIntersectionTestHelper.java b/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/RectIntersectionTestHelper.javaindex 32a78da7d8f..56e826b459f 100644--- a/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/RectIntersectionTestHelper.java+++ b/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/RectIntersectionTestHelper.java@@ -111,7 +111,7 @@ public abstract class RectIntersectionTestHelper<S extends Shape> extends RandomSpatialRelation ic = s.relate(r);- LogRule.log("S-R Rel: {}, Shape {}, Rectangle {}", ic, s, r);+ LogRule.log("S-R Rel: {}, Shape {}, Rectangle {} lap# {}", ic, s, r, laps);if (ic != DISJOINT) {assertTrue("if not disjoint then the shape's bbox shouldn't be disjoint",