Apache Lucene open-source search software
LUCENE-7934: Add planet model interface.
Karl Wright94b695e672b8
diff --git a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/Geo3DUtil.java b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/Geo3DUtil.javaindex 6d7321025f8..88537f47943 100644--- a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/Geo3DUtil.java+++ b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/Geo3DUtil.java@@ -134,12 +134,12 @@ class Geo3DUtil {final GeoPolygon component = fromPolygon(polygons[0]);if (component == null) {// Polygon is degenerate- shape = new GeoCompositePolygon();+ shape = new GeoCompositePolygon(PlanetModel.WGS84);} else {shape = component;}} else {- final GeoCompositePolygon poly = new GeoCompositePolygon();+ final GeoCompositePolygon poly = new GeoCompositePolygon(PlanetModel.WGS84);for (final Polygon p : polygons) {final GeoPolygon component = fromPolygon(p);if (component != null) {diff --git a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/BasePlanetObject.java b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/BasePlanetObject.javaindex 5cd5acca8ae..13072fe77d0 100644--- a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/BasePlanetObject.java+++ b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/BasePlanetObject.java@@ -22,7 +22,7 @@ package org.apache.lucene.spatial3d.geom;** @lucene.internal*/-public abstract class BasePlanetObject {+public abstract class BasePlanetObject implements PlanetObject {/** This is the planet model embedded in all objects derived from this* class. */@@ -35,7 +35,7 @@ public abstract class BasePlanetObject {this.planetModel = planetModel;}- /** Returns the {@link PlanetModel} provided when this shape was created. */+ @Overridepublic PlanetModel getPlanetModel() {return planetModel;}diff --git a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoBaseAreaShape.java b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoBaseAreaShape.javaindex 5bd8ab3e242..a2b2fa1b0c1 100644--- a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoBaseAreaShape.java+++ b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoBaseAreaShape.java@@ -94,6 +94,9 @@ abstract class GeoBaseAreaShape extends GeoBaseMembershipShape implements GeoAre@Overridepublic int getRelationship(GeoShape geoShape) {+ if (!geoShape.getPlanetModel().equals(planetModel)) {+ throw new IllegalArgumentException("Cannot relate shapes with different planet models.");+ }final int insideGeoAreaShape = isShapeInsideGeoAreaShape(geoShape);if (insideGeoAreaShape == SOME_INSIDE) {return GeoArea.OVERLAPS;diff --git a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoBaseCompositeAreaShape.java b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoBaseCompositeAreaShape.javaindex fea4eab501e..164d45837a6 100644--- a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoBaseCompositeAreaShape.java+++ b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoBaseCompositeAreaShape.java@@ -35,7 +35,8 @@ abstract class GeoBaseCompositeAreaShape<T extends GeoAreaShape> extends GeoBase/*** Constructor.*/- public GeoBaseCompositeAreaShape() {+ public GeoBaseCompositeAreaShape(PlanetModel planetModel) {+ super(planetModel);}@Override@@ -50,6 +51,9 @@ abstract class GeoBaseCompositeAreaShape<T extends GeoAreaShape> extends GeoBase@Overridepublic int getRelationship(GeoShape geoShape) {+ if (!geoShape.getPlanetModel().equals(planetModel)) {+ throw new IllegalArgumentException("Cannot relate shapes with different planet models.");+ }final int insideGeoAreaShape = isShapeInsideGeoAreaShape(geoShape);if (insideGeoAreaShape == SOME_INSIDE) {return GeoArea.OVERLAPS;diff --git a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoBaseCompositeMembershipShape.java b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoBaseCompositeMembershipShape.javaindex 0ebc8e2a29f..0f19a7c870c 100644--- a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoBaseCompositeMembershipShape.java+++ b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoBaseCompositeMembershipShape.java@@ -29,7 +29,8 @@ abstract class GeoBaseCompositeMembershipShape<T extends GeoMembershipShape>/*** Constructor.*/- GeoBaseCompositeMembershipShape() {+ GeoBaseCompositeMembershipShape(PlanetModel planetModel) {+ super(planetModel);}@Overridediff --git a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoBaseCompositeShape.java b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoBaseCompositeShape.javaindex 5fe8af154ee..32f6e9ad1c2 100644--- a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoBaseCompositeShape.java+++ b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoBaseCompositeShape.java@@ -27,7 +27,7 @@ import java.util.List;* @param <T> is the type of GeoShapes of the composite.* @lucene.experimental*/-public abstract class GeoBaseCompositeShape<T extends GeoShape> implements GeoShape {+public abstract class GeoBaseCompositeShape<T extends GeoShape> extends BasePlanetObject implements GeoShape {/*** Shape's container@@ -37,7 +37,8 @@ public abstract class GeoBaseCompositeShape<T extends GeoShape> implements GeoSh/*** Constructor.*/- public GeoBaseCompositeShape() {+ public GeoBaseCompositeShape(PlanetModel planetModel) {+ super(planetModel);}/**@@ -46,6 +47,9 @@ public abstract class GeoBaseCompositeShape<T extends GeoShape> implements GeoSh* @param shape is the shape to add.*/public void addShape(final T shape) {+ if (!shape.getPlanetModel().equals(planetModel)) {+ throw new IllegalArgumentException("Cannot add a shape into a composite with different planet models.");+ }shapes.add(shape);}@@ -108,7 +112,7 @@ public abstract class GeoBaseCompositeShape<T extends GeoShape> implements GeoSh@Overridepublic int hashCode() {- return shapes.hashCode();+ return super.hashCode() + shapes.hashCode();}@Override@@ -116,6 +120,6 @@ public abstract class GeoBaseCompositeShape<T extends GeoShape> implements GeoShif (!(o instanceof GeoBaseCompositeShape<?>))return false;GeoBaseCompositeShape<?> other = (GeoBaseCompositeShape<?>) o;- return shapes.equals(other.shapes);+ return super.equals(other) && shapes.equals(other.shapes);}}diff --git a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoCompositeAreaShape.java b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoCompositeAreaShape.javaindex 695b3ea1f96..085dbb3bf84 100644--- a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoCompositeAreaShape.java+++ b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoCompositeAreaShape.java@@ -27,7 +27,15 @@ public class GeoCompositeAreaShape extends GeoBaseCompositeAreaShape<GeoAreaShap/*** Constructor.*/- public GeoCompositeAreaShape() {+ public GeoCompositeAreaShape(PlanetModel planetModel) {+ super(planetModel);+ }++ @Override+ public boolean equals(Object o) {+ if (!(o instanceof GeoCompositeAreaShape))+ return false;+ return super.equals(o);}@Overridediff --git a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoCompositeMembershipShape.java b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoCompositeMembershipShape.javaindex 7aa4007091b..55ce75a5a90 100755--- a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoCompositeMembershipShape.java+++ b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoCompositeMembershipShape.java@@ -26,7 +26,15 @@ public class GeoCompositeMembershipShape extends GeoBaseCompositeMembershipShape/*** Constructor.*/- public GeoCompositeMembershipShape() {+ public GeoCompositeMembershipShape(PlanetModel planetModel) {+ super(planetModel);+ }++ @Override+ public boolean equals(Object o) {+ if (!(o instanceof GeoCompositeMembershipShape))+ return false;+ return super.equals(o);}@Overridediff --git a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoCompositePolygon.java b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoCompositePolygon.javaindex b16d76d7960..3e62177635b 100644--- a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoCompositePolygon.java+++ b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoCompositePolygon.java@@ -25,7 +25,15 @@ public class GeoCompositePolygon extends GeoBaseCompositeAreaShape<GeoPolygon> i/*** Constructor.*/- public GeoCompositePolygon() {+ public GeoCompositePolygon(PlanetModel planetModel) {+ super(planetModel);+ }++ @Override+ public boolean equals(Object o) {+ if (!(o instanceof GeoCompositePolygon))+ return false;+ return super.equals(o);}@Overridediff --git a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoDegeneratePoint.java b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoDegeneratePoint.javaindex 2860757200b..93d47088ff9 100644--- a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoDegeneratePoint.java+++ b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoDegeneratePoint.java@@ -39,6 +39,11 @@ class GeoDegeneratePoint extends GeoPoint implements GeoBBox, GeoCircle {this.edgePoints = new GeoPoint[]{this};}+ @Override+ public PlanetModel getPlanetModel() {+ return planetModel;+ }+@Overridepublic GeoBBox expand(final double angle) {final double newTopLat = latitude + angle;diff --git a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoPolygonFactory.java b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoPolygonFactory.javaindex 7cabe3217e7..f5997167198 100755--- a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoPolygonFactory.java+++ b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoPolygonFactory.java@@ -336,19 +336,19 @@ public class GeoPolygonFactory {final SidedPlane initialPlane = new SidedPlane(testPoint, filteredPointList.get(0), filteredPointList.get(1));// We don't know if this is the correct siding choice. We will only know as we build the complex polygon.// So we need to be prepared to try both possibilities.- GeoCompositePolygon rval = new GeoCompositePolygon();+ GeoCompositePolygon rval = new GeoCompositePolygon(planetModel);MutableBoolean seenConcave = new MutableBoolean();if (buildPolygonShape(rval, seenConcave, planetModel, filteredPointList, new BitSet(), 0, 1, initialPlane, holes, testPoint) == false) {// The testPoint was within the shape. Was that intended?if (testPointInside) {// Yes: build it for real- rval = new GeoCompositePolygon();+ rval = new GeoCompositePolygon(planetModel);seenConcave = new MutableBoolean();buildPolygonShape(rval, seenConcave, planetModel, filteredPointList, new BitSet(), 0, 1, initialPlane, holes, null);return rval;}// No: do the complement and return that.- rval = new GeoCompositePolygon();+ rval = new GeoCompositePolygon(planetModel);seenConcave = new MutableBoolean();buildPolygonShape(rval, seenConcave, planetModel, filteredPointList, new BitSet(), 0, 1, new SidedPlane(initialPlane), holes, null);return rval;@@ -359,7 +359,7 @@ public class GeoPolygonFactory {return rval;}// No: return the complement- rval = new GeoCompositePolygon();+ rval = new GeoCompositePolygon(planetModel);seenConcave = new MutableBoolean();buildPolygonShape(rval, seenConcave, planetModel, filteredPointList, new BitSet(), 0, 1, new SidedPlane(initialPlane), holes, null);return rval;diff --git a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoShape.java b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoShape.javaindex a2d3947585e..98283cdac70 100755--- a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoShape.java+++ b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoShape.java@@ -23,7 +23,7 @@ package org.apache.lucene.spatial3d.geom;** @lucene.experimental*/-public interface GeoShape extends Membership {+public interface GeoShape extends Membership, PlanetObject {/*** Return a sample point that is on the outside edge/boundary of the shape.diff --git a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/PlanetObject.java b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/PlanetObject.javanew file mode 100644index 00000000000..05ed7b15be9--- /dev/null+++ b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/PlanetObject.java@@ -0,0 +1,29 @@+/*+ * Licensed to the Apache Software Foundation (ASF) under one or more+ * contributor license agreements. See the NOTICE file distributed with+ * this work for additional information regarding copyright ownership.+ * The ASF licenses this file to You under the Apache License, Version 2.0+ * (the "License"); you may not use this file except in compliance with+ * the License. You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++package org.apache.lucene.spatial3d.geom;++/**+ * Relates all Geo3d shape with a specific {@link PlanetModel}.+ *+ * @lucene.experimental+ */+public interface PlanetObject {++ /** Returns the {@link PlanetModel} provided when this shape was created. */+ PlanetModel getPlanetModel();+}diff --git a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/XYZSolid.java b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/XYZSolid.javaindex 9298079b7b6..cceb11083bf 100644--- a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/XYZSolid.java+++ b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/XYZSolid.java@@ -21,6 +21,6 @@ package org.apache.lucene.spatial3d.geom;** @lucene.internal*/-public interface XYZSolid extends GeoArea {+public interface XYZSolid extends GeoArea, PlanetObject {}diff --git a/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/CompositeGeoPolygonRelationshipsTest.java b/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/CompositeGeoPolygonRelationshipsTest.javaindex ffcb5e388d3..1d5ffbe0ddc 100644--- a/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/CompositeGeoPolygonRelationshipsTest.java+++ b/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/CompositeGeoPolygonRelationshipsTest.java@@ -833,7 +833,7 @@ public class CompositeGeoPolygonRelationshipsTest {points2.add(point8);GeoPolygon p1 = GeoPolygonFactory.makeGeoPolygon(PlanetModel.SPHERE, points1);GeoPolygon p2 = GeoPolygonFactory.makeGeoPolygon(PlanetModel.SPHERE, points2);- GeoCompositeMembershipShape compositeMembershipShape = new GeoCompositeMembershipShape();+ GeoCompositeMembershipShape compositeMembershipShape = new GeoCompositeMembershipShape(PlanetModel.SPHERE);compositeMembershipShape.addShape(p1);compositeMembershipShape.addShape(p2);return compositeMembershipShape;diff --git a/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/Geo3DUtil.java b/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/Geo3DUtil.javaindex e9b7ebc7c2d..add46e43e57 100644--- a/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/Geo3DUtil.java+++ b/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/Geo3DUtil.java@@ -134,12 +134,12 @@ class Geo3DUtil {final GeoPolygon component = fromPolygon(polygons[0]);if (component == null) {// Polygon is degenerate- shape = new GeoCompositePolygon();+ shape = new GeoCompositePolygon(PlanetModel.WGS84);} else {shape = component;}} else {- final GeoCompositePolygon poly = new GeoCompositePolygon();+ final GeoCompositePolygon poly = new GeoCompositePolygon(PlanetModel.WGS84);for (final Polygon p : polygons) {final GeoPolygon component = fromPolygon(p);if (component != null) {diff --git a/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/GeoPolygonTest.java b/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/GeoPolygonTest.javaindex 3602e817aa0..00d789993ca 100755--- a/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/GeoPolygonTest.java+++ b/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/GeoPolygonTest.java@@ -441,7 +441,7 @@ public class GeoPolygonTest {PlanetModel pm = new PlanetModel(0.7563871189161702, 1.2436128810838298);// Build the polygon- GeoCompositeMembershipShape c = new GeoCompositeMembershipShape();+ GeoCompositeMembershipShape c = new GeoCompositeMembershipShape(pm);List<GeoPoint> points1 = new ArrayList<>();points1.add(new GeoPoint(pm, 0.014071770744627236, 0.011030818292803128));points1.add(new GeoPoint(pm, 0.006772117088906782, -0.0012531892445234592));@@ -500,7 +500,7 @@ shape:*/PlanetModel pm = new PlanetModel(0.8568069516722363, 1.1431930483277637);// Build the polygon- GeoCompositeMembershipShape c = new GeoCompositeMembershipShape();+ GeoCompositeMembershipShape c = new GeoCompositeMembershipShape(pm);List<GeoPoint> points1 = new ArrayList<>();points1.add(new GeoPoint(pm, 1.1577814487635816, 1.6283601832010004));points1.add(new GeoPoint(pm, 0.6664570999069251, 2.0855825542851574));@@ -626,7 +626,7 @@ shape:points.add(p1);final BitSet internal = new BitSet();- final GeoCompositePolygon rval = new GeoCompositePolygon();+ final GeoCompositePolygon rval = new GeoCompositePolygon(PlanetModel.WGS84);final GeoPolygonFactory.MutableBoolean mutableBoolean = new GeoPolygonFactory.MutableBoolean();boolean result = GeoPolygonFactory.buildPolygonShape(rval, mutableBoolean, PlanetModel.WGS84, points, internal, 0, 1,diff --git a/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/RandomGeoShapeGenerator.java b/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/RandomGeoShapeGenerator.javaindex f8b662964e1..ca7aecdcc0a 100644--- a/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/RandomGeoShapeGenerator.java+++ b/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/RandomGeoShapeGenerator.java@@ -380,7 +380,7 @@ public class RandomGeoShapeGenerator extends LuceneTestCase {while (iterations < MAX_SHAPE_ITERATIONS) {iterations++;int numberShapes = random().nextInt(3) + 2;- GeoCompositeAreaShape collection = new GeoCompositeAreaShape();+ GeoCompositeAreaShape collection = new GeoCompositeAreaShape(planetModel);for(int i=0; i<numberShapes;i++){GeoPolygon member = convexPolygon(planetModel, constraints);if (member != null){diff --git a/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/SimpleGeoPolygonRelationshipsTest.java b/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/SimpleGeoPolygonRelationshipsTest.javaindex 59a52b4ca91..973483ef3d3 100644--- a/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/SimpleGeoPolygonRelationshipsTest.java+++ b/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/SimpleGeoPolygonRelationshipsTest.java@@ -829,7 +829,7 @@ public class SimpleGeoPolygonRelationshipsTest {points2.add(point7);points2.add(point8);GeoPolygon pol2 = GeoPolygonFactory.makeGeoPolygon(PlanetModel.SPHERE, points2);- GeoCompositeMembershipShape composite = new GeoCompositeMembershipShape();+ GeoCompositeMembershipShape composite = new GeoCompositeMembershipShape(PlanetModel.SPHERE);composite.addShape(pol1);composite.addShape(pol2);return composite;