summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/mbgl/util/geo.hpp15
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()));