lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jpou...@apache.org
Subject svn commit: r1569835 - in /lucene/dev/trunk/lucene: CHANGES.txt core/src/java/org/apache/lucene/util/SloppyMath.java
Date Wed, 19 Feb 2014 17:28:54 GMT
Author: jpountz
Date: Wed Feb 19 17:28:53 2014
New Revision: 1569835

URL: http://svn.apache.org/r1569835
Log:
LUCENE-5457: Expose SloppyMath earth diameter table

Modified:
    lucene/dev/trunk/lucene/CHANGES.txt
    lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/SloppyMath.java

Modified: lucene/dev/trunk/lucene/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/CHANGES.txt?rev=1569835&r1=1569834&r2=1569835&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/CHANGES.txt (original)
+++ lucene/dev/trunk/lucene/CHANGES.txt Wed Feb 19 17:28:53 2014
@@ -177,6 +177,10 @@ New Features
   representations of a shape into BinaryDocValues. It supports exact geometry
   relationship calculations. (David Smiley)
 
+* LUCENE-5457: Add SloppyMath.earthDiameter(double latitude) that returns an
+  approximate value of the diameter of the earth at the given latitude.
+  (Adrien Grand)
+
 Build
 
 * LUCENE-5217,LUCENE-5420: Maven config: get dependencies from Ant+Ivy config;

Modified: lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/SloppyMath.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/SloppyMath.java?rev=1569835&r1=1569834&r2=1569835&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/SloppyMath.java (original)
+++ lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/SloppyMath.java Wed Feb 19
17:28:53 2014
@@ -48,11 +48,10 @@ public class SloppyMath {
     double h2 = 1 - cos((lon1 - lon2) * TO_RADIANS);
     double h = (h1 + cos(x1) * cos(x2) * h2) / 2;
 
-    double avgLat = Math.abs((x1 + x2) / 2d);
-    int index = (int)(avgLat * RADIUS_INDEXER + 0.5) % earthDiameterPerLatitude.length;
-    double radius = earthDiameterPerLatitude[index];
+    double avgLat = (x1 + x2) / 2d;
+    double diameter = earthDiameter(avgLat);
 
-    return radius * asin(Math.min(1, Math.sqrt(h)));
+    return diameter * asin(Math.min(1, Math.sqrt(h)));
     
   }
 
@@ -137,7 +136,13 @@ public class SloppyMath {
       }
     }
   }
-  
+
+  /** Return an approximate value of the diameter of the earth at the given latitude, in
kilometers. */
+  public static double earthDiameter(double latitude) {
+    final int index = (int)(Math.abs(latitude) * RADIUS_INDEXER + 0.5) % earthDiameterPerLatitude.length;
+    return earthDiameterPerLatitude[index];
+  }
+
   // haversin
   private static final double TO_RADIANS = Math.PI / 180D;
   



Mime
View raw message