summaryrefslogtreecommitdiff
path: root/include/mbgl/util
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2016-03-16 17:45:00 -0700
committerJohn Firebaugh <john.firebaugh@gmail.com>2017-04-06 09:22:51 -0700
commit0314a46ee411b97810d49908ab110bbef049e7b7 (patch)
tree8f9d902cc09a245dd2d41eab1ff16c4cdf8e7680 /include/mbgl/util
parent56ea87357aa9f4df48183ae1582c827f47547f83 (diff)
downloadqtlocation-mapboxgl-0314a46ee411b97810d49908ab110bbef049e7b7.tar.gz
[core] Tighten LatLng and other geo.hpp classes
* Remove LatLng::null and enforce invariants * Remove unnecessary operator bool()
Diffstat (limited to 'include/mbgl/util')
-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;