[core] Avoid NaNs in TransformState unit conversions

Fix cases where e.g. state has either zero width or height, causing the
unit convertion functions would return NaNs.
This commit is contained in:
Bruno de Oliveira Abinader
2016-05-19 19:03:41 +03:00
parent b962b56072
commit f751d2c465
3 changed files with 63 additions and 16 deletions

View File

@@ -45,24 +45,23 @@ Transform::Transform(std::function<void(MapChange)> callback_,
#pragma mark - Map View
bool Transform::resize(const std::array<uint16_t, 2> size) {
if (state.width != size[0] || state.height != size[1]) {
if (callback) {
callback(MapChangeRegionWillChange);
}
state.width = size[0];
state.height = size[1];
state.constrain(state.scale, state.x, state.y);
if (callback) {
callback(MapChangeRegionDidChange);
}
return true;
} else {
if (state.width == size[0] && state.height == size[1]) {
return false;
}
if (callback) {
callback(MapChangeRegionWillChange);
}
state.width = size[0];
state.height = size[1];
state.constrain(state.scale, state.x, state.y);
if (callback) {
callback(MapChangeRegionDidChange);
}
return true;
}
#pragma mark - Camera