summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorBruno de Oliveira Abinader <bruno@mapbox.com>2015-11-12 17:19:34 +0200
committerMinh Nguyễn <mxn@1ec5.org>2015-11-12 10:46:50 -0800
commit8b76f00d8cc617abb492c368fc6887183147402b (patch)
tree584e43e8147ec69be9097a0c52f4309fe639593a /include
parent6748b6155e0bdb61aa33ecfe467711ce7e1189c3 (diff)
downloadqtlocation-mapboxgl-8b76f00d8cc617abb492c368fc6887183147402b.tar.gz
[core] PrecisionPoint is now a vec2<double>
We could reuse all the operators defined in vec2<>, including operator bool() that checks if the contained values are !NaN.
Diffstat (limited to 'include')
-rw-r--r--include/mbgl/map/map.hpp2
-rw-r--r--include/mbgl/util/geo.hpp24
-rw-r--r--include/mbgl/util/vec.hpp17
3 files changed, 21 insertions, 22 deletions
diff --git a/include/mbgl/map/map.hpp b/include/mbgl/map/map.hpp
index 823fcd4f21..f2e605141b 100644
--- a/include/mbgl/map/map.hpp
+++ b/include/mbgl/map/map.hpp
@@ -124,7 +124,7 @@ public:
void setBearing(double degrees, const Duration& = Duration::zero());
void setBearing(double degrees, const PrecisionPoint&);
double getBearing() const;
- void resetNorth();
+ void resetNorth(const Duration& = std::chrono::milliseconds(500));
// Pitch
void setPitch(double pitch, const Duration& = Duration::zero());
diff --git a/include/mbgl/util/geo.hpp b/include/mbgl/util/geo.hpp
index dd2b1567fc..98b5daa6f5 100644
--- a/include/mbgl/util/geo.hpp
+++ b/include/mbgl/util/geo.hpp
@@ -9,17 +9,7 @@ namespace mbgl {
class TileID;
-struct PrecisionPoint {
- double x = 0;
- double y = 0;
-
- inline PrecisionPoint(double x_ = 0, double y_ = 0)
- : x(x_), y(y_) {}
-
- inline bool isValid() const {
- return !(std::isnan(x) || std::isnan(y));
- }
-};
+using PrecisionPoint = vec2<double>;
struct LatLng {
double latitude = 0;
@@ -28,7 +18,7 @@ struct LatLng {
inline LatLng(double lat = 0, double lon = 0)
: latitude(lat), longitude(lon) {}
- inline bool isValid() const {
+ inline operator bool() const {
return !(std::isnan(latitude) || std::isnan(longitude));
}
@@ -45,7 +35,7 @@ struct ProjectedMeters {
inline ProjectedMeters(double n = 0, double e = 0)
: northing(n), easting(e) {}
- inline bool isValid() const {
+ inline operator bool() const {
return !(std::isnan(northing) || std::isnan(easting));
}
};
@@ -57,8 +47,8 @@ struct LatLngBounds {
inline LatLngBounds(const LatLng& sw_ = {90, 180}, const LatLng& ne_ = {-90, -180})
: sw(sw_), ne(ne_) {}
- inline bool isValid() const {
- return sw.isValid() && ne.isValid();
+ inline operator bool() const {
+ return sw && ne;
}
// Constructs a LatLngBounds object with the tile's exact boundaries.
@@ -98,8 +88,8 @@ struct MetersBounds {
inline MetersBounds(const ProjectedMeters& sw_, const ProjectedMeters& ne_)
: sw(sw_), ne(ne_) {}
- inline bool isValid() const {
- return sw.isValid() && ne.isValid();
+ inline operator bool() const {
+ return sw && ne;
}
};
diff --git a/include/mbgl/util/vec.hpp b/include/mbgl/util/vec.hpp
index 052dffcfa1..4d2d6f6a74 100644
--- a/include/mbgl/util/vec.hpp
+++ b/include/mbgl/util/vec.hpp
@@ -41,13 +41,22 @@ struct vec2 {
return {x * o, y * o};
}
- template <typename O>
- inline typename std::enable_if<std::is_arithmetic<O>::value, vec2>::type &
- operator*=(O o) {
+ inline void operator*=(T o) {
x *= o;
y *= o;
}
+ template <typename O>
+ inline typename std::enable_if<std::is_arithmetic<O>::value, vec2>::type
+ operator/(O o) const {
+ return {x / o, y / o};
+ }
+
+ inline void operator/=(T o) {
+ x /= o;
+ y /= o;
+ }
+
inline vec2<T> operator *(const std::array<float, 16>& matrix) {
return { x * matrix[0] + y * matrix[4] + matrix[12], x * matrix[1] + y * matrix[5] + matrix[13] };
}
@@ -111,7 +120,7 @@ struct vec4 {
};
-typedef vec2<int16_t> Coordinate;
+using Coordinate = vec2<int16_t>;
}