summaryrefslogtreecommitdiff
path: root/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry
diff options
context:
space:
mode:
authorTobrun <tobrun@mapbox.com>2016-02-02 11:21:47 +0100
committerTobrun <tobrun@mapbox.com>2016-02-02 17:25:46 +0100
commit6dff169f2b2085f1de2b6c568f61b3d506b9374b (patch)
tree246bc43212c7bda0719454df0df5e1c42d562ba4 /platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry
parenta699690c1689222f518b5d7adc0dfd059884ac49 (diff)
downloadqtlocation-mapboxgl-6dff169f2b2085f1de2b6c568f61b3d506b9374b.tar.gz
[android] #3754 - newLatLngBounds: unit tests for LatLng and LatLngBounds, builder pattern + refactoring.
[android] #3754 - Working version using the underlying VisibleCoorindateBounds [android] #3754 - refactor Camera api inside maps package, correctly use factory pattern, LatLngBounds hooks into camera API [android] #3754 - cleanup old API
Diffstat (limited to 'platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry')
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/CoordinateBounds.java93
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/CoordinateRegion.java64
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/LatLngBounds.java90
3 files changed, 46 insertions, 201 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/CoordinateBounds.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/CoordinateBounds.java
deleted file mode 100644
index fefc2502d3..0000000000
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/CoordinateBounds.java
+++ /dev/null
@@ -1,93 +0,0 @@
-package com.mapbox.mapboxsdk.geometry;
-
-import android.os.Parcel;
-import android.os.Parcelable;
-import android.support.annotation.NonNull;
-
-/**
- * A rectangular geograpical region defined by a south west {@link LatLng} and a north east {@link LatLng}.
- */
-public class CoordinateBounds implements Parcelable {
-
- private LatLng mSouthWest;
- private LatLng mNorthEast;
-
- public CoordinateBounds(@NonNull Parcel in) {
- mSouthWest = in.readParcelable(LatLng.class.getClassLoader());
- mNorthEast = in.readParcelable(LatLng.class.getClassLoader());
- }
-
- public CoordinateBounds(@NonNull LatLng southWest, @NonNull LatLng northEast) {
- mSouthWest = southWest;
- mNorthEast = northEast;
- }
-
- @NonNull
- public LatLng getSouthWest() {
- return mSouthWest;
- }
-
- public void setSouthWest(@NonNull LatLng mSouthWest) {
- this.mSouthWest = mSouthWest;
- }
-
- @NonNull
- public LatLng getNorthEast() {
- return mNorthEast;
- }
-
- public void setNorthEast(@NonNull LatLng mNorthEast) {
- this.mNorthEast = mNorthEast;
- }
-
- @Override
- public int hashCode() {
- int result;
- long temp;
- temp = mSouthWest.hashCode();
- result = (int) (temp ^ (temp >>> 32));
- temp = mNorthEast.hashCode();
- result = 31 * result + (int) (temp ^ (temp >>> 32));
- return result;
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) return true;
- if (o instanceof CoordinateBounds) {
- CoordinateBounds other = (CoordinateBounds) o;
- return getNorthEast().equals(other.getNorthEast())
- && getSouthWest().equals(other.getSouthWest());
- }
- return false;
- }
-
- @Override
- public String toString() {
- return "CoordinateBounds [mNorthEast[" + getNorthEast() + "], mSouthWest[]" + getSouthWest() + "]";
- }
-
- public static final Parcelable.Creator<CoordinateBounds> CREATOR =
- new Parcelable.Creator<CoordinateBounds>() {
- @Override
- public CoordinateBounds createFromParcel(Parcel in) {
- return new CoordinateBounds(in);
- }
-
- @Override
- public CoordinateBounds[] newArray(int size) {
- return new CoordinateBounds[size];
- }
- };
-
- @Override
- public int describeContents() {
- return 0;
- }
-
- @Override
- public void writeToParcel(Parcel out, int arg1) {
- out.writeParcelable(mSouthWest, arg1);
- out.writeParcelable(mNorthEast, arg1);
- }
-}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/CoordinateRegion.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/CoordinateRegion.java
deleted file mode 100644
index c7c0aa1c49..0000000000
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/CoordinateRegion.java
+++ /dev/null
@@ -1,64 +0,0 @@
-package com.mapbox.mapboxsdk.geometry;
-
-import android.os.Parcel;
-import android.os.Parcelable;
-import android.support.annotation.NonNull;
-
-/**
- * A geographical region defined by a {@link LatLng} and a {@link CoordinateSpan}.
- */
-public class CoordinateRegion implements Parcelable{
-
- private LatLng mCenter;
- private CoordinateSpan mSpan;
-
- public CoordinateRegion(@NonNull Parcel in){
- mCenter = in.readParcelable(LatLng.class.getClassLoader());
- mSpan = in.readParcelable(CoordinateSpan.class.getClassLoader());
- }
-
- public CoordinateRegion(@NonNull LatLng center, @NonNull CoordinateSpan span) {
- mCenter = center;
- mSpan = span;
- }
-
- public LatLng getCenter() {
- return mCenter;
- }
-
- public void setCenter(@NonNull LatLng center) {
- mCenter = center;
- }
-
- public CoordinateSpan getSpan() {
- return mSpan;
- }
-
- public void setSpan(@NonNull CoordinateSpan span) {
- this.mSpan = span;
- }
-
- public static final Parcelable.Creator<CoordinateRegion> CREATOR =
- new Parcelable.Creator<CoordinateRegion>() {
- @Override
- public CoordinateRegion createFromParcel(Parcel in) {
- return new CoordinateRegion(in);
- }
-
- @Override
- public CoordinateRegion[] newArray(int size) {
- return new CoordinateRegion[size];
- }
- };
-
- @Override
- public int describeContents() {
- return 0;
- }
-
- @Override
- public void writeToParcel(Parcel out, int arg1) {
- out.writeParcelable(mCenter, arg1);
- out.writeParcelable(mSpan, arg1);
- }
-}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/LatLngBounds.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/LatLngBounds.java
index 9cfa5997c4..17816a0776 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/LatLngBounds.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/LatLngBounds.java
@@ -2,7 +2,14 @@ package com.mapbox.mapboxsdk.geometry;
import android.os.Parcel;
import android.os.Parcelable;
+import android.support.annotation.NonNull;
+import android.support.annotation.Nullable;
+import com.mapbox.mapboxsdk.annotations.Icon;
+import com.mapbox.mapboxsdk.annotations.Marker;
+import com.mapbox.mapboxsdk.exceptions.InvalidLatLngBoundsException;
+
+import java.util.ArrayList;
import java.util.List;
/**
@@ -15,46 +22,20 @@ public class LatLngBounds implements Parcelable {
private final double mLonEast;
private final double mLonWest;
- private final boolean mIsValid;
-
/**
* Construct a new LatLngBounds based on its corners, given in NESW
* order.
*
* @param northLatitude Northern Latitude
- * @param eastLongitude Eastern Longitude
+ * @param eastLongitude Eastern Longitude
* @param southLatitude Southern Latitude
- * @param westLongitude Western Longitude
+ * @param westLongitude Western Longitude
*/
- public LatLngBounds(final double northLatitude, final double eastLongitude, final double southLatitude, final double westLongitude) {
+ LatLngBounds(final double northLatitude, final double eastLongitude, final double southLatitude, final double westLongitude) {
this.mLatNorth = northLatitude;
this.mLonEast = eastLongitude;
this.mLatSouth = southLatitude;
this.mLonWest = westLongitude;
- this.mIsValid = ((this.mLonWest < this.mLonEast) && (this.mLatNorth > this.mLatSouth));
- }
-
- /**
- * Construct a new LatLngBounds based on its corners, given in NESW order.
- *
- * @param northEast Coordinate
- * @param southWest Coordinate
- */
- public LatLngBounds(final LatLng northEast, final LatLng southWest) {
- this(northEast.getLatitude(), northEast.getLongitude(), southWest.getLatitude(), southWest.getLongitude());
- }
-
- /**
- * Create a LatLngBounds box from another LatLngBounds
- *
- * @param other the other LatLngBounds
- */
- public LatLngBounds(final LatLngBounds other) {
- this.mLatNorth = other.getLatNorth();
- this.mLonEast = other.getLonEast();
- this.mLatSouth = other.getLatSouth();
- this.mLonWest = other.getLonWest();
- this.mIsValid = other.isValid();
}
/**
@@ -84,10 +65,6 @@ public class LatLngBounds implements Parcelable {
return this.mLonWest;
}
- public boolean isValid() {
- return this.mIsValid;
- }
-
/**
* Get the area spanned by this LatLngBounds
*
@@ -123,7 +100,7 @@ public class LatLngBounds implements Parcelable {
*
* @return boolean indicating if span is empty
*/
- public boolean isEmpty() {
+ public boolean isEmptySpan() {
return getLongitudeSpan() == 0.0 || getLatitudeSpan() == 0.0;
}
@@ -139,7 +116,7 @@ public class LatLngBounds implements Parcelable {
* @param latLngs List of LatLng objects
* @return LatLngBounds
*/
- public static LatLngBounds fromLatLngs(final List<? extends ILatLng> latLngs) {
+ static LatLngBounds fromLatLngs(final List<? extends ILatLng> latLngs) {
double minLat = 90,
minLon = 180,
maxLat = -90,
@@ -158,6 +135,10 @@ public class LatLngBounds implements Parcelable {
return new LatLngBounds(maxLat, maxLon, minLat, minLon);
}
+ public LatLng[] toLatLngs(){
+ return new LatLng[]{new LatLng(mLatNorth,mLonEast),new LatLng(mLatSouth,mLonWest)};
+ }
+
/**
* Determines whether this LatLngBounds matches another one via LatLng.
*
@@ -167,8 +148,8 @@ public class LatLngBounds implements Parcelable {
@Override
public boolean equals(final Object o) {
if (this == o) return true;
- if (o instanceof BoundingBox) {
- BoundingBox other = (BoundingBox) o;
+ if (o instanceof LatLngBounds) {
+ LatLngBounds other = (LatLngBounds) o;
return mLatNorth == other.getLatNorth()
&& mLatSouth == other.getLatSouth()
&& mLonEast == other.getLonEast()
@@ -184,7 +165,7 @@ public class LatLngBounds implements Parcelable {
* @param latLng the point which may be contained
* @return true, if the point is contained within the box.
*/
- public boolean contains(final ILatLng latLng) {
+ public boolean including(final ILatLng latLng) {
final double latitude = latLng.getLatitude();
final double longitude = latLng.getLongitude();
return ((latitude < this.mLatNorth)
@@ -242,14 +223,14 @@ public class LatLngBounds implements Parcelable {
/**
* Returns a new LatLngBounds that is the intersection of this with another LatLngBounds
*
- * @param northLongitude Northern Longitude
- * @param eastLatitude Eastern Latitude
- * @param southLongitude Southern Longitude
- * @param westLatitude Western Latitude
+ * @param northLatitude Northern Longitude
+ * @param eastLongitude Eastern Latitude
+ * @param southLatitude Southern Longitude
+ * @param westLongitude Western Latitude
* @return LatLngBounds
*/
- public LatLngBounds intersect(double northLongitude, double eastLatitude, double southLongitude, double westLatitude) {
- return intersect(new LatLngBounds(northLongitude, eastLatitude, southLongitude, westLatitude));
+ public LatLngBounds intersect(double northLatitude, double eastLongitude, double southLatitude, double westLongitude) {
+ return intersect(new LatLngBounds(northLatitude, eastLongitude, southLatitude, westLongitude));
}
public static final Parcelable.Creator<LatLngBounds> CREATOR =
@@ -293,4 +274,25 @@ public class LatLngBounds implements Parcelable {
final double latWest = in.readDouble();
return new LatLngBounds(lonNorth, latEast, lonSouth, latWest);
}
+
+ public static final class Builder {
+
+ private List<LatLng> mLatLngList;
+
+ public Builder() {
+ mLatLngList = new ArrayList<>();
+ }
+
+ public LatLngBounds build() {
+ if (mLatLngList.size() < 2) {
+ throw new InvalidLatLngBoundsException(mLatLngList.size());
+ }
+ return LatLngBounds.fromLatLngs(mLatLngList);
+ }
+
+ public Builder include(@NonNull LatLng latLng) {
+ mLatLngList.add(latLng);
+ return this;
+ }
+ }
}