[android] #4475 - Only wrapping when needed in LatLng.wrap(). Making Javadoc more clear. Making tests consistent.

This commit is contained in:
Brad Leege
2016-03-25 16:32:33 -05:00
parent 464c29f043
commit 7a9a58f4fb
3 changed files with 16 additions and 5 deletions

View File

@@ -126,7 +126,10 @@ public class LatLng implements ILatLng, Parcelable {
*/
public LatLng wrap(){
LatLng wrappedVersion = new LatLng(this);
wrappedVersion.setLongitude(MathUtils.wrap(wrappedVersion.getLongitude(), GeoConstants.MIN_LONGITUDE, GeoConstants.MAX_LONGITUDE));
double lon = wrappedVersion.getLongitude();
if (lon < GeoConstants.MIN_LONGITUDE || lon > GeoConstants.MAX_LONGITUDE) {
wrappedVersion.setLongitude(MathUtils.wrap(wrappedVersion.getLongitude(), GeoConstants.MIN_LONGITUDE, GeoConstants.MAX_LONGITUDE));
}
return wrappedVersion;
}

View File

@@ -25,7 +25,7 @@ public class MathUtils {
}
/**
* Constrains n to the given range (including min, excluding max) via modular arithmetic.
* Constrains value to the given range (including min, excluding max) via modular arithmetic.
*
* Same formula as used in Core GL (math.hpp)
* std::fmod((std::fmod((value - min), d) + d), d) + min;

View File

@@ -6,11 +6,11 @@ import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.utils.MockParcel;
import org.junit.Test;
import java.util.Objects;
import dalvik.annotation.TestTargetClass;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
@@ -204,7 +204,15 @@ public class LatLngTest {
public void testWrapped() {
LatLng latLng = new LatLng(45.0, -185.0);
LatLng wrapped = latLng.wrap();
assertTrue(!latLng.equals(wrapped));
assertTrue(wrapped.getLongitude() == 175.0);
assertNotSame(latLng, wrapped);
assertEquals("longitude wrapped value", wrapped.getLongitude(), 175.0, DELTA);
}
@Test
public void testUnnecessaryWrapped() {
LatLng latLng = new LatLng(45.0, 50.0);
LatLng wrapped = latLng.wrap();
assertNotSame(latLng, wrapped);
assertEquals("longitude wrapped value", wrapped.getLongitude(), 50.0, DELTA);
}
}