Tidy up JNI LatLng refs

This commit is contained in:
Leith Bade
2015-02-16 12:20:07 -08:00
parent d5b8d57a7f
commit 4daa02987b
6 changed files with 140 additions and 138 deletions

View File

@@ -41,34 +41,31 @@ public class LatLngZoom extends LatLng implements Parcelable {
this.zoom = zoom;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (!super.equals(o)) return false;
LatLngZoom that = (LatLngZoom) o;
if (Double.compare(that.zoom, zoom) != 0) return false;
return true;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
int result = super.hashCode();
long temp;
temp = super.hashCode();
result = prime * result + (int) (temp ^ (temp >>> 32));
temp = Double.doubleToLongBits(zoom);
result = 31 * result + (int) (temp ^ (temp >>> 32));
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
LatLngZoom other = (LatLngZoom) obj;
return super.equals(obj) && Double.doubleToLongBits(zoom) == Double.doubleToLongBits(other.zoom);
}
@Override
public String toString() {
return "LatLngZoom [lat=" + super.getLatitude() + ", lon=" + super.getLongitude() + ", zoom=" + zoom + "]";
return "LatLngZoom [latitude=" + super.getLatitude() + ", longitude=" + super.getLongitude() + ", altitude=" + super.getAltitude() + ", zoom=" + zoom + "]";
}
@Override

View File

@@ -248,11 +248,11 @@ class NativeMapView {
}
public void setLatLng(LatLng latLng, long duration) {
nativeSetLonLat(mNativeMapViewPtr, latLng, duration);
nativeSetLatLng(mNativeMapViewPtr, latLng, duration);
}
public LatLng getLatLng() {
return nativeGetLonLat(mNativeMapViewPtr);
return nativeGetLatLng(mNativeMapViewPtr);
}
public void startPanning() {
@@ -307,16 +307,16 @@ class NativeMapView {
return nativeGetZoom(mNativeMapViewPtr);
}
public void setLatLngZoom(LatLngZoom lonLatZoom) {
setLatLngZoom(lonLatZoom, 0);
public void setLatLngZoom(LatLngZoom latLngZoom) {
setLatLngZoom(latLngZoom, 0);
}
public void setLatLngZoom(LatLngZoom lonLatZoom, long duration) {
nativeSetLonLatZoom(mNativeMapViewPtr, lonLatZoom, duration);
public void setLatLngZoom(LatLngZoom latLngZoom, long duration) {
nativeSetLatLngZoom(mNativeMapViewPtr, latLngZoom, duration);
}
public LatLngZoom getLatLngZoom() {
return nativeGetLonLatZoom(mNativeMapViewPtr);
return nativeGetLatLngZoom(mNativeMapViewPtr);
}
public void resetZoom() {
@@ -490,10 +490,10 @@ class NativeMapView {
private native void nativeMoveBy(long nativeMapViewPtr, double dx,
double dy, long duration);
private native void nativeSetLonLat(long nativeMapViewPtr, LatLng latLng,
private native void nativeSetLatLng(long nativeMapViewPtr, LatLng latLng,
long duration);
private native LatLng nativeGetLonLat(long nativeMapViewPtr);
private native LatLng nativeGetLatLng(long nativeMapViewPtr);
private native void nativeStartPanning(long nativeMapViewPtr);
@@ -514,10 +514,10 @@ class NativeMapView {
private native double nativeGetZoom(long nativeMapViewPtr);
private native void nativeSetLonLatZoom(long nativeMapViewPtr,
private native void nativeSetLatLngZoom(long nativeMapViewPtr,
LatLngZoom lonLatZoom, long duration);
private native LatLngZoom nativeGetLonLatZoom(long nativeMapViewPtr);
private native LatLngZoom nativeGetLatLngZoom(long nativeMapViewPtr);
private native void nativeResetZoom(long nativeMapViewPtr);

View File

@@ -1,8 +1,8 @@
package com.mapbox.mapboxgl.lib.constants;
public interface MathConstants {
public static final float DEG2RAD = (float) (Math.PI / 180.0);
public static final float RAD2DEG = (float) (180.0 / Math.PI);
public static final double DEG2RAD = (Math.PI / 180.0);
public static final double RAD2DEG = (180.0 / Math.PI);
public static final float PI = (float) Math.PI;
public static final double PI = Math.PI;
}

View File

@@ -19,9 +19,9 @@ public class LatLng implements ILatLng, GeoConstants, MathConstants, Parcelable,
}
};
private double longitude;
private double latitude;
private double altitude = 0f;
private double longitude;
private double altitude = 0.0;
/**
* Construct a new latitude, longitude point given float arguments
@@ -85,30 +85,35 @@ public class LatLng implements ILatLng, GeoConstants, MathConstants, Parcelable,
}
@Override
public boolean equals(final Object obj) {
if (obj == null) {
return false;
}
if (obj == this) {
return true;
}
if (!obj.getClass().equals(this.getClass())) {
return false;
}
final LatLng rhs = (LatLng) obj;
return rhs.latitude == this.latitude
&& rhs.longitude == this.longitude
&& rhs.altitude == this.altitude;
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
LatLng latLng = (LatLng) o;
if (Double.compare(latLng.altitude, altitude) != 0) return false;
if (Double.compare(latLng.latitude, latitude) != 0) return false;
if (Double.compare(latLng.longitude, longitude) != 0) return false;
return true;
}
@Override
public int hashCode() {
return (int) (37.0 * (17.0 * latitude * 1E6d + longitude * 1E6d) + altitude);
int result;
long temp;
temp = Double.doubleToLongBits(latitude);
result = (int) (temp ^ (temp >>> 32));
temp = Double.doubleToLongBits(longitude);
result = 31 * result + (int) (temp ^ (temp >>> 32));
temp = Double.doubleToLongBits(altitude);
result = 31 * result + (int) (temp ^ (temp >>> 32));
return result;
}
@Override
public String toString() {
return "LatLng [longitude=" + longitude + ", latitude=" + latitude + "]";
return "LatLng [longitude=" + longitude + ", latitude=" + latitude + ", altitude=" + altitude + "]";
}
@Override
@@ -128,7 +133,7 @@ public class LatLng implements ILatLng, GeoConstants, MathConstants, Parcelable,
* @param other Other LatLng to compare to
* @return distance in meters
*/
public int distanceTo(final LatLng other) {
public double distanceTo(final LatLng other) {
final double a1 = DEG2RAD * this.latitude;
final double a2 = DEG2RAD * this.longitude;
@@ -143,6 +148,6 @@ public class LatLng implements ILatLng, GeoConstants, MathConstants, Parcelable,
final double t3 = Math.sin(a1) * Math.sin(b1);
final double tt = Math.acos(t1 + t2 + t3);
return (int) (RADIUS_EARTH_METERS * tt);
return RADIUS_EARTH_METERS * tt;
}
}