From 283b329bbbd8b6a8f9c75ec4e79ca4034c910e88 Mon Sep 17 00:00:00 2001 From: Karl Wright Date: Tue, 27 Dec 2016 19:41:55 -0500 Subject: [PATCH] LUCENE-7511: Introduce Vector.MINIMUM_ANGULAR_RESOLUTION. --- .../lucene/spatial3d/geom/GeoBBoxFactory.java | 34 +++++++++---------- .../spatial3d/geom/GeoCircleFactory.java | 2 +- .../spatial3d/geom/GeoPolygonFactory.java | 6 ++-- .../apache/lucene/spatial3d/geom/Vector.java | 4 +++ 4 files changed, 25 insertions(+), 21 deletions(-) diff --git a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoBBoxFactory.java b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoBBoxFactory.java index 3d0b8cb7a40..d0427bc91df 100755 --- a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoBBoxFactory.java +++ b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoBBoxFactory.java @@ -45,18 +45,18 @@ public class GeoBBoxFactory { leftLon = -Math.PI; if (rightLon > Math.PI) rightLon = Math.PI; - if ((Math.abs(leftLon + Math.PI) < Vector.MINIMUM_RESOLUTION && Math.abs(rightLon - Math.PI) < Vector.MINIMUM_RESOLUTION) || - (Math.abs(rightLon + Math.PI) < Vector.MINIMUM_RESOLUTION && Math.abs(leftLon - Math.PI) < Vector.MINIMUM_RESOLUTION)) { - if (Math.abs(topLat - Math.PI * 0.5) < Vector.MINIMUM_RESOLUTION && Math.abs(bottomLat + Math.PI * 0.5) < Vector.MINIMUM_RESOLUTION) + if ((Math.abs(leftLon + Math.PI) < Vector.MINIMUM_ANGULAR_RESOLUTION && Math.abs(rightLon - Math.PI) < Vector.MINIMUM_ANGULAR_RESOLUTION) || + (Math.abs(rightLon + Math.PI) < Vector.MINIMUM_ANGULAR_RESOLUTION && Math.abs(leftLon - Math.PI) < Vector.MINIMUM_ANGULAR_RESOLUTION)) { + if (Math.abs(topLat - Math.PI * 0.5) < Vector.MINIMUM_ANGULAR_RESOLUTION && Math.abs(bottomLat + Math.PI * 0.5) < Vector.MINIMUM_ANGULAR_RESOLUTION) return new GeoWorld(planetModel); - if (Math.abs(topLat - bottomLat) < Vector.MINIMUM_RESOLUTION) { - if (Math.abs(topLat - Math.PI * 0.5) < Vector.MINIMUM_RESOLUTION || Math.abs(topLat + Math.PI * 0.5) < Vector.MINIMUM_RESOLUTION) + if (Math.abs(topLat - bottomLat) < Vector.MINIMUM_ANGULAR_RESOLUTION) { + if (Math.abs(topLat - Math.PI * 0.5) < Vector.MINIMUM_ANGULAR_RESOLUTION || Math.abs(topLat + Math.PI * 0.5) < Vector.MINIMUM_ANGULAR_RESOLUTION) return new GeoDegeneratePoint(planetModel, topLat, 0.0); return new GeoDegenerateLatitudeZone(planetModel, topLat); } - if (Math.abs(topLat - Math.PI * 0.5) < Vector.MINIMUM_RESOLUTION) + if (Math.abs(topLat - Math.PI * 0.5) < Vector.MINIMUM_ANGULAR_RESOLUTION) return new GeoNorthLatitudeZone(planetModel, bottomLat); - else if (Math.abs(bottomLat + Math.PI * 0.5) < Vector.MINIMUM_RESOLUTION) + else if (Math.abs(bottomLat + Math.PI * 0.5) < Vector.MINIMUM_ANGULAR_RESOLUTION) return new GeoSouthLatitudeZone(planetModel, topLat); return new GeoLatitudeZone(planetModel, topLat, bottomLat); } @@ -65,7 +65,7 @@ public class GeoBBoxFactory { if (extent < 0.0) extent += Math.PI * 2.0; if (topLat == Math.PI * 0.5 && bottomLat == -Math.PI * 0.5) { - if (Math.abs(leftLon - rightLon) < Vector.MINIMUM_RESOLUTION) + if (Math.abs(leftLon - rightLon) < Vector.MINIMUM_ANGULAR_RESOLUTION) return new GeoDegenerateLongitudeSlice(planetModel, leftLon); if (extent >= Math.PI) @@ -74,35 +74,35 @@ public class GeoBBoxFactory { return new GeoLongitudeSlice(planetModel, leftLon, rightLon); } //System.err.println(" not longitude slice"); - if (Math.abs(leftLon - rightLon) < Vector.MINIMUM_RESOLUTION) { - if (Math.abs(topLat - bottomLat) < Vector.MINIMUM_RESOLUTION) + if (Math.abs(leftLon - rightLon) < Vector.MINIMUM_ANGULAR_RESOLUTION) { + if (Math.abs(topLat - bottomLat) < Vector.MINIMUM_ANGULAR_RESOLUTION) return new GeoDegeneratePoint(planetModel, topLat, leftLon); return new GeoDegenerateVerticalLine(planetModel, topLat, bottomLat, leftLon); } //System.err.println(" not vertical line"); if (extent >= Math.PI) { - if (Math.abs(topLat - bottomLat) < Vector.MINIMUM_RESOLUTION) { + if (Math.abs(topLat - bottomLat) < Vector.MINIMUM_ANGULAR_RESOLUTION) { //System.err.println(" wide degenerate line"); return new GeoWideDegenerateHorizontalLine(planetModel, topLat, leftLon, rightLon); } - if (Math.abs(topLat - Math.PI * 0.5) < Vector.MINIMUM_RESOLUTION) { + if (Math.abs(topLat - Math.PI * 0.5) < Vector.MINIMUM_ANGULAR_RESOLUTION) { return new GeoWideNorthRectangle(planetModel, bottomLat, leftLon, rightLon); - } else if (Math.abs(bottomLat + Math.PI * 0.5) < Vector.MINIMUM_RESOLUTION) { + } else if (Math.abs(bottomLat + Math.PI * 0.5) < Vector.MINIMUM_ANGULAR_RESOLUTION) { return new GeoWideSouthRectangle(planetModel, topLat, leftLon, rightLon); } //System.err.println(" wide rect"); return new GeoWideRectangle(planetModel, topLat, bottomLat, leftLon, rightLon); } - if (Math.abs(topLat - bottomLat) < Vector.MINIMUM_RESOLUTION) { - if (Math.abs(topLat - Math.PI * 0.5) < Vector.MINIMUM_RESOLUTION || Math.abs(topLat + Math.PI * 0.5) < Vector.MINIMUM_RESOLUTION) { + if (Math.abs(topLat - bottomLat) < Vector.MINIMUM_ANGULAR_RESOLUTION) { + if (Math.abs(topLat - Math.PI * 0.5) < Vector.MINIMUM_ANGULAR_RESOLUTION || Math.abs(topLat + Math.PI * 0.5) < Vector.MINIMUM_ANGULAR_RESOLUTION) { return new GeoDegeneratePoint(planetModel, topLat, 0.0); } //System.err.println(" horizontal line"); return new GeoDegenerateHorizontalLine(planetModel, topLat, leftLon, rightLon); } - if (Math.abs(topLat - Math.PI * 0.5) < Vector.MINIMUM_RESOLUTION) { + if (Math.abs(topLat - Math.PI * 0.5) < Vector.MINIMUM_ANGULAR_RESOLUTION) { return new GeoNorthRectangle(planetModel, bottomLat, leftLon, rightLon); - } else if (Math.abs(bottomLat + Math.PI * 0.5) < Vector.MINIMUM_RESOLUTION) { + } else if (Math.abs(bottomLat + Math.PI * 0.5) < Vector.MINIMUM_ANGULAR_RESOLUTION) { return new GeoSouthRectangle(planetModel, topLat, leftLon, rightLon); } //System.err.println(" rectangle"); diff --git a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoCircleFactory.java b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoCircleFactory.java index ee75179eb99..292790f4a0a 100644 --- a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoCircleFactory.java +++ b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoCircleFactory.java @@ -34,7 +34,7 @@ public class GeoCircleFactory { * @return a GeoCircle corresponding to what was specified. */ public static GeoCircle makeGeoCircle(final PlanetModel planetModel, final double latitude, final double longitude, final double radius) { - if (radius < Vector.MINIMUM_RESOLUTION) { + if (radius < Vector.MINIMUM_ANGULAR_RESOLUTION) { return new GeoDegeneratePoint(planetModel, latitude, longitude); } return new GeoStandardCircle(planetModel, latitude, longitude, radius); 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.java index f0e4bcd84af..97bc230bb5b 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 @@ -601,7 +601,7 @@ public class GeoPolygonFactory { if (angleDelta > Math.PI) { angleDelta -= Math.PI * 2.0; } - if (Math.abs(angleDelta - Math.PI) < Vector.MINIMUM_RESOLUTION) { + if (Math.abs(angleDelta - Math.PI) < Vector.MINIMUM_ANGULAR_RESOLUTION) { return null; } //System.out.println(" angle delta = "+angleDelta); @@ -624,7 +624,7 @@ public class GeoPolygonFactory { if (angleDelta > Math.PI) { angleDelta -= Math.PI * 2.0; } - if (Math.abs(angleDelta - Math.PI) < Vector.MINIMUM_RESOLUTION) { + if (Math.abs(angleDelta - Math.PI) < Vector.MINIMUM_ANGULAR_RESOLUTION) { return null; } //System.out.println(" angle delta = "+angleDelta); @@ -634,7 +634,7 @@ public class GeoPolygonFactory { // Clockwise == inside == negative //System.out.println("Arcdistance = "+arcDistance); - if (Math.abs(arcDistance) < Vector.MINIMUM_RESOLUTION) { + if (Math.abs(arcDistance) < Vector.MINIMUM_ANGULAR_RESOLUTION) { // No idea what direction, so try another pole. return null; } diff --git a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/Vector.java b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/Vector.java index 7ebf4535789..852cac49df1 100755 --- a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/Vector.java +++ b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/Vector.java @@ -28,6 +28,10 @@ public class Vector { * less than this. */ public static final double MINIMUM_RESOLUTION = 1.0e-12; + /** + * Angular version of minimum resolution. + */ + public static final double MINIMUM_ANGULAR_RESOLUTION = Math.PI * MINIMUM_RESOLUTION; /** * For squared quantities, the bound is squared too. */