|
@@ -20,8 +20,15 @@ package org.elasticsearch.h3;
|
|
|
|
|
|
import com.carrotsearch.randomizedtesting.generators.RandomPicks;
|
|
|
|
|
|
+import org.apache.lucene.spatial3d.geom.GeoPoint;
|
|
|
+import org.apache.lucene.spatial3d.geom.GeoPolygon;
|
|
|
+import org.apache.lucene.spatial3d.geom.GeoPolygonFactory;
|
|
|
+import org.apache.lucene.spatial3d.geom.PlanetModel;
|
|
|
import org.elasticsearch.test.ESTestCase;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
public class ParentChildNavigationTests extends ESTestCase {
|
|
|
|
|
|
public void testParentChild() {
|
|
@@ -44,11 +51,11 @@ public class ParentChildNavigationTests extends ESTestCase {
|
|
|
|
|
|
public void testHexRing() {
|
|
|
String[] h3Addresses = H3.getStringRes0Cells();
|
|
|
- String h3Address = RandomPicks.randomFrom(random(), h3Addresses);
|
|
|
for (int i = 1; i < H3.MAX_H3_RES; i++) {
|
|
|
+ String h3Address = RandomPicks.randomFrom(random(), h3Addresses);
|
|
|
+ assertEquals(i - 1, H3.getResolution(h3Address));
|
|
|
h3Addresses = H3.h3ToChildren(h3Address);
|
|
|
assertHexRing(i, h3Address, h3Addresses);
|
|
|
- h3Address = RandomPicks.randomFrom(random(), h3Addresses);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -65,4 +72,38 @@ public class ParentChildNavigationTests extends ESTestCase {
|
|
|
assertEquals(children[i], ring[positions[i - 1]]);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ public void testNoChildrenIntersecting() {
|
|
|
+ String[] h3Addresses = H3.getStringRes0Cells();
|
|
|
+ String h3Address = RandomPicks.randomFrom(random(), h3Addresses);
|
|
|
+ for (int i = 1; i <= H3.MAX_H3_RES; i++) {
|
|
|
+ h3Addresses = H3.h3ToChildren(h3Address);
|
|
|
+ assertIntersectingChildren(h3Address, h3Addresses);
|
|
|
+ h3Address = RandomPicks.randomFrom(random(), h3Addresses);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void assertIntersectingChildren(String h3Address, String[] children) {
|
|
|
+ String[] intersectingNotChildren = H3.h3ToNoChildrenIntersecting(h3Address);
|
|
|
+ for (String noChild : intersectingNotChildren) {
|
|
|
+ GeoPolygon p = getGeoPolygon(noChild);
|
|
|
+ int intersections = 0;
|
|
|
+ for (String o : children) {
|
|
|
+ if (p.intersects(getGeoPolygon(o))) {
|
|
|
+ intersections++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ assertEquals(2, intersections);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private GeoPolygon getGeoPolygon(String h3Address) {
|
|
|
+ CellBoundary cellBoundary = H3.h3ToGeoBoundary(h3Address);
|
|
|
+ List<GeoPoint> points = new ArrayList<>(cellBoundary.numPoints());
|
|
|
+ for (int i = 0; i < cellBoundary.numPoints(); i++) {
|
|
|
+ LatLng latLng = cellBoundary.getLatLon(i);
|
|
|
+ points.add(new GeoPoint(PlanetModel.SPHERE, latLng.getLatRad(), latLng.getLonRad()));
|
|
|
+ }
|
|
|
+ return GeoPolygonFactory.makeGeoPolygon(PlanetModel.SPHERE, points);
|
|
|
+ }
|
|
|
}
|