Content-Length: 324454 | pFad | http://github.com/fleaflet/flutter_map/pull/1860/commits/f146a16e23c7d0cf1ba3b159d44278b54373990a

D9 fix: allowed `LatLngBounds.center` to work across world boundary & added `simpleCenter` by monsieurtanuki · Pull Request #1860 · fleaflet/flutter_map · GitHub
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allowed LatLngBounds.center to work across world boundary & added simpleCenter #1860

Merged
merged 6 commits into from
May 26, 2024
Merged
Changes from 1 commit
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
Next Next commit
fix: 1689 - fixed LatLngBounds.center and added simpleCenter
Impacted files:
* `latlng_bounds.dart`: fixed the computation of `center` according to referenced link; added a more intuitive `simpleCenter` method.
* `latlng_bounds_test.dart`: added the tests that failed in the initial issue
  • Loading branch information
monsieurtanuki committed Mar 27, 2024
commit f146a16e23c7d0cf1ba3b159d44278b54373990a
8 changes: 7 additions & 1 deletion lib/src/geo/latlng_bounds.dart
Original file line number Diff line number Diff line change
@@ -175,9 +175,15 @@ class LatLngBounds {
final lambda3 = lambda1 + atan2(by, cos(phi1) + bx);

// phi3 and lambda3 are actually in radians and LatLng wants degrees
return LatLng(phi3 * radians2Degrees, lambda3 * radians2Degrees);
return LatLng(
phi3 * radians2Degrees,
(lambda3 * radians2Degrees + 540) % 360 - 180,
);
}

//github.com/ Obtain simple coordinates of the bounds center
LatLng get simpleCenter => LatLng((south + north) / 2, (east + west) / 2);

//github.com/ Checks whether [point] is inside bounds
bool contains(LatLng point) =>
point.longitude >= west &&
47 changes: 47 additions & 0 deletions test/geo/latlng_bounds_test.dart
Original file line number Diff line number Diff line change
@@ -47,5 +47,52 @@ void main() {
expect(bounds1.hashCode, bounds2.hashCode);
});
});

group('center', () {
// cf. https://github.com/fleaflet/flutter_map/issues/1689
test('should calculate center point #1', () async {
final bounds = LatLngBounds(
const LatLng(-77.45, -171.16),
const LatLng(46.64, 25.88),
);
final center = bounds.center;
expect(center.latitude, greaterThanOrEqualTo(-90));
expect(center.latitude, lessThanOrEqualTo(90));
expect(center.longitude, greaterThanOrEqualTo(-180));
expect(center.longitude, lessThanOrEqualTo(180));
});
test('should calculate center point #2', () async {
final bounds = LatLngBounds(
const LatLng(-0.87, -179.86),
const LatLng(84.92, 23.86),
);
final center = bounds.center;
expect(center.latitude, greaterThanOrEqualTo(-90));
expect(center.latitude, lessThanOrEqualTo(90));
expect(center.longitude, greaterThanOrEqualTo(-180));
expect(center.longitude, lessThanOrEqualTo(180));
});
});

group('simpleCenter', () {
test('should calculate center point #1', () async {
final bounds = LatLngBounds(
const LatLng(-77.45, -171.16),
const LatLng(46.64, 25.88),
);
final center = bounds.simpleCenter;
expect(center.latitude, (-77.45 + 46.64) / 2);
expect(center.longitude, (-171.16 + 25.88) / 2);
});
test('should calculate center point #2', () async {
final bounds = LatLngBounds(
const LatLng(-0.87, -179.86),
const LatLng(84.92, 23.86),
);
final center = bounds.simpleCenter;
expect(center.latitude, (-0.87 + 84.92) / 2);
expect(center.longitude, (-179.86 + 23.86) / 2);
});
});
});
}
Loading
Oops, something went wrong.








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/fleaflet/flutter_map/pull/1860/commits/f146a16e23c7d0cf1ba3b159d44278b54373990a

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy