summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/mbgl/util/geo.hpp35
1 files changed, 18 insertions, 17 deletions
diff --git a/include/mbgl/util/geo.hpp b/include/mbgl/util/geo.hpp
index 2cc9297aae..d0d0518c2a 100644
--- a/include/mbgl/util/geo.hpp
+++ b/include/mbgl/util/geo.hpp
@@ -9,6 +9,7 @@
#include <mapbox/geometry/box.hpp>
#include <cmath>
+#include <stdexcept>
namespace mbgl {
@@ -21,17 +22,29 @@ using ScreenBox = mapbox::geometry::box<double>;
class LatLng {
public:
- struct null {};
-
double latitude;
double longitude;
enum WrapMode : bool { Unwrapped, Wrapped };
- LatLng(null) : latitude(std::numeric_limits<double>::quiet_NaN()), longitude(latitude) {}
-
LatLng(double lat = 0, double lon = 0, WrapMode mode = Unwrapped)
- : latitude(lat), longitude(lon) { if (mode == Wrapped) wrap(); }
+ : latitude(lat), longitude(lon) {
+ if (std::isnan(lat)) {
+ throw std::domain_error("latitude must not be NaN");
+ }
+ if (std::isnan(lon)) {
+ throw std::domain_error("longitude must not be NaN");
+ }
+ if (std::abs(lat) > 90.0) {
+ throw std::domain_error("latitude must be between -90 and 90");
+ }
+ if (!std::isfinite(lon)) {
+ throw std::domain_error("longitude must not be infinite");
+ }
+ if (mode == Wrapped) {
+ wrap();
+ }
+ }
LatLng wrapped() const { return { latitude, longitude, Wrapped }; }
@@ -48,10 +61,6 @@ public:
else if (longitude < 0 && end.longitude > 0) longitude += util::DEGREES_MAX;
}
- explicit operator bool() const {
- return !(std::isnan(latitude) || std::isnan(longitude));
- }
-
// Constructs a LatLng object with the top left position of the specified tile.
LatLng(const CanonicalTileID& id);
LatLng(const UnwrappedTileID& id);
@@ -72,10 +81,6 @@ public:
ProjectedMeters(double n = 0, double e = 0)
: northing(n), easting(e) {}
-
- explicit operator bool() const {
- return !(std::isnan(northing) || std::isnan(easting));
- }
};
constexpr bool operator==(const ProjectedMeters& a, const ProjectedMeters& b) {
@@ -197,10 +202,6 @@ public:
EdgeInsets(const double t, const double l, const double b, const double r)
: top(t), left(l), bottom(b), right(r) {}
- explicit operator bool() const {
- return !(std::isnan(top) || std::isnan(left) || std::isnan(bottom) || std::isnan(right))
- && (top || left || bottom || right);
- }
void operator+=(const EdgeInsets& o) {
top += o.top;