diff options
author | John Firebaugh <john.firebaugh@gmail.com> | 2017-04-04 07:35:26 -0700 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2017-04-06 09:22:51 -0700 |
commit | 16a2839e23d42d4640ef028d62dc01322a0d2e5a (patch) | |
tree | b8b8ba6e7c9f2e91cc3ec230bb9420e3827f3c27 /src | |
parent | a261f7ff532584b3bbbe4ddef2d0ff96a1ee65a5 (diff) | |
download | qtlocation-mapboxgl-16a2839e23d42d4640ef028d62dc01322a0d2e5a.tar.gz |
[all] Make LatLng coordinates read-only
Diffstat (limited to 'src')
-rw-r--r-- | src/mbgl/annotation/symbol_annotation_impl.hpp | 2 | ||||
-rw-r--r-- | src/mbgl/map/transform.cpp | 4 | ||||
-rw-r--r-- | src/mbgl/map/transform_state.cpp | 4 | ||||
-rw-r--r-- | src/mbgl/style/layers/custom_layer_impl.cpp | 4 | ||||
-rw-r--r-- | src/mbgl/style/parser.cpp | 4 | ||||
-rw-r--r-- | src/mbgl/util/geo.cpp | 14 |
6 files changed, 17 insertions, 15 deletions
diff --git a/src/mbgl/annotation/symbol_annotation_impl.hpp b/src/mbgl/annotation/symbol_annotation_impl.hpp index 2e98f2414c..c9a99ffb8d 100644 --- a/src/mbgl/annotation/symbol_annotation_impl.hpp +++ b/src/mbgl/annotation/symbol_annotation_impl.hpp @@ -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 { diff --git a/src/mbgl/map/transform.cpp b/src/mbgl/map/transform.cpp index 71d216f1ed..c30b8d9687 100644 --- a/src/mbgl/map/transform.cpp +++ b/src/mbgl/map/transform.cpp @@ -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); diff --git a/src/mbgl/map/transform_state.cpp b/src/mbgl/map/transform_state.cpp index f7419fa5b4..3fae7b205c 100644 --- a/src/mbgl/map/transform_state.cpp +++ b/src/mbgl/map/transform_state.cpp @@ -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); diff --git a/src/mbgl/style/layers/custom_layer_impl.cpp b/src/mbgl/style/layers/custom_layer_impl.cpp index 379de25e8f..375c9ee27b 100644 --- a/src/mbgl/style/layers/custom_layer_impl.cpp +++ b/src/mbgl/style/layers/custom_layer_impl.cpp @@ -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(); diff --git a/src/mbgl/style/parser.cpp b/src/mbgl/style/parser.cpp index d970d8bbc0..19ea8cefee 100644 --- a/src/mbgl/style/parser.cpp +++ b/src/mbgl/style/parser.cpp @@ -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); } } diff --git a/src/mbgl/util/geo.cpp b/src/mbgl/util/geo.cpp index fe24334e82..1244a975a4 100644 --- a/src/mbgl/util/geo.cpp +++ b/src/mbgl/util/geo.cpp @@ -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 { |