Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[android] #4475 - Only wrapping when needed in LatLng.wrap(). Making …
Browse files Browse the repository at this point in the history
…Javadoc more clear. Making tests consistent.
  • Loading branch information
bleege committed Mar 25, 2016
1 parent fa16a53 commit b864fd4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,10 @@ public double getAltitude() {
*/
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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public static float clamp(float value, float min, float max) {
}

/**
* 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
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;
Expand Down Expand Up @@ -204,7 +204,15 @@ public void testDescribeContents() {
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);
}
}

0 comments on commit b864fd4

Please sign in to comment.