fix integer division to work in doubles in transform.cpp

This commit is contained in:
Dane Springmeyer
2015-05-03 23:23:13 -07:00
parent aa19f07ccf
commit 33f30aae93

View File

@@ -199,14 +199,14 @@ void Transform::_setScale(double new_scale, double cx, double cy, const Duration
// Zoom in on the center if we don't have click or gesture anchor coordinates.
if (cx < 0 || cy < 0) {
cx = current.width / 2;
cy = current.height / 2;
cx = static_cast<double>(current.width) / 2.0;
cy = static_cast<double>(current.height) / 2.0;
}
// Account for the x/y offset from the center (= where the user clicked or pinched)
const double factor = new_scale / current.scale;
const double dx = (cx - current.width / 2) * (1.0 - factor);
const double dy = (cy - current.height / 2) * (1.0 - factor);
const double dx = (cx - static_cast<double>(current.width) / 2.0) * (1.0 - factor);
const double dy = (cy - static_cast<double>(current.height) / 2.0) * (1.0 - factor);
// Account for angle
const double angle_sin = std::sin(-current.angle);
@@ -289,7 +289,7 @@ void Transform::rotateBy(const double start_x, const double start_y, const doubl
const double end_y, const Duration duration) {
std::lock_guard<std::recursive_mutex> lock(mtx);
double center_x = current.width / 2, center_y = current.height / 2;
double center_x = static_cast<double>(current.width) / 2.0, center_y = static_cast<double>(current.height) / 2.0;
const double begin_center_x = start_x - center_x;
const double begin_center_y = start_y - center_y;
@@ -328,8 +328,8 @@ void Transform::setAngle(const double new_angle, const double cx, const double c
double dx = 0, dy = 0;
if (cx >= 0 && cy >= 0) {
dx = (final.width / 2) - cx;
dy = (final.height / 2) - cy;
dx = (static_cast<double>(final.width) / 2.0) - cx;
dy = (static_cast<double>(final.height) / 2.0) - cy;
_moveBy(dx, dy, Duration::zero());
}