Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[core] Remove _validPoint from Transform code
Browse files Browse the repository at this point in the history
vec2<T>::operator bool() checks for NaNs already.
  • Loading branch information
brunoabinader committed Mar 10, 2016
1 parent dc28535 commit d300f34
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 11 deletions.
25 changes: 25 additions & 0 deletions include/mbgl/util/vec.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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();
}
};


Expand Down
14 changes: 3 additions & 11 deletions src/mbgl/map/transform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);
}
Expand All @@ -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) {
Expand Down

2 comments on commit d300f34

@jfirebaugh
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make the operator bool()s explicit.

@brunoabinader
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is already merged - will do in a separate patch 👍

Please sign in to comment.