[core] Added LatLngBounds::{valid,constrain}
This commit is contained in:
@@ -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()));
|
||||
|
||||
Reference in New Issue
Block a user