GeoPoint: cheaper range limiting

This commit is contained in:
Hannes Janetzek 2014-02-09 17:03:24 +01:00
parent 87f4277b8b
commit 83b914d1b2

View File

@ -17,6 +17,8 @@
*/ */
package org.oscim.core; package org.oscim.core;
import org.oscim.utils.FastMath;
/** /**
* A GeoPoint represents an immutable pair of latitude and longitude * A GeoPoint represents an immutable pair of latitude and longitude
* coordinates. * coordinates.
@ -43,19 +45,22 @@ public class GeoPoint implements Comparable<GeoPoint> {
private int hashCodeValue = 0; private int hashCodeValue = 0;
/** /**
* @param latitude * @param lat
* the latitude in degrees, will be limited to the possible * the latitude in degrees, will be limited to the possible
* latitude range. * latitude range.
* @param longitude * @param lon
* the longitude in degrees, will be limited to the possible * the longitude in degrees, will be limited to the possible
* longitude range. * longitude range.
*/ */
public GeoPoint(double latitude, double longitude) { public GeoPoint(double lat, double lon) {
double limitLatitude = MercatorProjection.limitLatitude(latitude); lat = FastMath.clamp(lat,
this.latitudeE6 = (int) (limitLatitude * CONVERSION_FACTOR); MercatorProjection.LATITUDE_MIN,
MercatorProjection.LATITUDE_MAX);
double limitLongitude = MercatorProjection.limitLongitude(longitude); this.latitudeE6 = (int) (lat * CONVERSION_FACTOR);
this.longitudeE6 = (int) (limitLongitude * CONVERSION_FACTOR); lon = FastMath.clamp(lon,
MercatorProjection.LONGITUDE_MIN,
MercatorProjection.LONGITUDE_MAX);
this.longitudeE6 = (int) (lon * CONVERSION_FACTOR);
} }
/** /**