[all] Make LatLng coordinates read-only

This commit is contained in:
John Firebaugh
2017-04-04 07:35:26 -07:00
parent a261f7ff53
commit 16a2839e23
21 changed files with 232 additions and 229 deletions

View File

@@ -27,7 +27,7 @@
#pragma GCC diagnostic pop
// Make Boost Geometry aware of our LatLng type
BOOST_GEOMETRY_REGISTER_POINT_2D(mbgl::LatLng, double, boost::geometry::cs::cartesian, longitude, latitude)
BOOST_GEOMETRY_REGISTER_POINT_2D_CONST(mbgl::LatLng, double, boost::geometry::cs::cartesian, longitude(), latitude())
BOOST_GEOMETRY_REGISTER_BOX(mbgl::LatLngBounds, mbgl::LatLng, southwest(), northeast())
namespace mbgl {

View File

@@ -103,7 +103,9 @@ void Transform::easeTo(const CameraOptions& camera, const AnimationOptions& anim
// If gesture in progress, we transfer the world rounds from the end
// longitude into start, so we can guarantee the "scroll effect" of rounding
// the world while assuring the end longitude remains wrapped.
if (isGestureInProgress()) startLatLng.longitude -= unwrappedLatLng.longitude - latLng.longitude;
if (isGestureInProgress()) {
startLatLng = LatLng(startLatLng.latitude(), startLatLng.longitude() - (unwrappedLatLng.longitude() - latLng.longitude()));
}
// Find the shortest path otherwise.
else startLatLng.unwrapForShortestPath(latLng);

View File

@@ -325,10 +325,10 @@ void TransformState::setLatLngZoom(const LatLng &latLng, double zoom) {
Cc = newWorldSize / util::M2PI;
const double m = 1 - 1e-15;
const double f = util::clamp(std::sin(util::DEG2RAD * latLng.latitude), -m, m);
const double f = util::clamp(std::sin(util::DEG2RAD * latLng.latitude()), -m, m);
ScreenCoordinate point = {
-latLng.longitude * Bc,
-latLng.longitude() * Bc,
0.5 * Cc * std::log((1 + f) / (1 - f)),
};
setScalePoint(newScale, point);

View File

@@ -55,8 +55,8 @@ void CustomLayer::Impl::render(const TransformState& state) const {
parameters.width = state.getSize().width;
parameters.height = state.getSize().height;
parameters.latitude = state.getLatLng().latitude;
parameters.longitude = state.getLatLng().longitude;
parameters.latitude = state.getLatLng().latitude();
parameters.longitude = state.getLatLng().longitude();
parameters.zoom = state.getZoom();
parameters.bearing = -state.getAngle() * util::RAD2DEG;
parameters.pitch = state.getPitch();

View File

@@ -56,8 +56,8 @@ StyleParseResult Parser::parse(const std::string& json) {
const JSValue& value = document["center"];
if (value.IsArray() && value.Size() >= 2) {
// Style spec uses lon/lat order
latLng.longitude = value[0].IsNumber() ? value[0].GetDouble() : 0;
latLng.latitude = value[1].IsNumber() ? value[1].GetDouble() : 0;
latLng = LatLng(value[1].IsNumber() ? value[1].GetDouble() : 0,
value[0].IsNumber() ? value[0].GetDouble() : 0);
}
}

View File

@@ -8,28 +8,28 @@ namespace mbgl {
namespace {
double lat(const uint8_t z, const int64_t y) {
double lat_(const uint8_t z, const int64_t y) {
const double n = M_PI - 2.0 * M_PI * y / std::pow(2.0, z);
return util::RAD2DEG * std::atan(0.5 * (std::exp(n) - std::exp(-n)));
}
double lon(const uint8_t z, const int64_t x) {
double lon_(const uint8_t z, const int64_t x) {
return x / std::pow(2.0, z) * util::DEGREES_MAX - util::LONGITUDE_MAX;
}
} // end namespace
LatLng::LatLng(const CanonicalTileID& id) : latitude(lat(id.z, id.y)), longitude(lon(id.z, id.x)) {
LatLng::LatLng(const CanonicalTileID& id) : lat(lat_(id.z, id.y)), lon(lon_(id.z, id.x)) {
}
LatLng::LatLng(const UnwrappedTileID& id)
: latitude(lat(id.canonical.z, id.canonical.y)),
longitude(lon(id.canonical.z, id.canonical.x) + id.wrap * util::DEGREES_MAX) {
: lat(lat_(id.canonical.z, id.canonical.y)),
lon(lon_(id.canonical.z, id.canonical.x) + id.wrap * util::DEGREES_MAX) {
}
LatLngBounds::LatLngBounds(const CanonicalTileID& id)
: sw({ lat(id.z, id.y + 1), lon(id.z, id.x) }),
ne({ lat(id.z, id.y), lon(id.z, id.x + 1) }) {
: sw({ lat_(id.z, id.y + 1), lon_(id.z, id.x) }),
ne({ lat_(id.z, id.y), lon_(id.z, id.x + 1) }) {
}
ScreenCoordinate EdgeInsets::getCenter(uint16_t width, uint16_t height) const {