[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.
This commit is contained in:
Bruno de Oliveira Abinader
2015-11-12 17:19:34 +02:00
committed by Minh Nguyễn
parent 6748b6155e
commit 8b76f00d8c
7 changed files with 41 additions and 43 deletions

View File

@@ -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());

View File

@@ -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;
}
};

View File

@@ -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>;
}