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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
//
// Created by narn on 12.02.19.
//
#ifndef MATCHING_DISTANCE_DUAL_POINT_H
#define MATCHING_DISTANCE_DUAL_POINT_H
#include <vector>
#include <ostream>
#include "common_util.h"
#include "box.h"
namespace md {
enum class AxisType {
x_type, y_type
};
enum class AngleType {
flat, steep
};
// class has two flags of AxisType and AngleType.
// ATTENTION. == operator is not overloaded,
// so, e.g., line y = x has 4 different non-equal representation.
// we are unlikely to ever need this, because 4 cases are
// always treated separately.
class DualPoint {
public:
using Real = md::Real;
DualPoint() = default;
DualPoint(const DualPoint&) = default;
DualPoint(DualPoint&&) = default;
DualPoint& operator=(const DualPoint& other)& = default;
DualPoint& operator=(DualPoint&& other) = default;
DualPoint(AxisType axis_type, AngleType angle_type, Real lambda, Real mu);
Real lambda() const { return lambda_; }
Real mu() const { return mu_; }
// angle between line and x-axis
Real gamma() const;
bool is_steep() const { return angle_type_ == AngleType::steep; }
bool is_flat() const { return angle_type_ == AngleType::flat; }
bool is_x_type() const { return axis_type_ == AxisType::x_type; }
bool is_y_type() const { return axis_type_ == AxisType::y_type; }
friend std::ostream& operator<<(std::ostream& os, const DualPoint& dp);
bool operator<(const DualPoint& rhs) const;
AxisType axis_type() const { return axis_type_; }
AngleType angle_type() const { return angle_type_; }
// throw exception, if fields are invalid
// return true otherwise
bool sanity_check() const;
Real weighted_push(Point p) const;
Point push(Point p) const;
bool is_horizontal() const;
bool is_vertical() const;
bool goes_below(Point p) const;
bool goes_above(Point p) const;
bool contains(Point p) const;
Real x_slope() const;
Real y_slope() const;
Real x_intercept() const;
Real y_intercept() const;
Real x_from_y(Real y) const;
Real y_from_x(Real x) const;
Real weight() const;
bool operator==(const DualPoint& other) const;
private:
AxisType axis_type_ {AxisType::y_type};
AngleType angle_type_ {AngleType::flat};
// both initial values are invalid: lambda must be between 0 and 1
Real lambda_ {-1.0};
Real mu_ {-1.0};
};
std::ostream& operator<<(std::ostream& os, const DualPoint& dp);
DualPoint midpoint(DualPoint x, DualPoint y);
};
#endif //MATCHING_DISTANCE_DUAL_POINT_H
|