diff options
author | Minh Nguyễn <mxn@1ec5.org> | 2015-11-11 15:02:05 -0800 |
---|---|---|
committer | Minh Nguyễn <mxn@1ec5.org> | 2015-11-12 10:46:43 -0800 |
commit | aae7f90e37ac9c074c3bc2205116d9827045027c (patch) | |
tree | 8b8a06182113adbe422c9c65d63f557953b22ecf | |
parent | b918b5167273ee46f7eaad8ed2384f3dd6cf1bfa (diff) | |
download | qtlocation-mapboxgl-aae7f90e37ac9c074c3bc2205116d9827045027c.tar.gz |
[core] Fixed Transform::_setScale()
Corrected Transform::_setScale() after the refactoring in 5a24ac605b23ae1d28ac052eb6eeae559db3bb79 for #2994. This change also addresses two dead store warnings from the static analyzer.
-rw-r--r-- | src/mbgl/map/transform.cpp | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/src/mbgl/map/transform.cpp b/src/mbgl/map/transform.cpp index cf39f2d32d..dac4018627 100644 --- a/src/mbgl/map/transform.cpp +++ b/src/mbgl/map/transform.cpp @@ -310,25 +310,28 @@ void Transform::rotateBy(const PrecisionPoint& first, const PrecisionPoint& seco return; } - double center_x = static_cast<double>(state.width) / 2.0; - double center_y = static_cast<double>(state.height) / 2.0; - const double first_x = first.x - center_x; - const double first_y = first.y - center_y; - const double second_x = second.x - center_x; - const double second_y = second.y - center_y; - const double beginning_center_dist = std::sqrt(first_x * first_x + first_y * first_y); + double center_x = static_cast<double>(state.width) / 2.0, center_y = static_cast<double>(state.height) / 2.0; + + 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); // 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(first_y, first_x); + 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; } + 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); _setAngle(ang, duration); |