diff options
author | Bruno de Oliveira Abinader <bruno@mapbox.com> | 2017-04-03 17:55:31 +0300 |
---|---|---|
committer | Bruno de Oliveira Abinader <bruno@mapbox.com> | 2017-04-11 12:51:09 +0300 |
commit | bc7f6da1356fdfc22d8fa1d5f76821ab171647eb (patch) | |
tree | be5ce3c2a892caa7d810f2e0b3fb204bb396fb4c /include | |
parent | ddc6dcf9cdaee59e6f31b7bfa05932f1980feba4 (diff) | |
download | qtlocation-mapboxgl-bc7f6da1356fdfc22d8fa1d5f76821ab171647eb.tar.gz |
[core] Added LatLngBounds::{valid,constrain}
Diffstat (limited to 'include')
-rw-r--r-- | include/mbgl/util/geo.hpp | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/include/mbgl/util/geo.hpp b/include/mbgl/util/geo.hpp index 6adbadca0d..04aa1e1bfa 100644 --- a/include/mbgl/util/geo.hpp +++ b/include/mbgl/util/geo.hpp @@ -1,5 +1,6 @@ #pragma once +#include <mbgl/math/clamp.hpp> #include <mbgl/math/wrap.hpp> #include <mbgl/util/constants.hpp> @@ -120,6 +121,10 @@ public: // Constructs a LatLngBounds object with the tile's exact boundaries. LatLngBounds(const CanonicalTileID&); + bool valid() const { + return (sw.latitude() <= ne.latitude()) && (sw.longitude() <= ne.longitude()); + } + double south() const { return sw.latitude(); } double west() const { return sw.longitude(); } double north() const { return ne.latitude(); } @@ -135,6 +140,16 @@ public: (sw.longitude() + ne.longitude()) / 2); } + LatLng constrain(const LatLng& p) const { + if (contains(p)) { + return p; + } + return LatLng { + util::clamp(p.latitude(), sw.latitude(), ne.latitude()), + util::clamp(p.longitude(), sw.longitude(), ne.longitude()) + }; + } + void extend(const LatLng& point) { sw = LatLng(std::min(point.latitude(), sw.latitude()), std::min(point.longitude(), sw.longitude())); |