diff --git a/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/CoordinateBounds.java b/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/CoordinateBounds.java index f4d9caedc..e5b4b2fdc 100644 --- a/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/CoordinateBounds.java +++ b/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/CoordinateBounds.java @@ -5,27 +5,54 @@ package com.mapbox.mapboxsdk.geometry; */ public class CoordinateBounds { - private LatLng sw; - private LatLng ne; + private LatLng southWest; + private LatLng northEast; - public CoordinateBounds(LatLng sw, LatLng ne) { - this.sw = sw; - this.ne = ne; + public CoordinateBounds(LatLng southWest, LatLng northEast) { + this.southWest = southWest; + this.northEast = northEast; } - public LatLng getSw() { - return sw; + public LatLng getSouthWest() { + return southWest; } - public void setSw(LatLng sw) { - this.sw = sw; + public void setSouthWest(LatLng southWest) { + this.southWest = southWest; } - public LatLng getNe() { - return ne; + public LatLng getNorthEast() { + return northEast; } - public void setNe(LatLng ne) { - this.ne = ne; + public void setNorthEast(LatLng northEast) { + this.northEast = northEast; + } + + @Override + public int hashCode() { + int result; + long temp; + temp = southWest.hashCode(); + result = (int) (temp ^ (temp >>> 32)); + temp = northEast.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() == other.getSouthWest(); + } + return false; + } + + @Override + public String toString() { + return "CoordinateBounds [northEast[" + getNorthEast() + "], southWest[]" + getSouthWest() + "]"; } } diff --git a/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/MapView.java b/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/MapView.java index 2c12f378b..bf4d23656 100644 --- a/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/MapView.java +++ b/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/MapView.java @@ -2019,10 +2019,10 @@ public final class MapView extends FrameLayout { @UiThread public void setVisibleCoordinateBounds(@NonNull CoordinateBounds bounds, @NonNull RectF padding, boolean animated) { LatLng[] coordinates = { - new LatLng(bounds.getNe().getLatitude(), bounds.getSw().getLongitude()), - bounds.getSw(), - new LatLng(bounds.getSw().getLatitude(), bounds.getNe().getLongitude()), - bounds.getNe() + new LatLng(bounds.getNorthEast().getLatitude(), bounds.getSouthWest().getLongitude()), + bounds.getSouthWest(), + new LatLng(bounds.getSouthWest().getLatitude(), bounds.getNorthEast().getLongitude()), + bounds.getNorthEast() }; setVisibleCoordinateBounds(coordinates, padding, animated); diff --git a/android/java/MapboxGLAndroidSDKTestApp/src/test/java/CoordinateBoundsTest.java b/android/java/MapboxGLAndroidSDKTestApp/src/test/java/CoordinateBoundsTest.java new file mode 100644 index 000000000..a5d389130 --- /dev/null +++ b/android/java/MapboxGLAndroidSDKTestApp/src/test/java/CoordinateBoundsTest.java @@ -0,0 +1,58 @@ +import com.mapbox.mapboxsdk.geometry.CoordinateBounds; +import com.mapbox.mapboxsdk.geometry.LatLng; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +public class CoordinateBoundsTest { + + @Test + public void testSanity() { + CoordinateBounds coordinateBounds = new CoordinateBounds(null, null); + assertNotNull("coordinateBounds should not be null", coordinateBounds); + } + + @Test + public void testSouthWestConstructor() { + LatLng southWest = new LatLng(12, 12); + CoordinateBounds coordinateBounds = new CoordinateBounds(southWest, null); + assertEquals("southWest should match", southWest, coordinateBounds.getSouthWest()); + } + + @Test + public void testNorthEastConstructor() { + LatLng northEast = new LatLng(12, 12); + CoordinateBounds coordinateBounds = new CoordinateBounds(null, northEast); + assertEquals("northEast should match", northEast, coordinateBounds.getNorthEast()); + } + + @Test + public void testHashCode() { + LatLng northEast = new LatLng(60, 60); + LatLng southWest = new LatLng(43, 26); + CoordinateBounds coordinateBounds = new CoordinateBounds(northEast, southWest); + assertEquals("hash code should match", coordinateBounds.hashCode(), -1515487232); + } + + @Test + public void testToString() { + LatLng northEast = new LatLng(60, 60); + LatLng southWest = new LatLng(43, 26); + CoordinateBounds coordinateBounds = new CoordinateBounds(northEast, southWest); + assertEquals("string should match", + coordinateBounds.toString(), + "CoordinateBounds [northEast[" + coordinateBounds.getNorthEast() + "], southWest[]" + coordinateBounds.getSouthWest() + "]"); + } + + @Test + public void testEquals() { + LatLng northEast = new LatLng(60, 60); + LatLng southWest = new LatLng(43, 26); + CoordinateBounds firstBounds = new CoordinateBounds(northEast, southWest); + CoordinateBounds sameBounds = new CoordinateBounds(northEast, southWest); + assertTrue(firstBounds.equals(sameBounds)); + } +}