1 #pragma once 2 3 #include <mbgl/util/chrono.hpp> 4 5 #include <cmath> 6 7 namespace mbgl { 8 9 struct ZoomHistory { 10 float lastZoom; 11 float lastFloorZoom; 12 float lastIntegerZoom; 13 TimePoint lastIntegerZoomTime; 14 bool first = true; 15 updatembgl::ZoomHistory16 bool update(float z, const TimePoint& now) { 17 constexpr TimePoint zero = TimePoint(Duration::zero()); 18 const float floorZ = std::floor(z); 19 20 if (first) { 21 first = false; 22 lastIntegerZoom = floorZ; 23 lastIntegerZoomTime = zero; 24 lastZoom = z; 25 lastFloorZoom = floorZ; 26 return true; 27 } 28 29 if (lastFloorZoom > floorZ) { 30 lastIntegerZoom = floorZ + 1; 31 lastIntegerZoomTime = now == Clock::time_point::max() ? zero : now; 32 } else if (lastFloorZoom < floorZ) { 33 lastIntegerZoom = floorZ; 34 lastIntegerZoomTime = now == Clock::time_point::max() ? zero : now; 35 } 36 37 if (z != lastZoom) { 38 lastZoom = z; 39 lastFloorZoom = floorZ; 40 return true; 41 } 42 43 return false; 44 } 45 }; 46 47 } // namespace mbgl 48