/
local_minimum.hpp
116 lines (100 loc) · 3.21 KB
/
local_minimum.hpp
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
107
108
109
110
111
112
113
114
115
116
#pragma once
#ifdef DEBUG
#include <iostream>
#endif
#include <queue>
#include <mapbox/geometry/wagyu/bound.hpp>
namespace mapbox {
namespace geometry {
namespace wagyu {
template <typename T>
struct local_minimum {
bound<T> left_bound;
bound<T> right_bound;
T y;
bool minimum_has_horizontal;
local_minimum(bound<T>&& left_bound_, bound<T>&& right_bound_, T y_, bool has_horz_)
: left_bound(std::move(left_bound_)),
right_bound(std::move(right_bound_)),
y(y_),
minimum_has_horizontal(has_horz_) {
}
};
template <typename T>
using local_minimum_list = std::deque<local_minimum<T>>;
template <typename T>
using local_minimum_itr = typename local_minimum_list<T>::iterator;
template <typename T>
using local_minimum_ptr = local_minimum<T>*;
template <typename T>
using local_minimum_ptr_list = std::vector<local_minimum_ptr<T>>;
template <typename T>
using local_minimum_ptr_list_itr = typename local_minimum_ptr_list<T>::iterator;
template <typename T>
struct local_minimum_sorter {
inline bool operator()(local_minimum_ptr<T> const& locMin1,
local_minimum_ptr<T> const& locMin2) {
if (locMin2->y == locMin1->y) {
return locMin2->minimum_has_horizontal != locMin1->minimum_has_horizontal &&
locMin1->minimum_has_horizontal;
}
return locMin2->y < locMin1->y;
}
};
#ifdef DEBUG
template <class charT, class traits, typename T>
inline std::basic_ostream<charT, traits>& operator<<(std::basic_ostream<charT, traits>& out,
const local_minimum<T>& lm) {
out << " Local Minimum:" << std::endl;
out << " y: " << lm.y << std::endl;
if (lm.minimum_has_horizontal) {
out << " minimum_has_horizontal: true" << std::endl;
} else {
out << " minimum_has_horizontal: false" << std::endl;
}
out << " left_bound: " << std::endl;
out << lm.left_bound << std::endl;
out << " right_bound: " << std::endl;
out << lm.right_bound << std::endl;
return out;
}
template <class charT, class traits, typename T>
inline std::basic_ostream<charT, traits>& operator<<(std::basic_ostream<charT, traits>& out,
const local_minimum_ptr_list<T>& lms) {
for (auto const& lm : lms) {
out << *lm;
}
return out;
}
template <typename T>
std::string output_all_edges(local_minimum_ptr_list<T> const& lms) {
std::ostringstream out;
out << "[";
bool first = true;
for (auto const& lm : lms) {
for (auto const& e : lm->left_bound.edges) {
if (first) {
first = false;
} else {
out << ",";
}
out << "[[" << e.bot.x << "," << e.bot.y << "],[";
out << e.top.x << "," << e.top.y << "]]";
}
for (auto const& e : lm->right_bound.edges) {
if (first) {
first = false;
} else {
out << ",";
}
out << "[[" << e.bot.x << "," << e.bot.y << "],[";
out << e.top.x << "," << e.top.y << "]]";
}
}
out << "]";
return out.str();
}
#endif
}
}
}