You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by iv...@apache.org on 2020/12/16 11:08:44 UTC
[lucene-solr] branch master updated: LUCENE-9637: Removes some
unused code and replaces the Point implementation on ShapeField/ShapeQuery
random tests
This is an automated email from the ASF dual-hosted git repository.
ivera pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git
The following commit(s) were added to refs/heads/master by this push:
new 6f56a3c LUCENE-9637: Removes some unused code and replaces the Point implementation on ShapeField/ShapeQuery random tests
6f56a3c is described below
commit 6f56a3cd739511f01e2abddf7569089cac0bc302
Author: Ignacio Vera <iv...@apache.org>
AuthorDate: Wed Dec 16 12:08:23 2020 +0100
LUCENE-9637: Removes some unused code and replaces the Point implementation on ShapeField/ShapeQuery random tests
---
lucene/CHANGES.txt | 2 +
.../lucene/document/BaseLatLonShapeTestCase.java | 115 +++------------
.../apache/lucene/document/BaseShapeTestCase.java | 157 ++++++---------------
.../lucene/document/BaseXYShapeTestCase.java | 92 +++---------
.../document/TestLatLonLineShapeQueries.java | 10 +-
.../document/TestLatLonMultiLineShapeQueries.java | 18 ---
.../document/TestLatLonMultiPointShapeQueries.java | 25 +---
.../TestLatLonMultiPolygonShapeQueries.java | 59 +-------
.../document/TestLatLonPointShapeQueries.java | 21 +--
.../document/TestLatLonPolygonShapeQueries.java | 24 ----
.../apache/lucene/document/TestLatLonShape.java | 12 +-
.../lucene/document/TestXYLineShapeQueries.java | 10 +-
.../document/TestXYMultiLineShapeQueries.java | 8 --
.../document/TestXYMultiPointShapeQueries.java | 26 ++--
.../document/TestXYMultiPolygonShapeQueries.java | 49 +------
.../lucene/document/TestXYPointShapeQueries.java | 27 ++--
.../lucene/document/TestXYPolygonShapeQueries.java | 26 +---
.../src/test/org/apache/lucene/geo/TestLine2D.java | 3 +-
.../java/org/apache/lucene/geo/GeoTestUtil.java | 17 +++
.../java/org/apache/lucene/geo/ShapeTestUtil.java | 7 +
20 files changed, 154 insertions(+), 554 deletions(-)
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 6d9dc4e..ac45db9 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -283,6 +283,8 @@ Other
* SOLR-14995: Update Jetty to 9.4.34 (Mike Drob)
+* LUCENE-9637: Removes some unused code and replaces the Point implementation on ShapeField/ShapeQuery
+ random tests. (Ignacio Vera)
======================= Lucene 8.7.0 =======================
diff --git a/lucene/core/src/test/org/apache/lucene/document/BaseLatLonShapeTestCase.java b/lucene/core/src/test/org/apache/lucene/document/BaseLatLonShapeTestCase.java
index 831c016..4277d61 100644
--- a/lucene/core/src/test/org/apache/lucene/document/BaseLatLonShapeTestCase.java
+++ b/lucene/core/src/test/org/apache/lucene/document/BaseLatLonShapeTestCase.java
@@ -25,8 +25,10 @@ import org.apache.lucene.geo.GeoTestUtil;
import org.apache.lucene.geo.GeoUtils;
import org.apache.lucene.geo.LatLonGeometry;
import org.apache.lucene.geo.Line;
+import org.apache.lucene.geo.Point;
import org.apache.lucene.geo.Polygon;
import org.apache.lucene.geo.Rectangle;
+import org.apache.lucene.geo.Tessellator;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.RandomIndexWriter;
import org.apache.lucene.search.IndexSearcher;
@@ -89,6 +91,11 @@ public abstract class BaseLatLonShapeTestCase extends BaseShapeTestCase {
}
@Override
+ protected Component2D toRectangle2D(double minX, double maxX, double minY, double maxY) {
+ return LatLonGeometry.create(new Rectangle(minY, maxY, minX, maxX));
+ }
+
+ @Override
protected Component2D toPoint2D(Object... points) {
double[][] p = Arrays.stream(points).toArray(double[][]::new);
org.apache.lucene.geo.Point[] pointArray = new org.apache.lucene.geo.Point[points.length];
@@ -251,11 +258,6 @@ public abstract class BaseLatLonShapeTestCase extends BaseShapeTestCase {
return LatLonShape.newPolygonQuery(field, queryRelation, polygons);
}
- /** factory method to create a new point query */
- protected Query newPointQuery(String field, QueryRelation queryRelation, double[]... points) {
- return LatLonShape.newPointQuery(field, queryRelation, points);
- }
-
public void testPolygonQueryEqualsAndHashcode() {
Polygon polygon = GeoTestUtil.nextPolygon();
QueryRelation queryRelation = RandomPicks.randomFrom(random(), QueryRelation.values());
@@ -293,21 +295,10 @@ public abstract class BaseLatLonShapeTestCase extends BaseShapeTestCase {
protected boolean rectCrossesDateline(Object rect) {
return ((Rectangle)rect).crossesDateline();
}
-
- /** use {@link GeoTestUtil#nextPolygon()} to create a random line; TODO: move to GeoTestUtil */
+
@Override
public Line nextLine() {
- return getNextLine();
- }
-
- public static Line getNextLine() {
- Polygon poly = GeoTestUtil.nextPolygon();
- double[] lats = new double[poly.numPoints() - 1];
- double[] lons = new double[lats.length];
- System.arraycopy(poly.getPolyLats(), 0, lats, 0, lats.length);
- System.arraycopy(poly.getPolyLons(), 0, lons, 0, lons.length);
-
- return new Line(lats, lons);
+ return GeoTestUtil.nextLine();
}
@Override
@@ -347,41 +338,6 @@ public abstract class BaseLatLonShapeTestCase extends BaseShapeTestCase {
double quantizeYCeil(double raw) {
return decodeLatitude(encodeLatitudeCeil(raw));
}
-
- /** quantizes a latitude value to be consistent with index encoding */
- protected double quantizeLat(double rawLat) {
- return quantizeY(rawLat);
- }
-
- /** quantizes a provided latitude value rounded up to the nearest encoded integer */
- protected double quantizeLatCeil(double rawLat) {
- return quantizeYCeil(rawLat);
- }
-
- /** quantizes a longitude value to be consistent with index encoding */
- protected double quantizeLon(double rawLon) {
- return quantizeX(rawLon);
- }
-
- /** quantizes a provided longitude value rounded up to the nearest encoded integer */
- protected double quantizeLonCeil(double rawLon) {
- return quantizeXCeil(rawLon);
- }
-
- @Override
- double[] quantizeTriangle(double ax, double ay, boolean ab, double bx, double by, boolean bc, double cx, double cy, boolean ca) {
- ShapeField.DecodedTriangle decoded = encodeDecodeTriangle(ax, ay, ab, bx, by, bc, cx, cy, ca);
- return new double[]{decodeLatitude(decoded.aY), decodeLongitude(decoded.aX), decodeLatitude(decoded.bY), decodeLongitude(decoded.bX), decodeLatitude(decoded.cY), decodeLongitude(decoded.cX)};
- }
-
- @Override
- ShapeField.DecodedTriangle encodeDecodeTriangle(double ax, double ay, boolean ab, double bx, double by, boolean bc, double cx, double cy, boolean ca) {
- byte[] encoded = new byte[7 * ShapeField.BYTES];
- ShapeField.encodeTriangle(encoded, encodeLatitude(ay), encodeLongitude(ax), ab, encodeLatitude(by), encodeLongitude(bx), bc, encodeLatitude(cy), encodeLongitude(cx), ca);
- ShapeField.DecodedTriangle triangle = new ShapeField.DecodedTriangle();
- ShapeField.decodeTriangle(encoded, triangle);
- return triangle;
- }
};
}
@@ -389,24 +345,25 @@ public abstract class BaseLatLonShapeTestCase extends BaseShapeTestCase {
protected enum ShapeType {
POINT() {
public Point nextShape() {
- return new Point(nextLongitude(), nextLatitude());
+ return GeoTestUtil.nextPoint();
}
},
LINE() {
public Line nextShape() {
- Polygon p = GeoTestUtil.nextPolygon();
- double[] lats = new double[p.numPoints() - 1];
- double[] lons = new double[lats.length];
- for (int i = 0; i < lats.length; ++i) {
- lats[i] = p.getPolyLat(i);
- lons[i] = p.getPolyLon(i);
- }
- return new Line(lats, lons);
+ return GeoTestUtil.nextLine();
}
},
POLYGON() {
public Polygon nextShape() {
- return GeoTestUtil.nextPolygon();
+ while (true) {
+ Polygon p = GeoTestUtil.nextPolygon();
+ try {
+ Tessellator.tessellate(p);
+ return p;
+ } catch (IllegalArgumentException e) {
+ // if we can't tessellate; then random polygon generator created a malformed shape
+ }
+ }
}
},
MIXED() {
@@ -421,37 +378,5 @@ public abstract class BaseLatLonShapeTestCase extends BaseShapeTestCase {
}
public abstract Object nextShape();
-
- static ShapeType fromObject(Object shape) {
- if (shape instanceof Point) {
- return POINT;
- } else if (shape instanceof Line) {
- return LINE;
- } else if (shape instanceof Polygon) {
- return POLYGON;
- }
- throw new IllegalArgumentException("invalid shape type from " + shape.toString());
- }
- }
-
- /** internal lat lon point class for testing point shapes */
- protected static class Point {
- double lon;
- double lat;
-
- public Point(double lon, double lat) {
- this.lon = lon;
- this.lat = lat;
- }
-
- public String toString() {
- StringBuilder sb = new StringBuilder();
- sb.append("POINT(");
- sb.append(lon);
- sb.append(',');
- sb.append(lat);
- sb.append(')');
- return sb.toString();
- }
}
}
diff --git a/lucene/core/src/test/org/apache/lucene/document/BaseShapeTestCase.java b/lucene/core/src/test/org/apache/lucene/document/BaseShapeTestCase.java
index 3374ea2..4412472 100644
--- a/lucene/core/src/test/org/apache/lucene/document/BaseShapeTestCase.java
+++ b/lucene/core/src/test/org/apache/lucene/document/BaseShapeTestCase.java
@@ -212,6 +212,8 @@ public abstract class BaseShapeTestCase extends LuceneTestCase {
protected abstract Component2D toCircle2D(Object circle);
+ protected abstract Component2D toRectangle2D(double minX, double maxX, double minY, double maxY);
+
private void verify(Object... shapes) throws Exception {
IndexWriterConfig iwc = newIndexWriterConfig();
iwc.setMergeScheduler(new SerialMergeScheduler());
@@ -299,37 +301,18 @@ public abstract class BaseShapeTestCase extends LuceneTestCase {
System.out.println(" query=" + query + ", relation=" + queryRelation);
}
- final FixedBitSet hits = new FixedBitSet(maxDoc);
- s.search(query, new SimpleCollector() {
-
- private int docBase;
-
- @Override
- public ScoreMode scoreMode() {
- return ScoreMode.COMPLETE_NO_SCORES;
- }
-
- @Override
- protected void doSetNextReader(LeafReaderContext context) throws IOException {
- docBase = context.docBase;
- }
-
- @Override
- public void collect(int doc) throws IOException {
- hits.set(docBase+doc);
- }
- });
-
+ final FixedBitSet hits = searchIndex(s, query, maxDoc);
+
boolean fail = false;
NumericDocValues docIDToID = MultiDocValues.getNumericValues(reader, "id");
for (int docID = 0; docID < maxDoc; ++docID) {
assertEquals(docID, docIDToID.nextDoc());
int id = (int) docIDToID.longValue();
boolean expected;
- double minLon = rectMinX(rect);
- double maxLon = rectMaxX(rect);
- double minLat = rectMinY(rect);
- double maxLat = rectMaxY(rect);
+ double minX = rectMinX(rect);
+ double maxX = rectMaxX(rect);
+ double minY = rectMinY(rect);
+ double maxY = rectMaxY(rect);
if (liveDocs != null && liveDocs.get(docID) == false) {
// document is deleted
expected = false;
@@ -339,10 +322,13 @@ public abstract class BaseShapeTestCase extends LuceneTestCase {
if (queryRelation == QueryRelation.CONTAINS && rectCrossesDateline(rect)) {
// For contains we need to call the validator for each section.
// It is only expected if both sides are contained.
- expected = VALIDATOR.setRelation(queryRelation).testBBoxQuery(minLat, maxLat, minLon, GeoUtils.MAX_LON_INCL, shapes[id]) &&
- VALIDATOR.setRelation(queryRelation).testBBoxQuery(minLat, maxLat, GeoUtils.MIN_LON_INCL, maxLon, shapes[id]);
+ Component2D left = toRectangle2D(minX, GeoUtils.MAX_LON_INCL, minY, maxY);
+ Component2D right = toRectangle2D(GeoUtils.MIN_LON_INCL, maxX, minY, maxY);
+ expected = VALIDATOR.setRelation(queryRelation).testComponentQuery(left, shapes[id]) &&
+ VALIDATOR.setRelation(queryRelation).testComponentQuery(right, shapes[id]);
} else {
- expected = VALIDATOR.setRelation(queryRelation).testBBoxQuery(minLat, maxLat, minLon, maxLon, shapes[id]);
+ Component2D component2D = toRectangle2D(minX, maxX, minY, maxY);
+ expected = VALIDATOR.setRelation(queryRelation).testComponentQuery(component2D, shapes[id]);
}
}
@@ -362,7 +348,7 @@ public abstract class BaseShapeTestCase extends LuceneTestCase {
b.append(" shape=" + shapes[id] + "\n");
}
b.append(" deleted?=" + (liveDocs != null && liveDocs.get(docID) == false));
- b.append(" rect=Rectangle(lat=" + ENCODER.quantizeYCeil(rectMinY(rect)) + " TO " + ENCODER.quantizeY(rectMaxY(rect)) + " lon=" + minLon + " TO " + ENCODER.quantizeX(rectMaxX(rect)) + ")\n");
+ b.append(" rect=Rectangle(lat=" + ENCODER.quantizeYCeil(rectMinY(rect)) + " TO " + ENCODER.quantizeY(rectMaxY(rect)) + " lon=" + minX + " TO " + ENCODER.quantizeX(rectMaxX(rect)) + ")\n");
if (true) {
fail("wrong hit (first of possibly more):\n\n" + b);
} else {
@@ -401,26 +387,7 @@ public abstract class BaseShapeTestCase extends LuceneTestCase {
System.out.println(" query=" + query + ", relation=" + queryRelation);
}
- final FixedBitSet hits = new FixedBitSet(maxDoc);
- s.search(query, new SimpleCollector() {
-
- private int docBase;
-
- @Override
- public ScoreMode scoreMode() {
- return ScoreMode.COMPLETE_NO_SCORES;
- }
-
- @Override
- protected void doSetNextReader(LeafReaderContext context) throws IOException {
- docBase = context.docBase;
- }
-
- @Override
- public void collect(int doc) throws IOException {
- hits.set(docBase+doc);
- }
- });
+ final FixedBitSet hits = searchIndex(s, query, maxDoc);
boolean fail = false;
NumericDocValues docIDToID = MultiDocValues.getNumericValues(reader, "id");
@@ -492,26 +459,7 @@ public abstract class BaseShapeTestCase extends LuceneTestCase {
System.out.println(" query=" + query + ", relation=" + queryRelation);
}
- final FixedBitSet hits = new FixedBitSet(maxDoc);
- s.search(query, new SimpleCollector() {
-
- private int docBase;
-
- @Override
- public ScoreMode scoreMode() {
- return ScoreMode.COMPLETE_NO_SCORES;
- }
-
- @Override
- protected void doSetNextReader(LeafReaderContext context) throws IOException {
- docBase = context.docBase;
- }
-
- @Override
- public void collect(int doc) throws IOException {
- hits.set(docBase+doc);
- }
- });
+ final FixedBitSet hits = searchIndex(s, query, maxDoc);
boolean fail = false;
NumericDocValues docIDToID = MultiDocValues.getNumericValues(reader, "id");
@@ -589,26 +537,7 @@ public abstract class BaseShapeTestCase extends LuceneTestCase {
System.out.println(" query=" + query + ", relation=" + queryRelation);
}
- final FixedBitSet hits = new FixedBitSet(maxDoc);
- s.search(query, new SimpleCollector() {
-
- private int docBase;
-
- @Override
- public ScoreMode scoreMode() {
- return ScoreMode.COMPLETE_NO_SCORES;
- }
-
- @Override
- protected void doSetNextReader(LeafReaderContext context) throws IOException {
- docBase = context.docBase;
- }
-
- @Override
- public void collect(int doc) throws IOException {
- hits.set(docBase+doc);
- }
- });
+ final FixedBitSet hits = searchIndex(s, query, maxDoc);
boolean fail = false;
NumericDocValues docIDToID = MultiDocValues.getNumericValues(reader, "id");
@@ -681,26 +610,7 @@ public abstract class BaseShapeTestCase extends LuceneTestCase {
System.out.println(" query=" + query + ", relation=" + queryRelation);
}
- final FixedBitSet hits = new FixedBitSet(maxDoc);
- s.search(query, new SimpleCollector() {
-
- private int docBase;
-
- @Override
- public ScoreMode scoreMode() {
- return ScoreMode.COMPLETE_NO_SCORES;
- }
-
- @Override
- protected void doSetNextReader(LeafReaderContext context) throws IOException {
- docBase = context.docBase;
- }
-
- @Override
- public void collect(int doc) throws IOException {
- hits.set(docBase+doc);
- }
- });
+ final FixedBitSet hits = searchIndex(s, query, maxDoc);
boolean fail = false;
NumericDocValues docIDToID = MultiDocValues.getNumericValues(reader, "id");
@@ -748,7 +658,30 @@ public abstract class BaseShapeTestCase extends LuceneTestCase {
}
}
+ private FixedBitSet searchIndex(IndexSearcher s, Query query, int maxDoc) throws IOException {
+ final FixedBitSet hits = new FixedBitSet(maxDoc);
+ s.search(query, new SimpleCollector() {
+
+ private int docBase;
+ @Override
+ public ScoreMode scoreMode() {
+ return ScoreMode.COMPLETE_NO_SCORES;
+ }
+
+ @Override
+ protected void doSetNextReader(LeafReaderContext context) {
+ docBase = context.docBase;
+ }
+
+ @Override
+ public void collect(int doc) {
+ hits.set(docBase+doc);
+ }
+ });
+ return hits;
+ }
+
protected abstract Validator getValidator();
protected static abstract class Encoder {
@@ -758,8 +691,6 @@ public abstract class BaseShapeTestCase extends LuceneTestCase {
abstract double quantizeXCeil(double raw);
abstract double quantizeY(double raw);
abstract double quantizeYCeil(double raw);
- abstract double[] quantizeTriangle(double ax, double ay, boolean ab, double bx, double by, boolean bc, double cx, double cy, boolean ca);
- abstract ShapeField.DecodedTriangle encodeDecodeTriangle(double ax, double ay, boolean ab, double bx, double by, boolean bc, double cx, double cy, boolean ca);
}
private int scaledIterationCount(int shapes) {
@@ -783,9 +714,7 @@ public abstract class BaseShapeTestCase extends LuceneTestCase {
}
protected QueryRelation queryRelation = QueryRelation.INTERSECTS;
-
- public abstract boolean testBBoxQuery(double minLat, double maxLat, double minLon, double maxLon, Object shape);
-
+
public abstract boolean testComponentQuery(Component2D line2d, Object shape);
public Validator setRelation(QueryRelation relation) {
diff --git a/lucene/core/src/test/org/apache/lucene/document/BaseXYShapeTestCase.java b/lucene/core/src/test/org/apache/lucene/document/BaseXYShapeTestCase.java
index eb6b765..3e44813 100644
--- a/lucene/core/src/test/org/apache/lucene/document/BaseXYShapeTestCase.java
+++ b/lucene/core/src/test/org/apache/lucene/document/BaseXYShapeTestCase.java
@@ -23,6 +23,7 @@ import com.carrotsearch.randomizedtesting.generators.RandomPicks;
import org.apache.lucene.document.ShapeField.QueryRelation;
import org.apache.lucene.geo.Component2D;
import org.apache.lucene.geo.ShapeTestUtil;
+import org.apache.lucene.geo.Tessellator;
import org.apache.lucene.geo.XYCircle;
import org.apache.lucene.geo.XYGeometry;
import org.apache.lucene.geo.XYLine;
@@ -92,6 +93,11 @@ public abstract class BaseXYShapeTestCase extends BaseShapeTestCase {
}
@Override
+ protected Component2D toRectangle2D(double minX, double maxX, double minY, double maxY) {
+ return XYGeometry.create(new XYRectangle((float)minX, (float)maxX, (float)minY, (float)maxY));
+ }
+
+ @Override
protected Component2D toCircle2D(Object circle) {
return XYGeometry.create((XYCircle) circle);
}
@@ -126,22 +132,10 @@ public abstract class BaseXYShapeTestCase extends BaseShapeTestCase {
return false;
}
- /** use {@link ShapeTestUtil#nextPolygon()} to create a random line; TODO: move to GeoTestUtil */
+ /** use {@link ShapeTestUtil#nextPolygon()} to create a random line */
@Override
public XYLine nextLine() {
- return getNextLine();
- }
-
- public static XYLine getNextLine() {
- XYPolygon poly = ShapeTestUtil.nextPolygon();
- float[] x = new float[poly.numPoints() - 1];
- float[] y = new float[x.length];
- for (int i = 0; i < x.length; ++i) {
- x[i] = poly.getPolyX(i);
- y[i] = poly.getPolyY(i);
- }
-
- return new XYLine(x, y);
+ return ShapeTestUtil.nextLine();
}
@Override
@@ -197,46 +191,32 @@ public abstract class BaseXYShapeTestCase extends BaseShapeTestCase {
double quantizeYCeil(double raw) {
return decode(encode((float) raw));
}
-
- @Override
- double[] quantizeTriangle(double ax, double ay, boolean ab, double bx, double by, boolean bc, double cx, double cy, boolean ca) {
- ShapeField.DecodedTriangle decoded = encodeDecodeTriangle(ax, ay, ab, bx, by, bc, cx, cy, ca);
- return new double[]{decode(decoded.aY), decode(decoded.aX), decode(decoded.bY), decode(decoded.bX), decode(decoded.cY), decode(decoded.cX)};
- }
-
- @Override
- ShapeField.DecodedTriangle encodeDecodeTriangle(double ax, double ay, boolean ab, double bx, double by, boolean bc, double cx, double cy, boolean ca) {
- byte[] encoded = new byte[7 * ShapeField.BYTES];
- ShapeField.encodeTriangle(encoded, encode((float) ay), encode((float) ax), ab, encode((float) by), encode((float) bx), bc, encode((float) cy), encode((float) cx), ca);
- ShapeField.DecodedTriangle triangle = new ShapeField.DecodedTriangle();
- ShapeField.decodeTriangle(encoded, triangle);
- return triangle;
- }
};
}
/** internal shape type for testing different shape types */
protected enum ShapeType {
POINT() {
- public Point nextShape() {
- return new Point((float)random().nextDouble(), (float)random().nextDouble());
+ public XYPoint nextShape() {
+ return ShapeTestUtil.nextPoint();
}
},
LINE() {
public XYLine nextShape() {
- XYPolygon p = ShapeTestUtil.nextPolygon();
- float[] x = new float[p.numPoints() - 1];
- float[] y = new float[x.length];
- for (int i = 0; i < x.length; ++i) {
- x[i] = p.getPolyX(i);
- y[i] = p.getPolyY(i);
- }
- return new XYLine(x, y);
+ return ShapeTestUtil.nextLine();
}
},
POLYGON() {
public XYPolygon nextShape() {
- return ShapeTestUtil.nextPolygon();
+ while (true) {
+ XYPolygon p = ShapeTestUtil.nextPolygon();
+ try {
+ Tessellator.tessellate(p);
+ return p;
+ } catch (IllegalArgumentException e) {
+ // if we can't tessellate; then random polygon generator created a malformed shape
+ }
+ }
}
},
MIXED() {
@@ -251,37 +231,5 @@ public abstract class BaseXYShapeTestCase extends BaseShapeTestCase {
}
public abstract Object nextShape();
-
- static ShapeType fromObject(Object shape) {
- if (shape instanceof Point) {
- return POINT;
- } else if (shape instanceof XYLine) {
- return LINE;
- } else if (shape instanceof XYPolygon) {
- return POLYGON;
- }
- throw new IllegalArgumentException("invalid shape type from " + shape.toString());
- }
- }
-
- /** internal point class for testing point shapes */
- protected static class Point {
- float x;
- float y;
-
- public Point(float x, float y) {
- this.x = x;
- this.y = y;
- }
-
- public String toString() {
- StringBuilder sb = new StringBuilder();
- sb.append("POINT(");
- sb.append(x);
- sb.append(',');
- sb.append(y);
- sb.append(')');
- return sb.toString();
- }
}
}
diff --git a/lucene/core/src/test/org/apache/lucene/document/TestLatLonLineShapeQueries.java b/lucene/core/src/test/org/apache/lucene/document/TestLatLonLineShapeQueries.java
index 8bceb99..1d2998e 100644
--- a/lucene/core/src/test/org/apache/lucene/document/TestLatLonLineShapeQueries.java
+++ b/lucene/core/src/test/org/apache/lucene/document/TestLatLonLineShapeQueries.java
@@ -21,9 +21,7 @@ import com.carrotsearch.randomizedtesting.generators.RandomNumbers;
import org.apache.lucene.document.ShapeField.QueryRelation;
import org.apache.lucene.geo.Component2D;
import org.apache.lucene.geo.GeoTestUtil;
-import org.apache.lucene.geo.LatLonGeometry;
import org.apache.lucene.geo.Line;
-import org.apache.lucene.geo.Rectangle;
/** random bounding box, line, and polygon query tests for random generated {@link Line} types */
@SuppressWarnings("SimpleText")
@@ -74,13 +72,7 @@ public class TestLatLonLineShapeQueries extends BaseLatLonShapeTestCase {
protected LineValidator(Encoder encoder) {
super(encoder);
}
-
- @Override
- public boolean testBBoxQuery(double minLat, double maxLat, double minLon, double maxLon, Object shape) {
- Component2D rectangle2D = LatLonGeometry.create(new Rectangle(minLat, maxLat, minLon, maxLon));
- return testComponentQuery(rectangle2D, shape);
- }
-
+
@Override
public boolean testComponentQuery(Component2D query, Object shape) {
Line line = (Line) shape;
diff --git a/lucene/core/src/test/org/apache/lucene/document/TestLatLonMultiLineShapeQueries.java b/lucene/core/src/test/org/apache/lucene/document/TestLatLonMultiLineShapeQueries.java
index aff1eef..5737fc8 100644
--- a/lucene/core/src/test/org/apache/lucene/document/TestLatLonMultiLineShapeQueries.java
+++ b/lucene/core/src/test/org/apache/lucene/document/TestLatLonMultiLineShapeQueries.java
@@ -74,24 +74,6 @@ public class TestLatLonMultiLineShapeQueries extends BaseLatLonShapeTestCase {
}
@Override
- public boolean testBBoxQuery(double minLat, double maxLat, double minLon, double maxLon, Object shape) {
- Line[] lines = (Line[])shape;
- for (Line l : lines) {
- boolean b = LINEVALIDATOR.testBBoxQuery(minLat, maxLat, minLon, maxLon, l);
- if (b == true && queryRelation == QueryRelation.INTERSECTS) {
- return true;
- } else if (b == true && queryRelation == QueryRelation.CONTAINS) {
- return true;
- } else if (b == false && queryRelation == QueryRelation.DISJOINT) {
- return false;
- } else if (b == false && queryRelation == QueryRelation.WITHIN) {
- return false;
- }
- }
- return queryRelation != QueryRelation.INTERSECTS && queryRelation != QueryRelation.CONTAINS;
- }
-
- @Override
public boolean testComponentQuery(Component2D query, Object shape) {
Line[] lines = (Line[])shape;
for (Line l : lines) {
diff --git a/lucene/core/src/test/org/apache/lucene/document/TestLatLonMultiPointShapeQueries.java b/lucene/core/src/test/org/apache/lucene/document/TestLatLonMultiPointShapeQueries.java
index 311c7a6..19142ec 100644
--- a/lucene/core/src/test/org/apache/lucene/document/TestLatLonMultiPointShapeQueries.java
+++ b/lucene/core/src/test/org/apache/lucene/document/TestLatLonMultiPointShapeQueries.java
@@ -21,6 +21,7 @@ import java.util.List;
import org.apache.lucene.document.ShapeField.QueryRelation;
import org.apache.lucene.geo.Component2D;
+import org.apache.lucene.geo.Point;
/** random bounding box, line, and polygon query tests for random indexed arrays of {@code latitude, longitude} points */
public class TestLatLonMultiPointShapeQueries extends BaseLatLonShapeTestCase {
@@ -35,7 +36,7 @@ public class TestLatLonMultiPointShapeQueries extends BaseLatLonShapeTestCase {
int n = random().nextInt(4) + 1;
Point[] points = new Point[n];
for (int i =0; i < n; i++) {
- points[i] = (Point)ShapeType.POINT.nextShape();
+ points[i] = (Point) ShapeType.POINT.nextShape();
}
return points;
}
@@ -45,7 +46,7 @@ public class TestLatLonMultiPointShapeQueries extends BaseLatLonShapeTestCase {
Point[] points = (Point[]) o;
List<Field> allFields = new ArrayList<>();
for (Point point : points) {
- Field[] fields = LatLonShape.createIndexableFields(name, point.lat, point.lon);
+ Field[] fields = LatLonShape.createIndexableFields(name, point.getLat(), point.getLon());
for (Field field : fields) {
allFields.add(field);
}
@@ -71,25 +72,7 @@ public class TestLatLonMultiPointShapeQueries extends BaseLatLonShapeTestCase {
POINTVALIDATOR.queryRelation = relation;
return this;
}
-
- @Override
- public boolean testBBoxQuery(double minLat, double maxLat, double minLon, double maxLon, Object shape) {
- Point[] points = (Point[]) shape;
- for (Point p : points) {
- boolean b = POINTVALIDATOR.testBBoxQuery(minLat, maxLat, minLon, maxLon, p);
- if (b == true && queryRelation == QueryRelation.INTERSECTS) {
- return true;
- } else if (b == true && queryRelation == QueryRelation.CONTAINS) {
- return true;
- } else if (b == false && queryRelation == QueryRelation.DISJOINT) {
- return false;
- } else if (b == false && queryRelation == QueryRelation.WITHIN) {
- return false;
- }
- }
- return queryRelation != QueryRelation.INTERSECTS && queryRelation != QueryRelation.CONTAINS;
- }
-
+
@Override
public boolean testComponentQuery(Component2D query, Object shape) {
Point[] points = (Point[]) shape;
diff --git a/lucene/core/src/test/org/apache/lucene/document/TestLatLonMultiPolygonShapeQueries.java b/lucene/core/src/test/org/apache/lucene/document/TestLatLonMultiPolygonShapeQueries.java
index 8732d5f..55dc57c 100644
--- a/lucene/core/src/test/org/apache/lucene/document/TestLatLonMultiPolygonShapeQueries.java
+++ b/lucene/core/src/test/org/apache/lucene/document/TestLatLonMultiPolygonShapeQueries.java
@@ -22,7 +22,6 @@ import java.util.List;
import org.apache.lucene.document.ShapeField.QueryRelation;
import org.apache.lucene.geo.Component2D;
import org.apache.lucene.geo.Polygon;
-import org.apache.lucene.geo.Tessellator;
/** random bounding box, line, and polygon query tests for random indexed arrays of {@link Polygon} types */
public class TestLatLonMultiPolygonShapeQueries extends BaseLatLonShapeTestCase {
@@ -37,47 +36,11 @@ public class TestLatLonMultiPolygonShapeQueries extends BaseLatLonShapeTestCase
int n = random().nextInt(4) + 1;
Polygon[] polygons = new Polygon[n];
for (int i =0; i < n; i++) {
- int repetitions =0;
- while (true) {
- // if we can't tessellate; then random polygon generator created a malformed shape
- Polygon p = (Polygon) getShapeType().nextShape();
- try {
- Tessellator.tessellate(p);
- //polygons are disjoint so CONTAINS works. Note that if we intersect
- //any shape then contains return false.
- if (isDisjoint(polygons, p)) {
- polygons[i] = p;
- break;
- }
- repetitions++;
- if (repetitions > 50) {
- //try again
- return nextShape();
- }
- } catch (IllegalArgumentException e) {
- continue;
- }
- }
+ polygons[i] = (Polygon) getShapeType().nextShape();
}
return polygons;
}
-
- private boolean isDisjoint(Polygon[] polygons, Polygon check) {
- // we use bounding boxes so we do not get intersecting polygons.
- for (Polygon polygon : polygons) {
- if (polygon != null) {
- if (getEncoder().quantizeY(polygon.minLat) > getEncoder().quantizeY(check.maxLat)
- || getEncoder().quantizeY(polygon.maxLat) < getEncoder().quantizeY(check.minLat)
- || getEncoder().quantizeX(polygon.minLon) > getEncoder().quantizeX(check.maxLon)
- || getEncoder().quantizeX(polygon.maxLon) < getEncoder().quantizeX(check.minLon)) {
- continue;
- }
- return false;
- }
- }
- return true;
- }
-
+
@Override
protected Field[] createIndexableFields(String name, Object o) {
Polygon[] polygons = (Polygon[]) o;
@@ -112,24 +75,6 @@ public class TestLatLonMultiPolygonShapeQueries extends BaseLatLonShapeTestCase
}
@Override
- public boolean testBBoxQuery(double minLat, double maxLat, double minLon, double maxLon, Object shape) {
- Polygon[] polygons = (Polygon[]) shape;
- for (Polygon p : polygons) {
- boolean b = POLYGONVALIDATOR.testBBoxQuery(minLat, maxLat, minLon, maxLon, p);
- if (b == true && queryRelation == QueryRelation.INTERSECTS) {
- return true;
- } else if (b == true && queryRelation == QueryRelation.CONTAINS) {
- return true;
- } else if (b == false && queryRelation == QueryRelation.DISJOINT) {
- return false;
- } else if (b == false && queryRelation == QueryRelation.WITHIN) {
- return false;
- }
- }
- return queryRelation != QueryRelation.INTERSECTS && queryRelation != QueryRelation.CONTAINS;
- }
-
- @Override
public boolean testComponentQuery(Component2D query, Object shape) {
Polygon[] polygons = (Polygon[]) shape;
if (queryRelation == QueryRelation.CONTAINS) {
diff --git a/lucene/core/src/test/org/apache/lucene/document/TestLatLonPointShapeQueries.java b/lucene/core/src/test/org/apache/lucene/document/TestLatLonPointShapeQueries.java
index 9ada389..10f896f 100644
--- a/lucene/core/src/test/org/apache/lucene/document/TestLatLonPointShapeQueries.java
+++ b/lucene/core/src/test/org/apache/lucene/document/TestLatLonPointShapeQueries.java
@@ -20,9 +20,8 @@ import com.carrotsearch.randomizedtesting.generators.RandomNumbers;
import org.apache.lucene.document.ShapeField.QueryRelation;
import org.apache.lucene.geo.Component2D;
import org.apache.lucene.geo.GeoTestUtil;
-import org.apache.lucene.geo.LatLonGeometry;
import org.apache.lucene.geo.Line;
-import org.apache.lucene.geo.Rectangle;
+import org.apache.lucene.geo.Point;
/** random bounding box, line, and polygon query tests for random generated {@code latitude, longitude} points */
public class TestLatLonPointShapeQueries extends BaseLatLonShapeTestCase {
@@ -45,8 +44,8 @@ public class TestLatLonPointShapeQueries extends BaseLatLonShapeTestCase {
for (int i = 0, j = 0; j < lats.length && i < shapes.length; ++i, ++j) {
Point p = (Point) (shapes[i]);
if (random().nextBoolean() && p != null) {
- lats[j] = p.lat;
- lons[j] = p.lon;
+ lats[j] = p.getLat();
+ lons[j] = p.getLon();
} else {
lats[j] = GeoTestUtil.nextLatitude();
lons[j] = GeoTestUtil.nextLongitude();
@@ -60,7 +59,7 @@ public class TestLatLonPointShapeQueries extends BaseLatLonShapeTestCase {
@Override
protected Field[] createIndexableFields(String field, Object point) {
Point p = (Point)point;
- return LatLonShape.createIndexableFields(field, p.lat, p.lon);
+ return LatLonShape.createIndexableFields(field, p.getLat(), p.getLon());
}
@Override
@@ -72,20 +71,14 @@ public class TestLatLonPointShapeQueries extends BaseLatLonShapeTestCase {
protected PointValidator(Encoder encoder) {
super(encoder);
}
-
- @Override
- public boolean testBBoxQuery(double minLat, double maxLat, double minLon, double maxLon, Object shape) {
- Component2D rectangle2D = LatLonGeometry.create(new Rectangle(minLat, maxLat, minLon, maxLon));
- return testComponentQuery(rectangle2D, shape);
- }
-
+
@Override
public boolean testComponentQuery(Component2D query, Object shape) {
Point p = (Point) shape;
if (queryRelation == QueryRelation.CONTAINS) {
- return testWithinQuery(query, LatLonShape.createIndexableFields("dummy", p.lat, p.lon)) == Component2D.WithinRelation.CANDIDATE;
+ return testWithinQuery(query, LatLonShape.createIndexableFields("dummy", p.getLat(), p.getLon())) == Component2D.WithinRelation.CANDIDATE;
}
- return testComponentQuery(query, LatLonShape.createIndexableFields("dummy", p.lat, p.lon));
+ return testComponentQuery(query, LatLonShape.createIndexableFields("dummy", p.getLat(), p.getLon()));
}
}
}
diff --git a/lucene/core/src/test/org/apache/lucene/document/TestLatLonPolygonShapeQueries.java b/lucene/core/src/test/org/apache/lucene/document/TestLatLonPolygonShapeQueries.java
index 96e1d2e..dc6f58d 100644
--- a/lucene/core/src/test/org/apache/lucene/document/TestLatLonPolygonShapeQueries.java
+++ b/lucene/core/src/test/org/apache/lucene/document/TestLatLonPolygonShapeQueries.java
@@ -18,10 +18,7 @@ package org.apache.lucene.document;
import org.apache.lucene.document.ShapeField.QueryRelation;
import org.apache.lucene.geo.Component2D;
-import org.apache.lucene.geo.LatLonGeometry;
import org.apache.lucene.geo.Polygon;
-import org.apache.lucene.geo.Rectangle;
-import org.apache.lucene.geo.Tessellator;
/** random bounding box, line, and polygon query tests for random indexed {@link Polygon} types */
public class TestLatLonPolygonShapeQueries extends BaseLatLonShapeTestCase {
@@ -32,21 +29,6 @@ public class TestLatLonPolygonShapeQueries extends BaseLatLonShapeTestCase {
}
@Override
- protected Polygon nextShape() {
- Polygon p;
- while (true) {
- // if we can't tessellate; then random polygon generator created a malformed shape
- p = (Polygon)getShapeType().nextShape();
- try {
- Tessellator.tessellate(p);
- return p;
- } catch (IllegalArgumentException e) {
- continue;
- }
- }
- }
-
- @Override
protected Field[] createIndexableFields(String field, Object polygon) {
return LatLonShape.createIndexableFields(field, (Polygon)polygon);
}
@@ -62,12 +44,6 @@ public class TestLatLonPolygonShapeQueries extends BaseLatLonShapeTestCase {
}
@Override
- public boolean testBBoxQuery(double minLat, double maxLat, double minLon, double maxLon, Object shape) {
- Component2D rectangle2D = LatLonGeometry.create(new Rectangle(minLat, maxLat, minLon, maxLon));
- return testComponentQuery(rectangle2D, shape);
- }
-
- @Override
public boolean testComponentQuery(Component2D query, Object o) {
Polygon polygon = (Polygon) o;
if (queryRelation == QueryRelation.CONTAINS) {
diff --git a/lucene/core/src/test/org/apache/lucene/document/TestLatLonShape.java b/lucene/core/src/test/org/apache/lucene/document/TestLatLonShape.java
index f515057..9c65e93 100644
--- a/lucene/core/src/test/org/apache/lucene/document/TestLatLonShape.java
+++ b/lucene/core/src/test/org/apache/lucene/document/TestLatLonShape.java
@@ -424,8 +424,8 @@ public class TestLatLonShape extends LuceneTestCase {
Directory dir = newDirectory();
RandomIndexWriter writer = new RandomIndexWriter(random(), dir);
Document document = new Document();
- BaseLatLonShapeTestCase.Point p = (BaseLatLonShapeTestCase.Point) BaseLatLonShapeTestCase.ShapeType.POINT.nextShape();
- Field[] fields = LatLonShape.createIndexableFields(FIELDNAME, p.lat, p.lon);
+ Point p = GeoTestUtil.nextPoint();
+ Field[] fields = LatLonShape.createIndexableFields(FIELDNAME, p.getLat(), p.getLon());
for (Field f : fields) {
document.add(f);
}
@@ -437,7 +437,7 @@ public class TestLatLonShape extends LuceneTestCase {
IndexSearcher s = newSearcher(r);
// search by same point
- Query q = LatLonShape.newPointQuery(FIELDNAME, QueryRelation.INTERSECTS, new double[] {p.lat, p.lon});
+ Query q = LatLonShape.newPointQuery(FIELDNAME, QueryRelation.INTERSECTS, new double[] {p.getLat(), p.getLon()});
assertEquals(1, s.count(q));
IOUtils.close(r, dir);
}
@@ -767,8 +767,8 @@ public class TestLatLonShape extends LuceneTestCase {
Directory dir = newDirectory();
RandomIndexWriter writer = new RandomIndexWriter(random(), dir);
Document document = new Document();
- BaseLatLonShapeTestCase.Point p = (BaseLatLonShapeTestCase.Point) BaseLatLonShapeTestCase.ShapeType.POINT.nextShape();
- Field[] fields = LatLonShape.createIndexableFields(FIELDNAME, p.lat,p.lon);
+ Point p = GeoTestUtil.nextPoint();
+ Field[] fields = LatLonShape.createIndexableFields(FIELDNAME, p.getLat(), p.getLon());
for (Field f : fields) {
document.add(f);
}
@@ -786,7 +786,7 @@ public class TestLatLonShape extends LuceneTestCase {
Component2D circle2D = LatLonGeometry.create(circle);
int expected;
int expectedDisjoint;
- if (circle2D.contains(p.lon, p.lat)) {
+ if (circle2D.contains(p.getLon(), p.getLat())) {
expected = 1;
expectedDisjoint = 0;
} else {
diff --git a/lucene/core/src/test/org/apache/lucene/document/TestXYLineShapeQueries.java b/lucene/core/src/test/org/apache/lucene/document/TestXYLineShapeQueries.java
index c23806e..ff6de9c 100644
--- a/lucene/core/src/test/org/apache/lucene/document/TestXYLineShapeQueries.java
+++ b/lucene/core/src/test/org/apache/lucene/document/TestXYLineShapeQueries.java
@@ -23,9 +23,7 @@ import java.util.Random;
import org.apache.lucene.document.ShapeField.QueryRelation;
import org.apache.lucene.geo.Component2D;
import org.apache.lucene.geo.ShapeTestUtil;
-import org.apache.lucene.geo.XYGeometry;
import org.apache.lucene.geo.XYLine;
-import org.apache.lucene.geo.XYRectangle;
/** random cartesian bounding box, line, and polygon query tests for random generated cartesian {@link XYLine} types */
public class TestXYLineShapeQueries extends BaseXYShapeTestCase {
@@ -76,13 +74,7 @@ public class TestXYLineShapeQueries extends BaseXYShapeTestCase {
protected LineValidator(Encoder encoder) {
super(encoder);
}
-
- @Override
- public boolean testBBoxQuery(double minY, double maxY, double minX, double maxX, Object shape) {
- Component2D rectangle2D = XYGeometry.create(new XYRectangle((float) minX, (float) maxX, (float) minY, (float) maxY));
- return testComponentQuery(rectangle2D, shape);
- }
-
+
@Override
public boolean testComponentQuery(Component2D query, Object shape) {
XYLine line = (XYLine) shape;
diff --git a/lucene/core/src/test/org/apache/lucene/document/TestXYMultiLineShapeQueries.java b/lucene/core/src/test/org/apache/lucene/document/TestXYMultiLineShapeQueries.java
index d530e66..f342458 100644
--- a/lucene/core/src/test/org/apache/lucene/document/TestXYMultiLineShapeQueries.java
+++ b/lucene/core/src/test/org/apache/lucene/document/TestXYMultiLineShapeQueries.java
@@ -21,9 +21,7 @@ import java.util.List;
import org.apache.lucene.document.ShapeField.QueryRelation;
import org.apache.lucene.geo.Component2D;
-import org.apache.lucene.geo.XYGeometry;
import org.apache.lucene.geo.XYLine;
-import org.apache.lucene.geo.XYRectangle;
/** random cartesian bounding box, line, and polygon query tests for random indexed arrays of cartesian {@link XYLine} types */
public class TestXYMultiLineShapeQueries extends BaseXYShapeTestCase {
@@ -75,12 +73,6 @@ public class TestXYMultiLineShapeQueries extends BaseXYShapeTestCase {
}
@Override
- public boolean testBBoxQuery(double minY, double maxY, double minX, double maxX, Object shape) {
- Component2D rectangle2D = XYGeometry.create(new XYRectangle((float) minX, (float) maxX, (float) minY, (float) maxY));
- return testComponentQuery(rectangle2D, shape);
- }
-
- @Override
public boolean testComponentQuery(Component2D query, Object shape) {
XYLine[] lines = (XYLine[])shape;
for (XYLine l : lines) {
diff --git a/lucene/core/src/test/org/apache/lucene/document/TestXYMultiPointShapeQueries.java b/lucene/core/src/test/org/apache/lucene/document/TestXYMultiPointShapeQueries.java
index 9c573da..5ccdecf 100644
--- a/lucene/core/src/test/org/apache/lucene/document/TestXYMultiPointShapeQueries.java
+++ b/lucene/core/src/test/org/apache/lucene/document/TestXYMultiPointShapeQueries.java
@@ -21,8 +21,8 @@ import java.util.List;
import org.apache.lucene.document.ShapeField.QueryRelation;
import org.apache.lucene.geo.Component2D;
-import org.apache.lucene.geo.XYGeometry;
-import org.apache.lucene.geo.XYRectangle;
+import org.apache.lucene.geo.ShapeTestUtil;
+import org.apache.lucene.geo.XYPoint;
/** random cartesian bounding box, line, and polygon query tests for random indexed arrays of {@code x, y} points */
public class TestXYMultiPointShapeQueries extends BaseXYShapeTestCase {
@@ -32,21 +32,21 @@ public class TestXYMultiPointShapeQueries extends BaseXYShapeTestCase {
}
@Override
- protected Point[] nextShape() {
+ protected XYPoint[] nextShape() {
int n = random().nextInt(4) + 1;
- Point[] points = new Point[n];
+ XYPoint[] points = new XYPoint[n];
for (int i =0; i < n; i++) {
- points[i] = (Point)ShapeType.POINT.nextShape();
+ points[i] = ShapeTestUtil.nextPoint();
}
return points;
}
@Override
protected Field[] createIndexableFields(String name, Object o) {
- Point[] points = (Point[]) o;
+ XYPoint[] points = (XYPoint[]) o;
List<Field> allFields = new ArrayList<>();
- for (Point point : points) {
- Field[] fields = XYShape.createIndexableFields(name, point.x, point.y);
+ for (XYPoint point : points) {
+ Field[] fields = XYShape.createIndexableFields(name, point.getX(), point.getY());
for (Field field : fields) {
allFields.add(field);
}
@@ -74,15 +74,9 @@ public class TestXYMultiPointShapeQueries extends BaseXYShapeTestCase {
}
@Override
- public boolean testBBoxQuery(double minY, double maxY, double minX, double maxX, Object shape) {
- Component2D rectangle2D = XYGeometry.create(new XYRectangle((float) minX, (float) maxX, (float) minY, (float) maxY));
- return testComponentQuery(rectangle2D, shape);
- }
-
- @Override
public boolean testComponentQuery(Component2D query, Object shape) {
- Point[] points = (Point[]) shape;
- for (Point p : points) {
+ XYPoint[] points = (XYPoint[]) shape;
+ for (XYPoint p : points) {
boolean b = POINTVALIDATOR.testComponentQuery(query, p);
if (b == true && queryRelation == QueryRelation.INTERSECTS) {
return true;
diff --git a/lucene/core/src/test/org/apache/lucene/document/TestXYMultiPolygonShapeQueries.java b/lucene/core/src/test/org/apache/lucene/document/TestXYMultiPolygonShapeQueries.java
index 92d27f8..7c4afce 100644
--- a/lucene/core/src/test/org/apache/lucene/document/TestXYMultiPolygonShapeQueries.java
+++ b/lucene/core/src/test/org/apache/lucene/document/TestXYMultiPolygonShapeQueries.java
@@ -21,10 +21,7 @@ import java.util.List;
import org.apache.lucene.document.ShapeField.QueryRelation;
import org.apache.lucene.geo.Component2D;
-import org.apache.lucene.geo.Tessellator;
import org.apache.lucene.geo.XYPolygon;
-import org.apache.lucene.geo.XYRectangle;
-import org.apache.lucene.geo.XYGeometry;
import org.apache.lucene.util.LuceneTestCase;
/** random cartesian bounding box, line, and polygon query tests for random indexed arrays of cartesian {@link XYPolygon} types */
@@ -40,47 +37,11 @@ public class TestXYMultiPolygonShapeQueries extends BaseXYShapeTestCase {
int n = random().nextInt(4) + 1;
XYPolygon[] polygons = new XYPolygon[n];
for (int i =0; i < n; i++) {
- int repetitions =0;
- while (true) {
- // if we can't tessellate; then random polygon generator created a malformed shape
- XYPolygon p = (XYPolygon) getShapeType().nextShape();
- try {
- Tessellator.tessellate(p);
- //polygons are disjoint so CONTAINS works. Note that if we intersect
- //any shape then contains return false.
- if (isDisjoint(polygons, p, i)) {
- polygons[i] = p;
- break;
- }
- repetitions++;
- if (repetitions > 2) {
- //try again
- return nextShape();
- }
- } catch (IllegalArgumentException e) {
- continue;
- }
- }
+ polygons[i] = (XYPolygon) getShapeType().nextShape();
}
return polygons;
}
-
- private boolean isDisjoint(XYPolygon[] polygons, XYPolygon check, int totalPolygons) {
- // we use bounding boxes so we do not get polygons with shared points.
- for (XYPolygon polygon : polygons) {
- if (polygon != null) {
- if (getEncoder().quantizeY(polygon.minY) > getEncoder().quantizeY(check.maxY)
- || getEncoder().quantizeY(polygon.maxY) < getEncoder().quantizeY(check.minY)
- || getEncoder().quantizeX(polygon.minX) > getEncoder().quantizeX(check.maxX)
- || getEncoder().quantizeX(polygon.maxX) < getEncoder().quantizeX(check.minX)) {
- continue;
- }
- return false;
- }
- }
- return true;
- }
-
+
@Override
protected Field[] createIndexableFields(String name, Object o) {
XYPolygon[] polygons = (XYPolygon[]) o;
@@ -115,12 +76,6 @@ public class TestXYMultiPolygonShapeQueries extends BaseXYShapeTestCase {
}
@Override
- public boolean testBBoxQuery(double minY, double maxY, double minX, double maxX, Object shape) {
- Component2D rectangle2D = XYGeometry.create(new XYRectangle((float) minX, (float) maxX, (float) minY, (float) maxY));
- return testComponentQuery(rectangle2D, shape);
- }
-
- @Override
public boolean testComponentQuery(Component2D query, Object shape) {
XYPolygon[] polygons = (XYPolygon[]) shape;
if (queryRelation == QueryRelation.CONTAINS) {
diff --git a/lucene/core/src/test/org/apache/lucene/document/TestXYPointShapeQueries.java b/lucene/core/src/test/org/apache/lucene/document/TestXYPointShapeQueries.java
index 745012a..678370e 100644
--- a/lucene/core/src/test/org/apache/lucene/document/TestXYPointShapeQueries.java
+++ b/lucene/core/src/test/org/apache/lucene/document/TestXYPointShapeQueries.java
@@ -23,9 +23,8 @@ import java.util.Random;
import org.apache.lucene.document.ShapeField.QueryRelation;
import org.apache.lucene.geo.Component2D;
import org.apache.lucene.geo.ShapeTestUtil;
-import org.apache.lucene.geo.XYGeometry;
import org.apache.lucene.geo.XYLine;
-import org.apache.lucene.geo.XYRectangle;
+import org.apache.lucene.geo.XYPoint;
/** random cartesian bounding box, line, and polygon query tests for random generated {@code x, y} points */
public class TestXYPointShapeQueries extends BaseXYShapeTestCase {
@@ -47,10 +46,10 @@ public class TestXYPointShapeQueries extends BaseXYShapeTestCase {
float[] x = new float[RandomNumbers.randomIntBetween(random, 2, maxBound)];
float[] y = new float[x.length];
for (int i = 0, j = 0; j < x.length && i < shapes.length; ++i, ++j) {
- Point p = (Point) (shapes[i]);
+ XYPoint p = (XYPoint) (shapes[i]);
if (random.nextBoolean() && p != null) {
- x[j] = p.x;
- y[j] = p.y;
+ x[j] = p.getX();
+ y[j] = p.getY();
} else {
x[j] = ShapeTestUtil.nextFloat(random);
y[j] = ShapeTestUtil.nextFloat(random);
@@ -63,8 +62,8 @@ public class TestXYPointShapeQueries extends BaseXYShapeTestCase {
@Override
protected Field[] createIndexableFields(String field, Object point) {
- Point p = (Point)point;
- return XYShape.createIndexableFields(field, p.x, p.y);
+ XYPoint p = (XYPoint)point;
+ return XYShape.createIndexableFields(field, p.getX(), p.getY());
}
@Override
@@ -76,20 +75,14 @@ public class TestXYPointShapeQueries extends BaseXYShapeTestCase {
protected PointValidator(Encoder encoder) {
super(encoder);
}
-
- @Override
- public boolean testBBoxQuery(double minY, double maxY, double minX, double maxX, Object shape) {
- Component2D rectangle2D = XYGeometry.create(new XYRectangle((float) minX, (float) maxX, (float) minY, (float) maxY));
- return testComponentQuery(rectangle2D, shape);
- }
-
+
@Override
public boolean testComponentQuery(Component2D query, Object shape) {
- Point point = (Point) shape;
+ XYPoint point = (XYPoint) shape;
if (queryRelation == QueryRelation.CONTAINS) {
- return testWithinQuery(query, XYShape.createIndexableFields("dummy", point.x, point.y)) == Component2D.WithinRelation.CANDIDATE;
+ return testWithinQuery(query, XYShape.createIndexableFields("dummy", point.getX(), point.getY())) == Component2D.WithinRelation.CANDIDATE;
}
- return testComponentQuery(query, XYShape.createIndexableFields("dummy", point.x, point.y));
+ return testComponentQuery(query, XYShape.createIndexableFields("dummy", point.getX(), point.getY()));
}
}
}
diff --git a/lucene/core/src/test/org/apache/lucene/document/TestXYPolygonShapeQueries.java b/lucene/core/src/test/org/apache/lucene/document/TestXYPolygonShapeQueries.java
index 7ebeb1b..4503bf5 100644
--- a/lucene/core/src/test/org/apache/lucene/document/TestXYPolygonShapeQueries.java
+++ b/lucene/core/src/test/org/apache/lucene/document/TestXYPolygonShapeQueries.java
@@ -18,10 +18,7 @@ package org.apache.lucene.document;
import org.apache.lucene.document.ShapeField.QueryRelation;
import org.apache.lucene.geo.Component2D;
-import org.apache.lucene.geo.Tessellator;
-import org.apache.lucene.geo.XYGeometry;
import org.apache.lucene.geo.XYPolygon;
-import org.apache.lucene.geo.XYRectangle;
/** random cartesian bounding box, line, and polygon query tests for random indexed {@link XYPolygon} types */
public class TestXYPolygonShapeQueries extends BaseXYShapeTestCase {
@@ -32,21 +29,6 @@ public class TestXYPolygonShapeQueries extends BaseXYShapeTestCase {
}
@Override
- protected XYPolygon nextShape() {
- XYPolygon p;
- while (true) {
- // if we can't tessellate; then random polygon generator created a malformed shape
- p = (XYPolygon)getShapeType().nextShape();
- try {
- Tessellator.tessellate(p);
- return p;
- } catch (IllegalArgumentException e) {
- continue;
- }
- }
- }
-
- @Override
protected Field[] createIndexableFields(String field, Object polygon) {
return XYShape.createIndexableFields(field, (XYPolygon)polygon);
}
@@ -60,13 +42,7 @@ public class TestXYPolygonShapeQueries extends BaseXYShapeTestCase {
protected PolygonValidator(Encoder encoder) {
super(encoder);
}
-
- @Override
- public boolean testBBoxQuery(double minY, double maxY, double minX, double maxX, Object shape) {
- Component2D rectangle2D = XYGeometry.create(new XYRectangle((float) minX, (float) maxX, (float) minY, (float) maxY));
- return testComponentQuery(rectangle2D, shape);
- }
-
+
@Override
public boolean testComponentQuery(Component2D query, Object o) {
XYPolygon polygon = (XYPolygon) o;
diff --git a/lucene/core/src/test/org/apache/lucene/geo/TestLine2D.java b/lucene/core/src/test/org/apache/lucene/geo/TestLine2D.java
index e2b2cd8..fb0f7f4 100644
--- a/lucene/core/src/test/org/apache/lucene/geo/TestLine2D.java
+++ b/lucene/core/src/test/org/apache/lucene/geo/TestLine2D.java
@@ -17,7 +17,6 @@
package org.apache.lucene.geo;
-import org.apache.lucene.document.TestLatLonLineShapeQueries;
import org.apache.lucene.index.PointValues.Relation;
import org.apache.lucene.util.LuceneTestCase;
@@ -72,7 +71,7 @@ public class TestLine2D extends LuceneTestCase {
}
public void testRandomTriangles() {
- Line line = TestLatLonLineShapeQueries.getNextLine();
+ Line line = GeoTestUtil.nextLine();
Component2D line2D = Line2D.create(line);
for (int i =0; i < 100; i++) {
diff --git a/lucene/test-framework/src/java/org/apache/lucene/geo/GeoTestUtil.java b/lucene/test-framework/src/java/org/apache/lucene/geo/GeoTestUtil.java
index cbcc4c1..f052ccc 100644
--- a/lucene/test-framework/src/java/org/apache/lucene/geo/GeoTestUtil.java
+++ b/lucene/test-framework/src/java/org/apache/lucene/geo/GeoTestUtil.java
@@ -391,6 +391,23 @@ public class GeoTestUtil {
return new Polygon(result[0], result[1]);
}
+ public static Point nextPoint() {
+ double lat = nextLatitude();
+ double lon = nextLongitude();
+ return new Point(lat, lon);
+ }
+
+ public static Line nextLine() {
+ Polygon p = nextPolygon();
+ double[] lats = new double[p.numPoints() - 1];
+ double[] lons = new double[lats.length];
+ for (int i = 0; i < lats.length; ++i) {
+ lats[i] = p.getPolyLat(i);
+ lons[i] = p.getPolyLon(i);
+ }
+ return new Line(lats, lons);
+ }
+
public static Circle nextCircle() {
double lat = nextLatitude();
double lon = nextLongitude();
diff --git a/lucene/test-framework/src/java/org/apache/lucene/geo/ShapeTestUtil.java b/lucene/test-framework/src/java/org/apache/lucene/geo/ShapeTestUtil.java
index 62e71d1..8f447e5 100644
--- a/lucene/test-framework/src/java/org/apache/lucene/geo/ShapeTestUtil.java
+++ b/lucene/test-framework/src/java/org/apache/lucene/geo/ShapeTestUtil.java
@@ -56,6 +56,13 @@ public class ShapeTestUtil {
}
}
+ public static XYPoint nextPoint() {
+ Random random = random();
+ float x = nextFloat(random);
+ float y = nextFloat(random);
+ return new XYPoint(x, y);
+ }
+
public static XYLine nextLine() {
XYPolygon poly = ShapeTestUtil.nextPolygon();
float[] x = new float[poly.numPoints() - 1];