From aae7f90e37ac9c074c3bc2205116d9827045027c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguy=E1=BB=85n?= Date: Wed, 11 Nov 2015 15:02:05 -0800 Subject: [PATCH] [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. --- src/mbgl/map/transform.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/mbgl/map/transform.cpp b/src/mbgl/map/transform.cpp index cf39f2d32..dac401862 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(state.width) / 2.0; - double center_y = static_cast(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(state.width) / 2.0, center_y = static_cast(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);