mirror of https://github.com/apache/lucene.git
LUCENE-6475: Fix Geo3d bug RE minimum error resolution
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1678859 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
e50f4d94c7
commit
29490437c5
|
@ -808,11 +808,6 @@ public class Plane extends Vector {
|
||||||
|
|
||||||
//System.err.println("E = " + E + " F = " + F + " G = " + G + " H = "+ H + " I = " + I + " J = " + J);
|
//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
|
// 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) {
|
if (Math.abs(J) >= MINIMUM_RESOLUTION && J > 0.0) {
|
||||||
// The derivative of the curve above is:
|
// The derivative of the curve above is:
|
||||||
|
@ -867,7 +862,7 @@ public class Plane extends Vector {
|
||||||
double sqrtClause = b * b - 4.0 * a * c;
|
double sqrtClause = b * b - 4.0 * a * c;
|
||||||
//System.out.println("sqrtClause="+sqrtClause);
|
//System.out.println("sqrtClause="+sqrtClause);
|
||||||
|
|
||||||
if (Math.abs(sqrtClause) < MINIMUM_RESOLUTION_SQUARED) {
|
if (Math.abs(sqrtClause) < MINIMUM_RESOLUTION_CUBED) {
|
||||||
//System.err.println(" One solution");
|
//System.err.println(" One solution");
|
||||||
double y0 = -b / (2.0 * a);
|
double y0 = -b / (2.0 * a);
|
||||||
double x0 = (-2.0 * J - I * y0) / H;
|
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);
|
//System.out.println("a="+a+" b="+b+" c="+c);
|
||||||
double sqrtClause = b * b - 4.0 * a * c;
|
double sqrtClause = b * b - 4.0 * a * c;
|
||||||
//System.out.println("sqrtClause="+sqrtClause);
|
//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);
|
//System.err.println(" One solution; sqrt clause was "+sqrtClause);
|
||||||
double x0 = -b / (2.0 * a);
|
double x0 = -b / (2.0 * a);
|
||||||
double y0 = (-2.0 * J - H * x0) / I;
|
double y0 = (-2.0 * J - H * x0) / I;
|
||||||
|
|
|
@ -34,6 +34,8 @@ public class Vector {
|
||||||
*/
|
*/
|
||||||
public static final double MINIMUM_RESOLUTION_SQUARED = MINIMUM_RESOLUTION * MINIMUM_RESOLUTION;
|
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 x;
|
||||||
public final double y;
|
public final double y;
|
||||||
public final double z;
|
public final double z;
|
||||||
|
|
|
@ -25,6 +25,7 @@ import com.carrotsearch.randomizedtesting.RandomizedContext;
|
||||||
import com.spatial4j.core.context.SpatialContext;
|
import com.spatial4j.core.context.SpatialContext;
|
||||||
import com.spatial4j.core.distance.DistanceUtils;
|
import com.spatial4j.core.distance.DistanceUtils;
|
||||||
import com.spatial4j.core.shape.Point;
|
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.Bounds;
|
||||||
import org.apache.lucene.spatial.spatial4j.geo3d.GeoArea;
|
import org.apache.lucene.spatial.spatial4j.geo3d.GeoArea;
|
||||||
import org.apache.lucene.spatial.spatial4j.geo3d.GeoBBox;
|
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;
|
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) {
|
protected static GeoBBox getBoundingBox(final GeoShape path) {
|
||||||
Bounds bounds = path.getBounds(null);
|
Bounds bounds = path.getBounds(null);
|
||||||
|
@ -260,4 +239,37 @@ public class Geo3dShapeRectRelationTest extends RandomizedShapeTestCase {
|
||||||
geoPoint.y * DistanceUtils.RADIANS_TO_DEGREES);
|
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());
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -111,7 +111,7 @@ public abstract class RectIntersectionTestHelper<S extends Shape> extends Random
|
||||||
|
|
||||||
SpatialRelation ic = s.relate(r);
|
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) {
|
if (ic != DISJOINT) {
|
||||||
assertTrue("if not disjoint then the shape's bbox shouldn't be disjoint",
|
assertTrue("if not disjoint then the shape's bbox shouldn't be disjoint",
|
||||||
|
|
Loading…
Reference in New Issue