aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/geo/bbox.h
blob: 7ec7e6f7d6b151004f2a5663ce5cef0922c098b7 (plain) (blame)
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
48
49
50
51
52
53
54
55
56
57
58
59
#pragma once

#include <util/generic/utility.h>

#include "point.h"

namespace NGeo {

    class TGeoBoundingBox {
    public:
        TGeoBoundingBox()

            = default;

        TGeoBoundingBox(const TGeoPoint& p1, const TGeoPoint& p2) {
            MinX_ = Min(p1.Lon(), p2.Lon());
            MaxX_ = Max(p1.Lon(), p2.Lon());
            MinY_ = Min(p1.Lat(), p2.Lat());
            MaxY_ = Max(p1.Lat(), p2.Lat());
        }

        const double& GetMinX() const {
            return MinX_;
        }

        const double& GetMaxX() const {
            return MaxX_;
        }

        const double& GetMinY() const {
            return MinY_;
        }

        const double& GetMaxY() const {
            return MaxY_;
        }

        double Width() const {
            return MaxX_ - MinX_;
        }

        double Height() const {
            return MaxY_ - MinY_;
        }

    private:
        double MinX_{std::numeric_limits<double>::quiet_NaN()};
        double MaxX_{std::numeric_limits<double>::quiet_NaN()};
        double MinY_{std::numeric_limits<double>::quiet_NaN()};
        double MaxY_{std::numeric_limits<double>::quiet_NaN()};
    };

    inline bool operator==(const TGeoBoundingBox& a, const TGeoBoundingBox& b) {
        return a.GetMinX() == b.GetMinX() &&
               a.GetMinY() == b.GetMinY() &&
               a.GetMaxX() == b.GetMaxX() &&
               a.GetMaxY() == b.GetMaxY();
    }
} // namespace NGeo