LUCENE-3599: Fix DistanceUtils.haversine() javadocs -- were incorrectly stating the expected order of the arguments

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1208118 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Chris M. Hostetter 2011-11-29 22:38:08 +00:00
parent 3ed5106920
commit 2337f4687f
3 changed files with 23 additions and 18 deletions

View File

@ -92,6 +92,11 @@ Bug Fixes
assert if such a parent doc was the first doc in the segment).
(Shay Banon, Mike McCandless)
Documentation
* LUCENE-3599: Javadocs for DistanceUtils.haversine() were incorrectly
stating the expected order of the arguments (David Smiley via hossman)
======================= Lucene 3.5.0 ================
Changes in backwards compatibility policy

View File

@ -312,15 +312,15 @@ public class DistanceUtils {
}
/**
* @param x1 The x coordinate of the first point, in radians
* Computes the haversine distance between two points. The arguments are in radians and provided in lat,lon order.
* @param y1 The y coordinate of the first point, in radians
* @param x2 The x coordinate of the second point, in radians
* @param x1 The x coordinate of the first point, in radians
* @param y2 The y coordinate of the second point, in radians
* @param x2 The x coordinate of the second point, in radians
* @param radius The radius of the sphere
* @return The distance between the two points, as determined by the Haversine formula.
* @return The distance between the two points, as determined by the haversine formula.
*/
public static double haversine(double x1, double y1, double x2, double y2, double radius) {
public static double haversine(double y1, double x1, double y2, double x2, double radius) {
double result = 0;
//make sure they aren't all the same, as then we can just return 0
if ((x1 != x2) || (y1 != y2)) {
@ -328,8 +328,8 @@ public class DistanceUtils {
double diffY = y1 - y2;
double hsinX = Math.sin(diffX * 0.5);
double hsinY = Math.sin(diffY * 0.5);
double h = hsinX * hsinX +
(Math.cos(x1) * Math.cos(x2) * hsinY * hsinY);
double h = hsinY * hsinY +
(Math.cos(y1) * Math.cos(y2) * hsinX * hsinX);
result = (radius * 2 * Math.atan2(Math.sqrt(h), Math.sqrt(1 - h)));
}
return result;

View File

@ -76,22 +76,22 @@ public class HaversineFunction extends ValueSource {
double[] p2D = new double[2];
p1DV.doubleVal(doc, p1D);
p2DV.doubleVal(doc, p2D);
double x1;
double y1;
double x2;
double x1;
double y2;
double x2;
if (convertToRadians) {
x1 = p1D[0] * DistanceUtils.DEGREES_TO_RADIANS;
y1 = p1D[1] * DistanceUtils.DEGREES_TO_RADIANS;
x2 = p2D[0] * DistanceUtils.DEGREES_TO_RADIANS;
y2 = p2D[1] * DistanceUtils.DEGREES_TO_RADIANS;
y1 = p1D[0] * DistanceUtils.DEGREES_TO_RADIANS;
x1 = p1D[1] * DistanceUtils.DEGREES_TO_RADIANS;
y2 = p2D[0] * DistanceUtils.DEGREES_TO_RADIANS;
x2 = p2D[1] * DistanceUtils.DEGREES_TO_RADIANS;
} else {
x1 = p1D[0];
y1 = p1D[1];
x2 = p2D[0];
y2 = p2D[1];
y1 = p1D[0];
x1 = p1D[1];
y2 = p2D[0];
x2 = p2D[1];
}
return DistanceUtils.haversine(x1, y1, x2, y2, radius);
return DistanceUtils.haversine(y1, x1, y2, x2, radius);
}