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

[android] fixed center calculation for LatLngBounds with zero span #11650

Merged
merged 1 commit into from
Apr 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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