From 88c9da6c899c7015f6c9a818a4a4f91984022254 Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Fri, 22 Apr 2016 15:10:39 -0400 Subject: [PATCH] LUCENE-7249: LatLonPoint polygon should use tree relate() --- .../src/java/org/apache/lucene/document/LatLonGrid.java | 4 ++-- .../apache/lucene/document/LatLonPointInPolygonQuery.java | 5 +++-- .../src/test/org/apache/lucene/document/TestLatLonGrid.java | 6 +++--- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/lucene/sandbox/src/java/org/apache/lucene/document/LatLonGrid.java b/lucene/sandbox/src/java/org/apache/lucene/document/LatLonGrid.java index 2083f03fd1b..4b3b2b2acb9 100644 --- a/lucene/sandbox/src/java/org/apache/lucene/document/LatLonGrid.java +++ b/lucene/sandbox/src/java/org/apache/lucene/document/LatLonGrid.java @@ -62,12 +62,12 @@ final class LatLonGrid { final LatLonTree[] tree; - LatLonGrid(int minLat, int maxLat, int minLon, int maxLon, Polygon... polygons) { + LatLonGrid(int minLat, int maxLat, int minLon, int maxLon, LatLonTree[] tree) { this.minLat = minLat; this.maxLat = maxLat; this.minLon = minLon; this.maxLon = maxLon; - this.tree = LatLonTree.build(polygons); + this.tree = tree; if (minLon > maxLon) { // maybe make 2 grids if you want this? throw new IllegalArgumentException("Grid cannot cross the dateline"); diff --git a/lucene/sandbox/src/java/org/apache/lucene/document/LatLonPointInPolygonQuery.java b/lucene/sandbox/src/java/org/apache/lucene/document/LatLonPointInPolygonQuery.java index 15361b5640a..23a98d22c77 100644 --- a/lucene/sandbox/src/java/org/apache/lucene/document/LatLonPointInPolygonQuery.java +++ b/lucene/sandbox/src/java/org/apache/lucene/document/LatLonPointInPolygonQuery.java @@ -92,10 +92,11 @@ final class LatLonPointInPolygonQuery extends Query { NumericUtils.intToSortableBytes(encodeLongitude(box.minLon), minLon, 0); NumericUtils.intToSortableBytes(encodeLongitude(box.maxLon), maxLon, 0); + final LatLonTree[] tree = LatLonTree.build(polygons); final LatLonGrid grid = new LatLonGrid(encodeLatitude(box.minLat), encodeLatitude(box.maxLat), encodeLongitude(box.minLon), - encodeLongitude(box.maxLon), polygons); + encodeLongitude(box.maxLon), tree); return new ConstantScoreWeight(this) { @@ -156,7 +157,7 @@ final class LatLonPointInPolygonQuery extends Query { double cellMaxLat = decodeLatitude(maxPackedValue, 0); double cellMaxLon = decodeLongitude(maxPackedValue, Integer.BYTES); - return Polygon.relate(polygons, cellMinLat, cellMaxLat, cellMinLon, cellMaxLon); + return LatLonTree.relate(tree, cellMinLat, cellMaxLat, cellMinLon, cellMaxLon); } }); diff --git a/lucene/sandbox/src/test/org/apache/lucene/document/TestLatLonGrid.java b/lucene/sandbox/src/test/org/apache/lucene/document/TestLatLonGrid.java index 891e3d52fba..0c185ea366d 100644 --- a/lucene/sandbox/src/test/org/apache/lucene/document/TestLatLonGrid.java +++ b/lucene/sandbox/src/test/org/apache/lucene/document/TestLatLonGrid.java @@ -40,7 +40,7 @@ public class TestLatLonGrid extends LuceneTestCase { int maxLat = encodeLatitude(box.maxLat); int minLon = encodeLongitude(box.minLon); int maxLon = encodeLongitude(box.maxLon); - LatLonGrid grid = new LatLonGrid(minLat, maxLat, minLon, maxLon, polygon); + LatLonGrid grid = new LatLonGrid(minLat, maxLat, minLon, maxLon, LatLonTree.build(polygon)); // we are in integer space... but exhaustive testing is slow! for (int j = 0; j < 10000; j++) { int lat = TestUtil.nextInt(random(), minLat, maxLat); @@ -79,7 +79,7 @@ public class TestLatLonGrid extends LuceneTestCase { int maxLat = encodeLatitude(box.maxLat); int minLon = encodeLongitude(box.minLon); int maxLon = encodeLongitude(box.maxLon); - LatLonGrid grid = new LatLonGrid(minLat, maxLat, minLon, maxLon, polygon); + LatLonGrid grid = new LatLonGrid(minLat, maxLat, minLon, maxLon, LatLonTree.build(polygon)); // we are in integer space... but exhaustive testing is slow! for (int j = 0; j < 1000; j++) { int lat = TestUtil.nextInt(random(), minLat, maxLat); @@ -99,7 +99,7 @@ public class TestLatLonGrid extends LuceneTestCase { double ONE = decodeLatitude(1); Polygon tiny = new Polygon(new double[] { ZERO, ZERO, ONE, ONE, ZERO }, new double[] { ZERO, ONE, ONE, ZERO, ZERO }); for (int max = 1; max < 500000; max++) { - LatLonGrid grid = new LatLonGrid(0, max, 0, max, tiny); + LatLonGrid grid = new LatLonGrid(0, max, 0, max, LatLonTree.build(tiny)); assertEquals(tiny.contains(decodeLatitude(max), decodeLongitude(max)), grid.contains(max, max)); } }