summaryrefslogtreecommitdiff
path: root/matching/include/dual_box.h
blob: 0e4f4d535f7f4e0109b8ba838a892a675168688a (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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#ifndef MATCHING_DISTANCE_DUAL_BOX_H
#define MATCHING_DISTANCE_DUAL_BOX_H

#include <ostream>
#include <limits>
#include <vector>
#include <random>

#include "spdlog/spdlog.h"
#include "spdlog/fmt/ostr.h"


#include "common_util.h"
#include "dual_point.h"

namespace md {


    template<class Real>
    class DualBox {
    public:

        DualBox(DualPoint<Real> ll, DualPoint<Real> ur);

        DualBox() = default;
        DualBox(const DualBox&) = default;
        DualBox(DualBox&&) = default;

        DualBox& operator=(const DualBox& other) & = default;
        DualBox& operator=(DualBox&& other) = default;


        DualPoint<Real> center() const { return midpoint(lower_left_, upper_right_); }
        DualPoint<Real> lower_left() const { return lower_left_; }
        DualPoint<Real> upper_right() const { return upper_right_; }

        DualPoint<Real> lower_right() const;
        DualPoint<Real> upper_left() const;

        AxisType axis_type() const { return lower_left_.axis_type(); }
        AngleType angle_type() const { return lower_left_.angle_type(); }

        Real mu_min() const { return lower_left_.mu(); }
        Real mu_max() const { return upper_right_.mu(); }
        Real lambda_min() const { return lower_left_.lambda(); }
        Real lambda_max() const { return upper_right_.lambda(); }

        // return true, if all lines in dual_box are flat
        bool is_flat() const { return upper_right_.is_flat(); }
        bool is_steep() const { return lower_left_.is_steep(); }

        std::vector<DualBox> refine() const;
        std::vector<DualPoint<Real>> corners() const;
        std::vector<DualPoint<Real>> critical_points(const Point<Real>& p) const;
        // sample n points from the box uniformly; for tests
        std::vector<DualPoint<Real>> random_points(int n) const;

        // return 2 dual points at the boundary
        // where push changes from horizontal to vertical
        std::vector<DualPoint<Real>> push_change_points(const Point<Real>& p) const;

        // check that a has same sign, angles are all flat or all steep
        bool sanity_check() const;
        bool contains(const DualPoint<Real>& dp) const;

        bool operator==(const DualBox& other) const;

    private:
        DualPoint<Real> lower_left_;
        DualPoint<Real> upper_right_;
    };

    template<class Real>
    std::ostream& operator<<(std::ostream& os, const DualBox<Real>& db)
    {
        os << "DualBox(" << db.lower_left() << ", " << db.upper_right() << ")";
        return os;
    }
}

#include "dual_box.hpp"

#endif //MATCHING_DISTANCE_DUAL_BOX_H