[core] Do not constrain on X axis in ConstrainMode::HeightOnly

This commit is contained in:
Bruno de Oliveira Abinader
2018-08-12 12:32:49 +03:00
parent 0ef0a9763c
commit 19179e08bc
4 changed files with 32 additions and 27 deletions

View File

@@ -352,20 +352,25 @@ bool TransformState::rotatedNorth() const {
}
void TransformState::constrain(double& scale_, double& x_, double& y_) const {
// Constrain minimum scale to avoid zooming out far enough to show off-world areas.
scale_ = util::max(scale_,
static_cast<double>(rotatedNorth() ? size.height : size.width) / util::tileSize,
static_cast<double>(rotatedNorth() ? size.width : size.height) / util::tileSize);
// Constrain min/max pan to avoid showing off-world areas.
if (constrainMode == ConstrainMode::WidthAndHeight) {
double max_x = (scale_ * util::tileSize - (rotatedNorth() ? size.height : size.width)) / 2;
x_ = std::max(-max_x, std::min(x_, max_x));
if (constrainMode == ConstrainMode::None) {
return;
}
if (constrainMode != ConstrainMode::None) {
double max_y = (scale_ * util::tileSize - (rotatedNorth() ? size.width : size.height)) / 2;
y_ = std::max(-max_y, std::min(y_, max_y));
const double ratioX = (rotatedNorth() ? size.height : size.width) / util::tileSize;
const double ratioY = (rotatedNorth() ? size.width : size.height) / util::tileSize;
// Constrain minimum scale to avoid zooming out far enough to show off-world areas on the Y axis.
// If Y axis ratio is too small to be constrained, use X axis ratio instead.
scale_ = util::max(scale_, ratioY < 1.0 ? ratioX : ratioY);
// Constrain min/max pan to avoid showing off-world areas on the Y axis.
double max_y = (scale_ * util::tileSize - (rotatedNorth() ? size.width : size.height)) / 2;
y_ = std::max(-max_y, std::min(y_, max_y));
if (constrainMode == ConstrainMode::WidthAndHeight) {
// Constrain min/max pan to avoid showing off-world areas on the X axis.
double max_x = (scale_ * util::tileSize - (rotatedNorth() ? size.height : size.width)) / 2;
x_ = std::max(-max_x, std::min(x_, max_x));
}
}