summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBruno de Oliveira Abinader <bruno@mapbox.com>2015-11-12 17:21:00 +0200
committerMinh Nguyễn <mxn@1ec5.org>2015-11-12 10:46:50 -0800
commitfc2fa73363b04f02b112b02c73f33549985b5720 (patch)
tree77cfdcb22da73954e77574cac30fa26769c5cda9 /src
parent8b76f00d8cc617abb492c368fc6887183147402b (diff)
downloadqtlocation-mapboxgl-fc2fa73363b04f02b112b02c73f33549985b5720.tar.gz
[core] Cleanup Transform::rotateBy
Make use of PrecisionPoint's operator functionalities inherited from vec2<> and reduced overhead eg. offset_y is always 0 so no need to add this to calculation inside the if.
Diffstat (limited to 'src')
-rw-r--r--src/mbgl/map/transform.cpp29
1 files changed, 12 insertions, 17 deletions
diff --git a/src/mbgl/map/transform.cpp b/src/mbgl/map/transform.cpp
index b932c8cb38..3c451d00eb 100644
--- a/src/mbgl/map/transform.cpp
+++ b/src/mbgl/map/transform.cpp
@@ -310,29 +310,24 @@ void Transform::rotateBy(const PrecisionPoint& first, const PrecisionPoint& seco
return;
}
- double center_x = static_cast<double>(state.width) / 2.0, center_y = static_cast<double>(state.height) / 2.0;
+ PrecisionPoint center(state.width, state.height);
+ center /= 2;
- const double begin_center_x = first.x - center_x;
- const double begin_center_y = first.y - center_y;
-
- const double beginning_center_dist =
- std::sqrt(begin_center_x * begin_center_x + begin_center_y * begin_center_y);
+ const PrecisionPoint offset = first - center;
+ const double distance = std::sqrt(std::pow(2, offset.x) + std::pow(2, offset.y));
// If the first click was too close to the center, move the center of rotation by 200 pixels
// in the direction of the click.
- if (beginning_center_dist < 200) {
- const double offset_x = -200, offset_y = 0;
- const double rotate_angle = std::atan2(begin_center_y, begin_center_x);
- const double rotate_angle_sin = std::sin(rotate_angle);
- const double rotate_angle_cos = std::cos(rotate_angle);
- center_x = first.x + rotate_angle_cos * offset_x - rotate_angle_sin * offset_y;
- center_y = first.y + rotate_angle_sin * offset_x + rotate_angle_cos * offset_y;
+ if (distance < 200) {
+ const double heightOffset = -200;
+ const double rotateAngle = std::atan2(offset.y, offset.x);
+ center.x = first.x + std::cos(rotateAngle) * heightOffset;
+ center.y = first.y + std::sin(rotateAngle) * heightOffset;
}
- const double first_x = first.x - center_x, first_y = first.y - center_y;
- const double second_x = second.x - center_x, second_y = second.y - center_y;
-
- const double ang = state.angle + util::angle_between(first_x, first_y, second_x, second_y);
+ const PrecisionPoint newFirst = first - center;
+ const PrecisionPoint newSecond = second - center;
+ const double ang = state.angle + util::angle_between(newFirst.x, newFirst.y, newSecond.x, newSecond.y);
_setAngle(ang, duration);
}