Remove some duplicate codes and magic numbers
This commit is contained in:
parent
c78b56645c
commit
5a62480bd3
9 changed files with 128 additions and 120 deletions
|
|
@ -15,9 +15,9 @@ public final class CheapRulerSingleton {
|
|||
private static volatile CheapRulerSingleton instance = null;
|
||||
|
||||
// Conversion constants
|
||||
private final static double ILATLNG_TO_LATLNG = 1e-6; // From integer to degrees
|
||||
private final static int KILOMETERS_TO_METERS = 1000;
|
||||
private final static double DEG_TO_RAD = Math.PI / 180.;
|
||||
public final static double ILATLNG_TO_LATLNG = 1e-6; // From integer to degrees
|
||||
public final static int KILOMETERS_TO_METERS = 1000;
|
||||
public final static double DEG_TO_RAD = Math.PI / 180.;
|
||||
|
||||
// Cosine cache constants
|
||||
private final static int COS_CACHE_LENGTH = 8192;
|
||||
|
|
@ -58,7 +58,7 @@ public final class CheapRulerSingleton {
|
|||
/**
|
||||
* Helper to compute the cosine of an integer latitude.
|
||||
*/
|
||||
private double cosLat(int ilat) {
|
||||
public double cosIlat(int ilat) {
|
||||
double latDegrees = ilat * ILATLNG_TO_LATLNG;
|
||||
if (ilat > 90000000) {
|
||||
// Use the symmetry of the cosine.
|
||||
|
|
@ -67,6 +67,16 @@ public final class CheapRulerSingleton {
|
|||
return COS_CACHE[(int) (latDegrees * COS_CACHE_LENGTH / COS_CACHE_MAX_DEGREES)];
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper to compute the cosine of a latitude (in degrees).
|
||||
*/
|
||||
public double cosLat(double lat) {
|
||||
if (lat < 0) {
|
||||
lat += 90.;
|
||||
}
|
||||
return COS_CACHE[(int) (lat * COS_CACHE_LENGTH / COS_CACHE_MAX_DEGREES)];
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute the distance (in meters) between two points represented by their
|
||||
* (integer) latitude and longitude.
|
||||
|
|
@ -80,7 +90,7 @@ public final class CheapRulerSingleton {
|
|||
* Integer latitude is ((latitude in degrees) + 90) * 1e6.
|
||||
*/
|
||||
public double distance(int ilon1, int ilat1, int ilon2, int ilat2) {
|
||||
double cos = cosLat(ilat1);
|
||||
double cos = cosIlat(ilat1);
|
||||
double cos2 = 2 * cos * cos - 1;
|
||||
double cos3 = 2 * cos * cos2 - cos;
|
||||
double cos4 = 2 * cos * cos3 - cos2;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue