From bc7f6da1356fdfc22d8fa1d5f76821ab171647eb Mon Sep 17 00:00:00 2001 From: Bruno de Oliveira Abinader Date: Mon, 3 Apr 2017 17:55:31 +0300 Subject: [core] Added LatLngBounds::{valid,constrain} --- include/mbgl/util/geo.hpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'include/mbgl/util/geo.hpp') 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 #include #include @@ -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())); -- cgit v1.2.1