From ddecdeca9493ac1caaae2301eb822bdbf2f75ff9 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Fri, 14 Apr 2017 12:37:43 -0700 Subject: [core] Move ProjectedMeters to projection.hpp --- include/mbgl/util/projection.hpp | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'include/mbgl/util/projection.hpp') diff --git a/include/mbgl/util/projection.hpp b/include/mbgl/util/projection.hpp index ed34261b18..3cc1146513 100644 --- a/include/mbgl/util/projection.hpp +++ b/include/mbgl/util/projection.hpp @@ -5,9 +5,36 @@ #include #include - namespace mbgl { +class ProjectedMeters { +private: + double _northing; // Distance measured northwards. + double _easting; // Distance measured eastwards. + +public: + ProjectedMeters(double n_ = 0, double e_ = 0) + : _northing(n_), _easting(e_) { + if (std::isnan(_northing)) { + throw std::domain_error("northing must not be NaN"); + } + if (std::isnan(_easting)) { + throw std::domain_error("easting must not be NaN"); + } + } + + double northing() const { return _northing; } + double easting() const { return _easting; } + + friend bool operator==(const ProjectedMeters& a, const ProjectedMeters& b) { + return a._northing == b._northing && a._easting == b._easting; + } + + friend bool operator!=(const ProjectedMeters& a, const ProjectedMeters& b) { + return !(a == b); + } +}; + // Spherical Mercator projection // http://docs.openlayers.org/library/spherical_mercator.html class Projection { -- cgit v1.2.1