Apache Solr open-source search software
LUCENE-6597: Geo3D's GeoCircle now supports a world-globe diameter.
David Wayne Smiley94235d3e0972
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txtindex 182cf748495..ffc9f65ff04 100644--- a/lucene/CHANGES.txt+++ b/lucene/CHANGES.txt@@ -164,6 +164,9 @@ Bug fixes* LUCENE-6588: Fix how ToChildBlockJoinQuery deals with acceptDocs.(Christoph Kaser via Adrien Grand)+* LUCENE-6597: Geo3D's GeoCircle now supports a world-globe diameter.+ (Karl Wright via David Smiley)+Changes in Runtime Behavior* LUCENE-6501: The subreader structure in ParallelCompositeReaderdiff --git a/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoCircle.java b/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoCircle.javaindex e4d764a9784..fbfc1c34ad9 100755--- a/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoCircle.java+++ b/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoCircle.java@@ -37,7 +37,6 @@ public class GeoCircle extends GeoBaseExtendedShape implements GeoDistanceShape,throw new IllegalArgumentException("Longitude out of bounds");if (cutoffAngle <= 0.0 || cutoffAngle > Math.PI)throw new IllegalArgumentException("Cutoff angle out of bounds");- final double cosAngle = Math.cos(cutoffAngle);this.center = new GeoPoint(planetModel, lat, lon);// In an ellipsoidal world, cutoff distances make no sense, unfortunately. Only membership// can be used to make in/out determination.@@ -62,16 +61,17 @@ public class GeoCircle extends GeoBaseExtendedShape implements GeoDistanceShape,}final GeoPoint upperPoint = new GeoPoint(planetModel, upperLat, upperLon);final GeoPoint lowerPoint = new GeoPoint(planetModel, lowerLat, lowerLon);- // Construct normal plane- final Plane normalPlane = new Plane(upperPoint, center);- // Construct a sided plane that goes through the two points and whose normal is in the normalPlane.- this.circlePlane = SidedPlane.constructNormalizedPerpendicularSidedPlane(center, normalPlane, upperPoint, lowerPoint);- if (circlePlane == null)- throw new RuntimeException("Couldn't construct circle plane. Cutoff angle = "+cutoffAngle+"; upperPoint = "+upperPoint+"; lowerPoint = "+lowerPoint);- // Compute a point on the circle boundary.- if (cutoffAngle == Math.PI)+ if (Math.abs(cutoffAngle - Math.PI) < Vector.MINIMUM_RESOLUTION) {+ // Circle is the whole world+ this.circlePlane = null;this.edgePoints = new GeoPoint[0];- else {+ } else {+ // Construct normal plane+ final Plane normalPlane = new Plane(upperPoint, center);+ // Construct a sided plane that goes through the two points and whose normal is in the normalPlane.+ this.circlePlane = SidedPlane.constructNormalizedPerpendicularSidedPlane(center, normalPlane, upperPoint, lowerPoint);+ if (circlePlane == null)+ throw new RuntimeException("Couldn't construct circle plane. Cutoff angle = "+cutoffAngle+"; upperPoint = "+upperPoint+"; lowerPoint = "+lowerPoint);this.edgePoints = new GeoPoint[]{upperPoint};}}@@ -194,12 +194,18 @@ public class GeoCircle extends GeoBaseExtendedShape implements GeoDistanceShape,@Overridepublic boolean isWithin(final Vector point) {+ if (circlePlane == null) {+ return true;+ }// Fastest way of determining membershipreturn circlePlane.isWithin(point);}@Overridepublic boolean isWithin(final double x, final double y, final double z) {+ if (circlePlane == null) {+ return true;+ }// Fastest way of determining membershipreturn circlePlane.isWithin(x, y, z);}@@ -211,6 +217,9 @@ public class GeoCircle extends GeoBaseExtendedShape implements GeoDistanceShape,@Overridepublic boolean intersects(final Plane p, final GeoPoint[] notablePoints, final Membership... bounds) {+ if (circlePlane == null) {+ return false;+ }return circlePlane.intersects(planetModel, p, notablePoints, circlePoints, bounds);}@@ -226,6 +235,11 @@ public class GeoCircle extends GeoBaseExtendedShape implements GeoDistanceShape,@Overridepublic Bounds getBounds(Bounds bounds) {bounds = super.getBounds(bounds);+ if (circlePlane == null) {+ // Entire world+ bounds.noTopLatitudeBound().noBottomLatitudeBound().noLongitudeBound();+ return bounds;+ }bounds.addPoint(center);circlePlane.recordBounds(planetModel, bounds);return bounds;diff --git a/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/Geo3dShapeRectRelationTestCase.java b/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/Geo3dShapeRectRelationTestCase.javaindex 8ba34a80945..f4996bc30d9 100644--- a/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/Geo3dShapeRectRelationTestCase.java+++ b/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/Geo3dShapeRectRelationTestCase.java@@ -108,19 +108,11 @@ public abstract class Geo3dShapeRectRelationTestCase extends RandomizedShapeTest@Overrideprotected Geo3dShape generateRandomShape(Point nearP) {- while (true) {- final int circleRadius = random().nextInt(179) + 1;//no 0-radius- final Point point = nearP;- try {- final GeoShape shape = new GeoCircle(planetModel, point.getY() * DEGREES_TO_RADIANS, point.getX() * DEGREES_TO_RADIANS,- circleRadius * DEGREES_TO_RADIANS);- return new Geo3dShape(planetModel, shape, ctx);- } catch (IllegalArgumentException e) {- // This is what happens when we create a shape that is invalid. Although it is conceivable that there are cases where- // the exception is thrown incorrectly, we aren't going to be able to do that in this random test.- continue;- }- }+ final int circleRadius = 180 - random().nextInt(180);//no 0-radius+ final Point point = nearP;+ final GeoShape shape = new GeoCircle(planetModel, point.getY() * DEGREES_TO_RADIANS, point.getX() * DEGREES_TO_RADIANS,+ circleRadius * DEGREES_TO_RADIANS);+ return new Geo3dShape(planetModel, shape, ctx);}@Overridediff --git a/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/geo3d/GeoCircleTest.java b/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/geo3d/GeoCircleTest.javaindex 11e1ad1c735..1f890e5dfa7 100755--- a/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/geo3d/GeoCircleTest.java+++ b/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/geo3d/GeoCircleTest.java@@ -45,6 +45,29 @@ public class GeoCircleTest {assertEquals(0.049979, c.computeNormalDistance(gp), 0.000001);}+ @Test+ public void testCircleFullWorld() {+ GeoCircle c;+ GeoPoint gp;+ c = new GeoCircle(PlanetModel.SPHERE, 0.0, -0.5, Math.PI);+ gp = new GeoPoint(PlanetModel.SPHERE, 0.0, 0.0);+ assertTrue(c.isWithin(gp));+ gp = new GeoPoint(PlanetModel.SPHERE, 0.0, -0.5);+ assertTrue(c.isWithin(gp));+ gp = new GeoPoint(PlanetModel.SPHERE, 0.0, -0.55);+ assertTrue(c.isWithin(gp));+ gp = new GeoPoint(PlanetModel.SPHERE, 0.0, -0.45);+ assertTrue(c.isWithin(gp));+ gp = new GeoPoint(PlanetModel.SPHERE, Math.PI * 0.5, 0.0);+ assertTrue(c.isWithin(gp));+ gp = new GeoPoint(PlanetModel.SPHERE, 0.0, Math.PI);+ assertTrue(c.isWithin(gp));+ Bounds b = c.getBounds(null);+ assertTrue(b.checkNoLongitudeBound());+ assertTrue(b.checkNoTopLatitudeBound());+ assertTrue(b.checkNoBottomLatitudeBound());+ }+@Testpublic void testCirclePointWithin() {GeoCircle c;