summaryrefslogtreecommitdiff
path: root/src/mbgl/map/zoom_history.hpp
blob: 308846b1e3a609a8fb6a20a7347e744a5a1afb1e (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
#pragma once

#include <mbgl/util/chrono.hpp>

#include <cmath>

namespace mbgl {

struct ZoomHistory {
    float lastZoom;
    float lastIntegerZoom;
    TimePoint lastIntegerZoomTime;
    bool first = true;

    bool update(float z, const TimePoint& now) {
        if (first) {
            first = false;
            lastIntegerZoom = std::floor(z);
            lastIntegerZoomTime = TimePoint(Duration::zero());
            lastZoom = z;
            return true;
        } else {
            if (std::floor(lastZoom) < std::floor(z)) {
                lastIntegerZoom = std::floor(z);
                lastIntegerZoomTime = now;
            } else if (std::floor(lastZoom) > std::floor(z)) {
                lastIntegerZoom = std::floor(z + 1);
                lastIntegerZoomTime = now;
            }

            if (z != lastZoom) {
                lastZoom = z;
                return true;
            }

            return false;
        }
    }
};

} // namespace mbgl