You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ds...@apache.org on 2015/05/12 06:21:39 UTC
svn commit: r1678859 - in /lucene/dev/trunk/lucene/spatial/src:
java/org/apache/lucene/spatial/spatial4j/geo3d/
test/org/apache/lucene/spatial/spatial4j/
Author: dsmiley
Date: Tue May 12 04:21:39 2015
New Revision: 1678859
URL: http://svn.apache.org/r1678859
Log:
LUCENE-6475: Fix Geo3d bug RE minimum error resolution
Modified:
lucene/dev/trunk/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/Plane.java
lucene/dev/trunk/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/Vector.java
lucene/dev/trunk/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/Geo3dShapeRectRelationTest.java
lucene/dev/trunk/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/RectIntersectionTestHelper.java
Modified: lucene/dev/trunk/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/Plane.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/Plane.java?rev=1678859&r1=1678858&r2=1678859&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/Plane.java (original)
+++ lucene/dev/trunk/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/Plane.java Tue May 12 04:21:39 2015
@@ -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 zero
if (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;
Modified: lucene/dev/trunk/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/Vector.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/Vector.java?rev=1678859&r1=1678858&r2=1678859&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/Vector.java (original)
+++ lucene/dev/trunk/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/Vector.java Tue May 12 04:21:39 2015
@@ -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;
Modified: lucene/dev/trunk/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/Geo3dShapeRectRelationTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/Geo3dShapeRectRelationTest.java?rev=1678859&r1=1678858&r2=1678859&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/Geo3dShapeRectRelationTest.java (original)
+++ lucene/dev/trunk/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/Geo3dShapeRectRelationTest.java Tue May 12 04:21:39 2015
@@ -25,6 +25,7 @@ import com.carrotsearch.randomizedtestin
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
}
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
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());
+
+ }
}
Modified: lucene/dev/trunk/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/RectIntersectionTestHelper.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/RectIntersectionTestHelper.java?rev=1678859&r1=1678858&r2=1678859&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/RectIntersectionTestHelper.java (original)
+++ lucene/dev/trunk/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/RectIntersectionTestHelper.java Tue May 12 04:21:39 2015
@@ -111,7 +111,7 @@ public abstract class RectIntersectionTe
SpatialRelation 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",