summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruno de Oliveira Abinader <bruno@mapbox.com>2016-03-08 18:30:28 +0200
committerBruno de Oliveira Abinader <bruno@mapbox.com>2016-03-10 03:36:46 +0200
commitd300f341bca4d4fe295a6dd303c0961bff7a0520 (patch)
tree5c3e2f9241a46a42ff1aae013a16beec4d759339
parentdc2853533f4e641ac192ebca5458f876109441ff (diff)
downloadqtlocation-mapboxgl-d300f341bca4d4fe295a6dd303c0961bff7a0520.tar.gz
[core] Remove _validPoint from Transform code
vec2<T>::operator bool() checks for NaNs already.
-rw-r--r--include/mbgl/util/vec.hpp25
-rw-r--r--src/mbgl/map/transform.cpp14
2 files changed, 28 insertions, 11 deletions
diff --git a/include/mbgl/util/vec.hpp b/include/mbgl/util/vec.hpp
index 83530a1798..a8bbd14b0f 100644
--- a/include/mbgl/util/vec.hpp
+++ b/include/mbgl/util/vec.hpp
@@ -105,6 +105,18 @@ struct vec3 {
inline bool operator==(const vec3& rhs) const {
return x == rhs.x && y == rhs.y && z == rhs.z;
}
+
+ template<typename U = T, typename std::enable_if<std::numeric_limits<U>::has_quiet_NaN, int>::type = 0>
+ inline operator bool() const {
+ return !std::isnan(x) && !std::isnan(y) && !std::isnan(z);
+ }
+
+ template<typename U = T, typename std::enable_if<!std::numeric_limits<U>::has_quiet_NaN, int>::type = 0>
+ inline operator bool() const {
+ return x != std::numeric_limits<T>::min()
+ && y != std::numeric_limits<T>::min()
+ && z != std::numeric_limits<T>::min();
+ }
};
template <typename T = double>
@@ -117,6 +129,19 @@ struct vec4 {
inline bool operator==(const vec4& rhs) const {
return x == rhs.x && y == rhs.y && z == rhs.z && w == rhs.w;
}
+
+ template<typename U = T, typename std::enable_if<std::numeric_limits<U>::has_quiet_NaN, int>::type = 0>
+ inline operator bool() const {
+ return !std::isnan(x) && !std::isnan(y) && !std::isnan(z) && !std::isnan(w);
+ }
+
+ template<typename U = T, typename std::enable_if<!std::numeric_limits<U>::has_quiet_NaN, int>::type = 0>
+ inline operator bool() const {
+ return x != std::numeric_limits<T>::min()
+ && y != std::numeric_limits<T>::min()
+ && z != std::numeric_limits<T>::min()
+ && w != std::numeric_limits<T>::min();
+ }
};
diff --git a/src/mbgl/map/transform.cpp b/src/mbgl/map/transform.cpp
index 79b43f8901..6aa0bd9a41 100644
--- a/src/mbgl/map/transform.cpp
+++ b/src/mbgl/map/transform.cpp
@@ -35,10 +35,6 @@ static double _normalizeAngle(double angle, double anchorAngle)
return angle;
}
-inline bool _validPoint(const ScreenCoordinate& point) {
- return !std::isnan(point.x) && !std::isnan(point.y);
-}
-
Transform::Transform(View &view_, ConstrainMode constrainMode)
: view(view_)
, state(constrainMode)
@@ -341,9 +337,7 @@ void Transform::flyTo(const CameraOptions &camera, const AnimationOptions &anima
#pragma mark - Position
void Transform::moveBy(const ScreenCoordinate& offset, const Duration& duration) {
- if (!_validPoint(offset)) {
- return;
- }
+ if (!offset) return;
ScreenCoordinate centerOffset = {
offset.x,
@@ -583,7 +577,7 @@ void Transform::startTransition(const CameraOptions& camera,
// Associate the anchor, if given, with a coordinate.
ScreenCoordinate anchor = camera.anchor ? *camera.anchor : ScreenCoordinate(NAN, NAN);
LatLng anchorLatLng;
- if (_validPoint(anchor)) {
+ if (anchor) {
anchor.y = state.getHeight() - anchor.y;
anchorLatLng = state.screenCoordinateToLatLng(anchor);
}
@@ -601,9 +595,7 @@ void Transform::startTransition(const CameraOptions& camera,
result = frame(ease.solve(t, 0.001));
}
- if (_validPoint(anchor)) {
- state.moveLatLng(anchorLatLng, anchor);
- }
+ if (anchor) state.moveLatLng(anchorLatLng, anchor);
// At t = 1.0, a DidChangeAnimated notification should be sent from finish().
if (t < 1.0) {