You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ho...@apache.org on 2011/11/29 23:38:09 UTC

svn commit: r1208118 - in /lucene/dev/trunk: lucene/contrib/CHANGES.txt lucene/contrib/spatial/src/java/org/apache/lucene/spatial/DistanceUtils.java solr/core/src/java/org/apache/solr/search/function/distance/HaversineFunction.java

Author: hossman
Date: Tue Nov 29 22:38:08 2011
New Revision: 1208118

URL: http://svn.apache.org/viewvc?rev=1208118&view=rev
Log:
LUCENE-3599: Fix DistanceUtils.haversine() javadocs -- were incorrectly stating the expected order of the arguments

Modified:
    lucene/dev/trunk/lucene/contrib/CHANGES.txt
    lucene/dev/trunk/lucene/contrib/spatial/src/java/org/apache/lucene/spatial/DistanceUtils.java
    lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/function/distance/HaversineFunction.java

Modified: lucene/dev/trunk/lucene/contrib/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/contrib/CHANGES.txt?rev=1208118&r1=1208117&r2=1208118&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/contrib/CHANGES.txt (original)
+++ lucene/dev/trunk/lucene/contrib/CHANGES.txt Tue Nov 29 22:38:08 2011
@@ -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

Modified: lucene/dev/trunk/lucene/contrib/spatial/src/java/org/apache/lucene/spatial/DistanceUtils.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/contrib/spatial/src/java/org/apache/lucene/spatial/DistanceUtils.java?rev=1208118&r1=1208117&r2=1208118&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/contrib/spatial/src/java/org/apache/lucene/spatial/DistanceUtils.java (original)
+++ lucene/dev/trunk/lucene/contrib/spatial/src/java/org/apache/lucene/spatial/DistanceUtils.java Tue Nov 29 22:38:08 2011
@@ -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;

Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/function/distance/HaversineFunction.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/function/distance/HaversineFunction.java?rev=1208118&r1=1208117&r2=1208118&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/function/distance/HaversineFunction.java (original)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/function/distance/HaversineFunction.java Tue Nov 29 22:38:08 2011
@@ -76,22 +76,22 @@ public class HaversineFunction extends V
     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);
   }