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

Commit

Permalink
[android] center was calculated incorrectly for LatLngBounds with zer…
Browse files Browse the repository at this point in the history
…o span
  • Loading branch information
“osana” authored and tobrun committed Apr 11, 2018
1 parent 33d3c27 commit c119cc3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public LatLng getCenter() {
double latCenter = (this.latitudeNorth + this.latitudeSouth) / 2.0;
double longCenter;

if (this.longitudeEast > this.longitudeWest) {
if (this.longitudeEast >= this.longitudeWest) {
longCenter = (this.longitudeEast + this.longitudeWest) / 2;
} else {
double halfSpan = (GeometryConstants.LONGITUDE_SPAN + this.longitudeEast - this.longitudeWest) / 2.0;
Expand Down Expand Up @@ -180,7 +180,7 @@ public double getLatitudeSpan() {
*/
public double getLongitudeSpan() {
double longSpan = Math.abs(this.longitudeEast - this.longitudeWest);
if (this.longitudeEast > this.longitudeWest) {
if (this.longitudeEast >= this.longitudeWest) {
return longSpan;
}

Expand All @@ -191,7 +191,7 @@ public double getLongitudeSpan() {

static double getLongitudeSpan(final double longEast, final double longWest) {
double longSpan = Math.abs(longEast - longWest);
if (longEast > longWest) {
if (longEast >= longWest) {
return longSpan;
}

Expand Down Expand Up @@ -240,7 +240,6 @@ static LatLngBounds fromLatLngs(final List<? extends ILatLng> latLngs) {
westLon = temp;
}
} else {
lonSpan = GeometryConstants.LONGITUDE_SPAN - lonSpan;
if (westLon < eastLon) {
double temp = eastLon;
eastLon = westLon;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,14 @@ public void dateLineSpanFrom2() {
latLngSpan);
}

@Test
public void zeroLongitudeSpan() {
latLngBounds = LatLngBounds.from(10, 10, -10, 10);
LatLngSpan latLngSpan = latLngBounds.getSpan();
assertEquals("LatLngSpan should be shortest distance", new LatLngSpan(20, 0),
latLngSpan);
}

@Test
public void nearDateLineCenter1() {
latLngBounds = LatLngBounds.from(10, -175, -10, 165);
Expand Down Expand Up @@ -145,6 +153,19 @@ public void nearDateLineCenter5() {
assertEquals("Center should match", new LatLng(0, 90), center);
}

@Test
public void centerForBoundsWithSameLongitude() {
latLngBounds = LatLngBounds.from(10, 10, -10, 10);
LatLng center = latLngBounds.getCenter();
assertEquals("Center should match", new LatLng(0, 10), center);
}

@Test
public void centerForBoundsWithSameLatitude() {
latLngBounds = LatLngBounds.from(10, 10, 10, -10);
LatLng center = latLngBounds.getCenter();
assertEquals("Center should match", new LatLng(10, 0), center);
}

@Test
public void center() {
Expand Down

0 comments on commit c119cc3

Please sign in to comment.