blob: 7821499d726d75bc57f0d57198ee4ef8b408eccd (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
#pragma once
#include <mbgl/util/chrono.hpp>
#include <cmath>
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 = floorZ;
lastIntegerZoomTime = zero;
lastZoom = z;
lastFloorZoom = floorZ;
return true;
}
if (lastFloorZoom > floorZ) {
lastIntegerZoom = floorZ + 1;
lastIntegerZoomTime = now == Clock::time_point::max() ? zero : now;
} else if (lastFloorZoom < floorZ) {
lastIntegerZoom = floorZ;
lastIntegerZoomTime = now == Clock::time_point::max() ? zero : now;
}
if (z != lastZoom) {
lastZoom = z;
lastFloorZoom = floorZ;
return true;
}
return false;
}
};
} // namespace mbgl
|