Apache Lucene open-source search software
LUCENE-8299: Geo3D wrapper uses new polygon method factory that gives better support for polygons with many points (>100)
Ignacio Veraaf7dfb182ebc
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txtindex 9eecc4206b0..8f307fe45ab 100644--- a/lucene/CHANGES.txt+++ b/lucene/CHANGES.txt@@ -267,6 +267,9 @@ Other* LUCENE-8301: Update randomizedtesting to 2.6.0. (Dawid Weiss)+* LUCENE-8299: Geo3D wrapper uses new polygon method factory that gives better+ support for polygons with many points (>100). (Ignacio vera)+* LUCENE-8261: InterpolatedProperties.interpolate and recursive propertyreferences. (Steve Rowe, Dawid Weiss)diff --git a/lucene/spatial-extras/src/java/org/apache/lucene/spatial/spatial4j/Geo3dShapeFactory.java b/lucene/spatial-extras/src/java/org/apache/lucene/spatial/spatial4j/Geo3dShapeFactory.javaindex a6147dfdf41..ccbd6df2e43 100644--- a/lucene/spatial-extras/src/java/org/apache/lucene/spatial/spatial4j/Geo3dShapeFactory.java+++ b/lucene/spatial-extras/src/java/org/apache/lucene/spatial/spatial4j/Geo3dShapeFactory.java@@ -311,7 +311,7 @@ public class Geo3dShapeFactory implements S2ShapeFactory {*/private class Geo3dPolygonBuilder extends Geo3dPointBuilder<PolygonBuilder> implements PolygonBuilder {- List<GeoPolygon> polyHoles;+ List<GeoPolygonFactory.PolygonDescription> polyHoles = new ArrayList<>();@Overridepublic HoleBuilder hole() {@@ -321,10 +321,7 @@ public class Geo3dShapeFactory implements S2ShapeFactory {class Geo3dHoleBuilder extends Geo3dPointBuilder<PolygonBuilder.HoleBuilder> implements PolygonBuilder.HoleBuilder {@Overridepublic PolygonBuilder endHole() {- if (polyHoles == null) {- polyHoles = new ArrayList<>();- }- polyHoles.add(GeoPolygonFactory.makeGeoPolygon(planetModel, points));+ polyHoles.add(new GeoPolygonFactory.PolygonDescription(points));return Geo3dPolygonBuilder.this;}}@@ -332,7 +329,8 @@ public class Geo3dShapeFactory implements S2ShapeFactory {@SuppressWarnings("unchecked")@Overridepublic Shape build() {- GeoPolygon polygon = GeoPolygonFactory.makeGeoPolygon(planetModel, points, polyHoles);+ GeoPolygonFactory.PolygonDescription description = new GeoPolygonFactory.PolygonDescription(points, polyHoles);+ GeoPolygon polygon = GeoPolygonFactory.makeGeoPolygon(planetModel, description);return new Geo3dShape<>(polygon, context);}diff --git a/lucene/spatial-extras/src/test/org/apache/lucene/spatial/spatial4j/Geo3dRptTest.java b/lucene/spatial-extras/src/test/org/apache/lucene/spatial/spatial4j/Geo3dRptTest.javaindex d3b144f154c..eb6ed5bc69f 100644--- a/lucene/spatial-extras/src/test/org/apache/lucene/spatial/spatial4j/Geo3dRptTest.java+++ b/lucene/spatial-extras/src/test/org/apache/lucene/spatial/spatial4j/Geo3dRptTest.java@@ -18,9 +18,11 @@ package org.apache.lucene.spatial.spatial4j;import java.io.IOException;import java.util.ArrayList;+import java.util.Iterator;import java.util.List;import com.carrotsearch.randomizedtesting.annotations.Repeat;+import org.apache.lucene.spatial.SpatialTestData;import org.apache.lucene.spatial.composite.CompositeSpatialStrategy;import org.apache.lucene.spatial.prefix.RandomSpatialOpStrategyTestCase;import org.apache.lucene.spatial.prefix.RecursivePrefixTreeStrategy;@@ -96,7 +98,7 @@ public class Geo3dRptTest extends RandomSpatialOpStrategyTestCase {points.add(new GeoPoint(planetModel, 14 * DEGREES_TO_RADIANS, -180 * DEGREES_TO_RADIANS));points.add(new GeoPoint(planetModel, -15 * DEGREES_TO_RADIANS, 153 * DEGREES_TO_RADIANS));- final Shape triangle = new Geo3dShape(GeoPolygonFactory.makeGeoPolygon(planetModel, points),ctx);+ final Shape triangle = new Geo3dShape<>(GeoPolygonFactory.makeGeoPolygon(planetModel, points),ctx);final Rectangle rect = ctx.makeRectangle(-49, -45, 73, 86);testOperation(rect,SpatialOperation.Intersects,triangle, false);}@@ -116,7 +118,7 @@ public class Geo3dRptTest extends RandomSpatialOpStrategyTestCase {new GeoPoint(planetModel, 54.0 * DEGREES_TO_RADIANS, 165.0 * DEGREES_TO_RADIANS),new GeoPoint(planetModel, -90.0 * DEGREES_TO_RADIANS, 0.0)};final GeoPath path = GeoPathFactory.makeGeoPath(planetModel, 29 * DEGREES_TO_RADIANS, pathPoints);- final Shape shape = new Geo3dShape(path,ctx);+ final Shape shape = new Geo3dShape<>(path,ctx);final Rectangle rect = ctx.makeRectangle(131, 143, 39, 54);testOperation(rect,SpatialOperation.Intersects,shape,true);}@@ -146,6 +148,23 @@ public class Geo3dRptTest extends RandomSpatialOpStrategyTestCase {return new Geo3dShape<>(areaShape, ctx);}+ @Test+ public void testOperationsFromFile() throws IOException {+ setupStrategy();+ final Iterator<SpatialTestData> indexedSpatialData = getSampleData( "states-poly.txt");+ final List<Shape> indexedShapes = new ArrayList<>();+ while(indexedSpatialData.hasNext()) {+ indexedShapes.add(indexedSpatialData.next().shape);+ }+ final Iterator<SpatialTestData> querySpatialData = getSampleData( "states-bbox.txt");+ final List<Shape> queryShapes = new ArrayList<>();+ while(querySpatialData.hasNext()) {+ queryShapes.add(querySpatialData.next().shape);+ queryShapes.add(randomQueryShape());+ }+ testOperation(SpatialOperation.Intersects, indexedShapes, queryShapes, random().nextBoolean());+ }+//TODO move to a new test class?@Testpublic void testWKT() throws Exception {