Removing pole restriction on GeoDistanceRangeQueryTests

This commit corrects the maxRadialDistance computation for points at the poles to half the distance of the meridian.
This commit is contained in:
Nicholas Knize 2015-11-13 09:32:31 -06:00
parent 12bb1b79f6
commit 9b3920b52c
2 changed files with 5 additions and 5 deletions

View File

@ -68,6 +68,9 @@ public class GeoUtils {
/** Returns the maximum distance/radius from the point 'center' before overlapping */
public static double maxRadialDistance(GeoPoint center) {
if (Math.abs(center.lat()) == 90.0) {
return SloppyMath.haversin(center.lat(), center.lon(), 0, center.lon())*1000.0;
}
return SloppyMath.haversin(center.lat(), center.lon(), center.lat(), (180.0 + center.lon()) % 360)*1000.0;
}

View File

@ -47,7 +47,7 @@ public class GeoDistanceRangeQueryTests extends AbstractQueryTestCase<GeoDistanc
if (randomBoolean()) {
builder = new GeoDistanceRangeQueryBuilder(GEO_POINT_FIELD_NAME, randomGeohash(3, 12));
} else {
GeoPoint point = RandomGeoGenerator.randomPointIn(random(), -179, -89, 89, 179);
GeoPoint point = RandomGeoGenerator.randomPoint(random());
if (randomBoolean()) {
builder = new GeoDistanceRangeQueryBuilder(GEO_POINT_FIELD_NAME, point);
} else {
@ -55,10 +55,7 @@ public class GeoDistanceRangeQueryTests extends AbstractQueryTestCase<GeoDistanc
}
}
GeoPoint point = builder.point();
// todo remove the following pole hack when LUCENE-6846 lands
final double distToPole = SloppyMath.haversin(point.lat(), point.lon(), (point.lat()<0) ? -90.0 : 90.0, point.lon());
final double maxRadius = GeoUtils.maxRadialDistance(point, distToPole);
final double maxRadius = GeoUtils.maxRadialDistance(point);
final int fromValueMeters = randomInt((int)(maxRadius*0.5));
final int toValueMeters = randomIntBetween(fromValueMeters + 1, (int)maxRadius);
DistanceUnit fromToUnits = randomFrom(DistanceUnit.values());