You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by rm...@apache.org on 2016/04/19 01:48:00 UTC

lucene-solr:master: LUCENE-7185: fix buggy worst-case error and add test for absurd distances

Repository: lucene-solr
Updated Branches:
  refs/heads/master 4ac2546e5 -> b83932574


LUCENE-7185: fix buggy worst-case error and add test for absurd distances


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/b8393257
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/b8393257
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/b8393257

Branch: refs/heads/master
Commit: b839325740f9487bf30c74b649993c7e400a2aaa
Parents: 4ac2546
Author: Robert Muir <rm...@apache.org>
Authored: Mon Apr 18 19:47:22 2016 -0400
Committer: Robert Muir <rm...@apache.org>
Committed: Mon Apr 18 19:47:22 2016 -0400

----------------------------------------------------------------------
 .../java/org/apache/lucene/util/SloppyMath.java |  2 +-
 .../org/apache/lucene/util/TestSloppyMath.java  | 23 +++++++++++++++++---
 2 files changed, 21 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/b8393257/lucene/core/src/java/org/apache/lucene/util/SloppyMath.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/util/SloppyMath.java b/lucene/core/src/java/org/apache/lucene/util/SloppyMath.java
index 7be9be1..0bfca5e 100644
--- a/lucene/core/src/java/org/apache/lucene/util/SloppyMath.java
+++ b/lucene/core/src/java/org/apache/lucene/util/SloppyMath.java
@@ -37,7 +37,7 @@ public class SloppyMath {
    * specified in decimal degrees (latitude/longitude).  This works correctly
    * even if the dateline is between the two points.
    * <p>
-   * Error is at most 2E-1 (20cm) from the actual haversine distance, but is typically
+   * Error is at most 4E-1 (40cm) from the actual haversine distance, but is typically
    * much smaller for reasonable distances: around 1E-5 (0.01mm) for distances less than
    * 1000km.
    *

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/b8393257/lucene/core/src/test/org/apache/lucene/util/TestSloppyMath.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/util/TestSloppyMath.java b/lucene/core/src/test/org/apache/lucene/util/TestSloppyMath.java
index 6a2eb86..488f00e 100644
--- a/lucene/core/src/test/org/apache/lucene/util/TestSloppyMath.java
+++ b/lucene/core/src/test/org/apache/lucene/util/TestSloppyMath.java
@@ -33,7 +33,7 @@ public class TestSloppyMath extends LuceneTestCase {
   // accuracy for asin()
   static double ASIN_DELTA = 1E-7;
   // accuracy for haversinMeters()
-  static double HAVERSIN_DELTA = 2E-1;
+  static double HAVERSIN_DELTA = 38E-2;
   // accuracy for haversinMeters() for "reasonable" distances (< 1000km)
   static double REASONABLE_HAVERSIN_DELTA = 1E-5;
   
@@ -161,11 +161,28 @@ public class TestSloppyMath extends LuceneTestCase {
       double lat2 = GeoTestUtil.nextLatitude();
       double lon2 = GeoTestUtil.nextLongitude();
 
-      double expected = haversinMeters(lat1, lon1, lat2, lon2);
-      double actual = slowHaversin(lat1, lon1, lat2, lon2);
+      double expected = slowHaversin(lat1, lon1, lat2, lon2);
+      double actual = haversinMeters(lat1, lon1, lat2, lon2);
       assertEquals(expected, actual, HAVERSIN_DELTA);
     }
   }
+
+  /**
+   * Step across the whole world to find huge absolute errors.
+   * Don't rely on random number generator to pick these massive distances. */
+  public void testAcrossWholeWorldSteps() {
+    for (int lat1 = -90; lat1 <= 90; lat1 += 10) {
+      for (int lon1 = -180; lon1 <= 180; lon1 += 10) {
+        for (int lat2 = -90; lat2 <= 90; lat2 += 10) {
+          for (int lon2 = -180; lon2 <= 180; lon2 += 10) {
+            double expected = slowHaversin(lat1, lon1, lat2, lon2);
+            double actual = haversinMeters(lat1, lon1, lat2, lon2);
+            assertEquals(expected, actual, HAVERSIN_DELTA);
+          }
+        }
+      }
+    }
+  }
   
   public void testAgainstSlowVersionReasonable() {
     for (int i = 0; i < 100_000; i++) {