[android] #3758 - Projection / Visible Region implementation.
[android] #3758 - add VisibleRegion + unit tests, removed boundingbox, cleanup jni, cleanup test app, renamed CoordinateSpan to LatLng.
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
package com.mapbox.mapboxsdk.geometry;
|
||||
|
||||
import com.mapbox.mapboxsdk.annotations.Marker;
|
||||
import com.mapbox.mapboxsdk.annotations.MarkerOptions;
|
||||
import com.mapbox.mapboxsdk.exceptions.InvalidLatLngBoundsException;
|
||||
|
||||
import org.junit.Before;
|
||||
@@ -58,8 +56,8 @@ public class LatLngBoundsTest {
|
||||
|
||||
@Test
|
||||
public void testCoordinateSpan() {
|
||||
CoordinateSpan coordinateSpan = mLatLngBounds.getSpan();
|
||||
assertEquals("CoordinateSpan should be the same", new CoordinateSpan(2, 2), coordinateSpan);
|
||||
LatLngSpan latLngSpan = mLatLngBounds.getSpan();
|
||||
assertEquals("LatLngSpan should be the same", new LatLngSpan(2, 2), latLngSpan);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
package com.mapbox.mapboxsdk.geometry;
|
||||
|
||||
import com.mapbox.mapboxsdk.geometry.LatLngSpan;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
public class LatLngSpanTest {
|
||||
|
||||
private static final double DELTA = 1e-15;
|
||||
|
||||
@Test
|
||||
public void testSanity() {
|
||||
LatLngSpan latLngSpan = new LatLngSpan(0.0, 0.0);
|
||||
assertNotNull("latLngSpan should not be null", latLngSpan);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLatitudeConstructor() {
|
||||
double latitude = 1.23;
|
||||
LatLngSpan latLngSpan = new LatLngSpan(latitude, 0.0);
|
||||
assertEquals("latitude in constructor", latLngSpan.getLatitudeSpan(), latitude, DELTA);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLongitudeConstructor() {
|
||||
double longitude = 1.23;
|
||||
LatLngSpan latLngSpan = new LatLngSpan(0.0, longitude);
|
||||
assertEquals("latitude in constructor", latLngSpan.getLongitudeSpan(), longitude, DELTA);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLatitudeMethod() {
|
||||
double latitude = 1.23;
|
||||
LatLngSpan latLngSpan = new LatLngSpan(0.0, 0.0);
|
||||
latLngSpan.setLatitudeSpan(latitude);
|
||||
assertEquals("latitude in constructor", latLngSpan.getLatitudeSpan(), latitude, DELTA);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLongitudeMethod() {
|
||||
double longitude = 1.23;
|
||||
LatLngSpan latLngSpan = new LatLngSpan(0.0, 0.0);
|
||||
latLngSpan.setLongitudeSpan(longitude);
|
||||
assertEquals("latitude in constructor", latLngSpan.getLongitudeSpan(), longitude, DELTA);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.mapbox.mapboxsdk.maps;
|
||||
package com.mapbox.mapboxsdk.geometry;
|
||||
|
||||
import com.mapbox.mapboxsdk.geometry.ProjectedMeters;
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
package com.mapbox.mapboxsdk.geometry;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
public class VisibleRegionTest {
|
||||
|
||||
private static final LatLng FAR_LEFT = new LatLng(52, -12);
|
||||
private static final LatLng NEAR_LEFT = new LatLng(34, -12);
|
||||
private static final LatLng FAR_RIGHT = new LatLng(52, 26);
|
||||
private static final LatLng NEAR_RIGHT = new LatLng(34, 26);
|
||||
private static final LatLngBounds BOUNDS = new LatLngBounds.Builder().include(FAR_LEFT).include(FAR_RIGHT).include(NEAR_LEFT).include(NEAR_RIGHT).build();
|
||||
|
||||
@Test
|
||||
public void testSanity() {
|
||||
VisibleRegion region = new VisibleRegion(FAR_LEFT, FAR_RIGHT, NEAR_LEFT, NEAR_RIGHT, BOUNDS);
|
||||
assertNotNull("region should not be null", region);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFarLeftConstructor() {
|
||||
VisibleRegion region = new VisibleRegion(FAR_LEFT, FAR_RIGHT, NEAR_LEFT, NEAR_RIGHT, BOUNDS);
|
||||
assertEquals("LatLng should match", region.farLeft, FAR_LEFT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNearLeftConstructor() {
|
||||
VisibleRegion region = new VisibleRegion(FAR_LEFT, FAR_RIGHT, NEAR_LEFT, NEAR_RIGHT, BOUNDS);
|
||||
assertEquals("LatLng should match", region.nearLeft, NEAR_LEFT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFarRightConstructor() {
|
||||
VisibleRegion region = new VisibleRegion(FAR_LEFT, FAR_RIGHT, NEAR_LEFT, NEAR_RIGHT, BOUNDS);
|
||||
assertEquals("LatLng should match", region.farRight, FAR_RIGHT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNearRightConstructor() {
|
||||
VisibleRegion region = new VisibleRegion(FAR_LEFT, FAR_RIGHT, NEAR_LEFT, NEAR_RIGHT, BOUNDS);
|
||||
assertEquals("LatLng should match", region.nearRight, NEAR_RIGHT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLatLngBoundsConstructor() {
|
||||
VisibleRegion region = new VisibleRegion(FAR_LEFT, FAR_RIGHT, NEAR_LEFT, NEAR_RIGHT, BOUNDS);
|
||||
assertEquals("LatLngBounds should match", region.latLngBounds, BOUNDS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEquals() {
|
||||
VisibleRegion regionLeft = new VisibleRegion(FAR_LEFT, FAR_RIGHT, NEAR_LEFT, NEAR_RIGHT, BOUNDS);
|
||||
VisibleRegion regionRight = new VisibleRegion(FAR_LEFT, FAR_RIGHT, NEAR_LEFT, NEAR_RIGHT, BOUNDS);
|
||||
assertEquals("VisibleRegions should match", regionLeft, regionRight);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToString() {
|
||||
VisibleRegion region = new VisibleRegion(FAR_LEFT, FAR_RIGHT, NEAR_LEFT, NEAR_RIGHT, BOUNDS);
|
||||
assertEquals("string should match",
|
||||
"[farLeft [LatLng [longitude=-12.0, latitude=52.0, altitude=0.0]], " +
|
||||
"farRight [LatLng [longitude=26.0, latitude=52.0, altitude=0.0]], " +
|
||||
"nearLeft [LatLng [longitude=-12.0, latitude=34.0, altitude=0.0]], " +
|
||||
"nearRight [LatLng [longitude=26.0, latitude=34.0, altitude=0.0]], " +
|
||||
"latLngBounds [N:52.0; E:26.0; S:34.0; W:-12.0]]"
|
||||
, region.toString());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,170 +0,0 @@
|
||||
package com.mapbox.mapboxsdk.maps;
|
||||
|
||||
import com.mapbox.mapboxsdk.geometry.BoundingBox;
|
||||
import com.mapbox.mapboxsdk.geometry.CoordinateSpan;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class BoundingBoxTest {
|
||||
|
||||
private BoundingBox mBoundingBox;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
mBoundingBox = new BoundingBox(20.0, 10.0, 0.0, 0.0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSanity() {
|
||||
BoundingBox boundingBox = new BoundingBox(0.0, 0.0, 0.0, 0.0);
|
||||
assertNotNull("boundingBox should not be null", boundingBox);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEqualityConstructors() {
|
||||
BoundingBox cornerBoundingBox = new BoundingBox(new LatLng(20.0, 10.0), new LatLng(0.0, 0.0));
|
||||
BoundingBox cloneBoundingBox = new BoundingBox(mBoundingBox);
|
||||
assertEquals("boundingBoxes should match", mBoundingBox, cornerBoundingBox);
|
||||
assertEquals("boundingBoxes should match", mBoundingBox, cloneBoundingBox);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidBox() {
|
||||
assertTrue(mBoundingBox.isValid());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvalidLatitudeSpanBox() {
|
||||
mBoundingBox = new BoundingBox(0.0, 10.0, 10.0, 0.0);
|
||||
assertFalse(mBoundingBox.isValid());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvalidLongitudeSpanBox() {
|
||||
mBoundingBox = new BoundingBox(10.0, 0.0, 0.0, 20.0);
|
||||
assertFalse(mBoundingBox.isValid());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCenterCoordinate() {
|
||||
LatLng center = new LatLng(10.0, 5.0);
|
||||
assertEquals("boundingBox center should match", center, mBoundingBox.getCenter());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnionSameBox() {
|
||||
assertEquals(mBoundingBox, mBoundingBox.union(mBoundingBox));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnionInnerBox() {
|
||||
BoundingBox innerBox = new BoundingBox(2.0, 2.0, 1.0, 1.0);
|
||||
assertEquals(mBoundingBox.union(innerBox), mBoundingBox);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnionOverlapBox() {
|
||||
BoundingBox resultBox = new BoundingBox(22.0, 12.0, 0.0, 0.0);
|
||||
BoundingBox overlapBox = new BoundingBox(22.0, 12.0, 1.0, 1.0);
|
||||
assertEquals(resultBox, mBoundingBox.union(overlapBox));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnionOuterBox() {
|
||||
BoundingBox resultBox = new BoundingBox(40.0, 40.0, 0.0, 0.0);
|
||||
BoundingBox outerBox = new BoundingBox(40.0, 40.0, 0.0, 0.0);
|
||||
assertEquals(resultBox, mBoundingBox.union(outerBox));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIntersectSameBox() {
|
||||
assertEquals(mBoundingBox, mBoundingBox.intersect(mBoundingBox));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIntersectInnerBox() {
|
||||
BoundingBox innerBox = new BoundingBox(2.0, 2.0, 1.0, 1.0);
|
||||
assertEquals(innerBox, mBoundingBox.intersect(innerBox));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIntersectOuterBox() {
|
||||
BoundingBox outerBox = new BoundingBox(40.0, 40.0, 0.0, 0.0);
|
||||
assertEquals(mBoundingBox, mBoundingBox.intersect(outerBox));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIntersectOverlapBox() {
|
||||
BoundingBox resultBox = new BoundingBox(20.0, 10.0, 1.0, 1.0);
|
||||
BoundingBox overlapBox = new BoundingBox(22.0, 12.0, 1.0, 1.0);
|
||||
assertEquals(resultBox, mBoundingBox.intersect(overlapBox));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIntersectNoneBox() {
|
||||
BoundingBox outsideBox = new BoundingBox(100.0, 100.0, 50.0, 50.0);
|
||||
assertNull(mBoundingBox.intersect(outsideBox));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testContainsCoordinate() {
|
||||
LatLng coordinate = new LatLng(1.0, 1.0);
|
||||
assertTrue(mBoundingBox.contains(coordinate));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testContainsCoordinateOnBoundary() {
|
||||
LatLng coordinate = new LatLng(20.0, 9.0);
|
||||
assertFalse(mBoundingBox.contains(coordinate));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testContainsNoCoordinate() {
|
||||
LatLng coordinate = new LatLng(100.0, 100.0);
|
||||
assertFalse(mBoundingBox.contains(coordinate));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSpan() {
|
||||
CoordinateSpan span = new CoordinateSpan(20.0, 10.0);
|
||||
assertTrue(mBoundingBox.getSpan().equals(span));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLatitudeSpan() {
|
||||
double height = 20.0;
|
||||
assertTrue(mBoundingBox.getLatitudeSpan() == height);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLongitudeSpan() {
|
||||
double width = 10.0;
|
||||
assertTrue(mBoundingBox.getLongitudeSpan() == width);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEmptySpanEmptyNotEmptyBox() {
|
||||
assertFalse(mBoundingBox.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEmptySpanEmptyLatitude() {
|
||||
mBoundingBox = new BoundingBox(1.0, 2.0, 0.0, 2.0);
|
||||
assertTrue(mBoundingBox.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEmptySpanEmptyLongitude() {
|
||||
mBoundingBox = new BoundingBox(0.0, 3.0, 0.0, 1.0);
|
||||
assertTrue(mBoundingBox.isEmpty());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
package com.mapbox.mapboxsdk.maps;
|
||||
|
||||
import com.mapbox.mapboxsdk.geometry.CoordinateSpan;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
public class CoordinateSpanTest {
|
||||
|
||||
private static final double DELTA = 1e-15;
|
||||
|
||||
@Test
|
||||
public void testSanity() {
|
||||
CoordinateSpan coordinateSpan = new CoordinateSpan(0.0, 0.0);
|
||||
assertNotNull("coordinateSpan should not be null", coordinateSpan);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLatitudeConstructor() {
|
||||
double latitude = 1.23;
|
||||
CoordinateSpan coordinateSpan = new CoordinateSpan(latitude, 0.0);
|
||||
assertEquals("latitude in constructor", coordinateSpan.getLatitudeSpan(), latitude, DELTA);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLongitudeConstructor() {
|
||||
double longitude = 1.23;
|
||||
CoordinateSpan coordinateSpan = new CoordinateSpan(0.0, longitude);
|
||||
assertEquals("latitude in constructor", coordinateSpan.getLongitudeSpan(), longitude, DELTA);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLatitudeMethod() {
|
||||
double latitude = 1.23;
|
||||
CoordinateSpan coordinateSpan = new CoordinateSpan(0.0, 0.0);
|
||||
coordinateSpan.setLatitudeSpan(latitude);
|
||||
assertEquals("latitude in constructor", coordinateSpan.getLatitudeSpan(), latitude, DELTA);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLongitudeMethod() {
|
||||
double longitude = 1.23;
|
||||
CoordinateSpan coordinateSpan = new CoordinateSpan(0.0, 0.0);
|
||||
coordinateSpan.setLongitudeSpan(longitude);
|
||||
assertEquals("latitude in constructor", coordinateSpan.getLongitudeSpan(), longitude, DELTA);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -47,7 +47,7 @@ public class MapboxMapTest {
|
||||
}
|
||||
|
||||
//
|
||||
// Test UiSettings
|
||||
// UiSettings
|
||||
//
|
||||
|
||||
@Test
|
||||
@@ -55,6 +55,16 @@ public class MapboxMapTest {
|
||||
assertNotNull("UiSettings should not be null", mMapboxMap.getUiSettings());
|
||||
}
|
||||
|
||||
//
|
||||
// Projection
|
||||
//
|
||||
|
||||
@Test
|
||||
public void testProjection(){
|
||||
assertNotNull("Projection should not be null",mMapboxMap.getProjection());
|
||||
}
|
||||
|
||||
|
||||
|
||||
//
|
||||
// InfoWindow
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.mapbox.mapboxsdk.maps;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
public class ProjectionTest {
|
||||
|
||||
@InjectMocks
|
||||
MapView mMapView = mock(MapView.class);
|
||||
|
||||
@Before
|
||||
public void beforeTest() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSanity() {
|
||||
Projection projection = new Projection(mMapView);
|
||||
assertNotNull("projection should not be null", projection);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user