From aa8857643d404a5512b1bc3cec380e56f88b6f75 Mon Sep 17 00:00:00 2001 From: Bruno de Oliveira Abinader Date: Wed, 11 Nov 2015 16:48:58 +0200 Subject: [core] Added MetersBounds --- include/mbgl/util/geo.hpp | 14 +++++++++++++- include/mbgl/util/projection.hpp | 20 +++++--------------- 2 files changed, 18 insertions(+), 16 deletions(-) (limited to 'include/mbgl/util') diff --git a/include/mbgl/util/geo.hpp b/include/mbgl/util/geo.hpp index 7e2ad998b9..dd2b1567fc 100644 --- a/include/mbgl/util/geo.hpp +++ b/include/mbgl/util/geo.hpp @@ -54,7 +54,7 @@ struct LatLngBounds { LatLng sw = {90, 180}; LatLng ne = {-90, -180}; - inline LatLngBounds(LatLng sw_ = {90, 180}, LatLng ne_ = {-90, -180}) + inline LatLngBounds(const LatLng& sw_ = {90, 180}, const LatLng& ne_ = {-90, -180}) : sw(sw_), ne(ne_) {} inline bool isValid() const { @@ -91,6 +91,18 @@ struct LatLngBounds { } }; +struct MetersBounds { + ProjectedMeters sw; + ProjectedMeters ne; + + inline MetersBounds(const ProjectedMeters& sw_, const ProjectedMeters& ne_) + : sw(sw_), ne(ne_) {} + + inline bool isValid() const { + return sw.isValid() && ne.isValid(); + } +}; + } #endif diff --git a/include/mbgl/util/projection.hpp b/include/mbgl/util/projection.hpp index 9563900851..391e37dd34 100644 --- a/include/mbgl/util/projection.hpp +++ b/include/mbgl/util/projection.hpp @@ -11,24 +11,14 @@ namespace mbgl { class Projection { public: - static inline void getWorldBoundsMeters(ProjectedMeters &sw, ProjectedMeters &ne) { + static inline MetersBounds getWorldBoundsMeters() { const double d = util::EARTH_RADIUS_M * M_PI; - - sw.easting = -d; - sw.northing = -d; - - ne.easting = d; - ne.northing = d; + return { { -d, -d }, { d, d } }; } - static inline void getWorldBoundsLatLng(LatLng &sw, LatLng &ne) { - ProjectedMeters projectedMetersSW = ProjectedMeters(); - ProjectedMeters projectedMetersNE = ProjectedMeters(); - - getWorldBoundsMeters(projectedMetersSW, projectedMetersNE); - - sw = latLngForProjectedMeters(projectedMetersSW); - ne = latLngForProjectedMeters(projectedMetersNE); + static inline LatLngBounds getWorldBoundsLatLng() { + MetersBounds bounds = getWorldBoundsMeters(); + return { latLngForProjectedMeters(bounds.sw), latLngForProjectedMeters(bounds.ne) }; } static inline double getMetersPerPixelAtLatitude(const double lat, const double zoom) { -- cgit v1.2.1