[core] Update ZoomHistory.lastInteger{Zoom,Time} if different from floor zoom

This commit is contained in:
Bruno de Oliveira Abinader
2017-08-13 12:20:03 +03:00
parent d21f19686b
commit 80e4b2f1ab

View File

@@ -8,34 +8,39 @@ namespace mbgl {
struct ZoomHistory {
float lastZoom;
float lastFloorZoom;
float lastIntegerZoom;
TimePoint lastIntegerZoomTime;
bool first = true;
bool update(float z, const TimePoint& now) {
constexpr TimePoint zero = TimePoint(Duration::zero());
const float floorZ = std::floor(z);
if (first) {
first = false;
lastIntegerZoom = std::floor(z);
lastIntegerZoom = floorZ;
lastIntegerZoomTime = zero;
lastZoom = z;
lastFloorZoom = floorZ;
return true;
} else {
if (std::floor(lastZoom) < std::floor(z)) {
lastIntegerZoom = std::floor(z);
lastIntegerZoomTime = now == Clock::time_point::max() ? zero : now;
} else if (std::floor(lastZoom) > std::floor(z)) {
lastIntegerZoom = std::floor(z + 1);
lastIntegerZoomTime = now == Clock::time_point::max() ? zero : now;
}
if (z != lastZoom) {
lastZoom = z;
return true;
}
return false;
}
if (lastFloorZoom > floorZ) {
lastIntegerZoom = floorZ + 1;
lastIntegerZoomTime = now == Clock::time_point::max() ? zero : now;
} else if (lastFloorZoom < floorZ || lastIntegerZoom != floorZ) {
lastIntegerZoom = floorZ;
lastIntegerZoomTime = now == Clock::time_point::max() ? zero : now;
}
if (z != lastZoom) {
lastZoom = z;
lastFloorZoom = floorZ;
return true;
}
return false;
}
};