-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathrvg-decorated-path-f-forward-and-backward.h
213 lines (172 loc) · 6.38 KB
/
rvg-decorated-path-f-forward-and-backward.h
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
// Stroke-to-fill conversion program and test harness
// Copyright (C) 2020 Diego Nehab
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// Contact information: diego.nehab@gmail.com
//
#ifndef RVG_DECORATED_PATH_F_FORWARD_AND_BACKWARD_H
#define RVG_DECORATED_PATH_F_FORWARD_AND_BACKWARD_H
#include <utility>
#include "rvg-i-point-regular-path.h"
#include "rvg-i-point-decorated-path.h"
#include "rvg-i-monotonic-parameters.h"
#include "rvg-i-dashing-parameters.h"
#include "rvg-i-offsetting-parameters.h"
#include "rvg-path-data.h"
namespace rvg {
template <typename SINK>
class decorated_path_f_forward_and_backward final:
public i_sink<decorated_path_f_forward_and_backward<SINK>>,
public i_point_regular_path<decorated_path_f_forward_and_backward<SINK>>,
public i_parameters_f_hold<decorated_path_f_forward_and_backward<SINK>>,
public i_point_decorated_path<decorated_path_f_forward_and_backward<SINK>> {
path_data m_saved;
SINK m_sink;
public:
explicit decorated_path_f_forward_and_backward(SINK &&sink):
m_sink(std::forward<SINK>(sink)) {
static_assert(rvg::meta::is_an_i_regular_path<SINK>::value,
"sink is not an i_regular_path");
static_assert(rvg::meta::is_an_i_decorated_path<SINK>::value,
"sink is not an i_decorated_path");
static_assert(rvg::meta::is_an_i_dashing_parameters<SINK>::value,
"sink is not an i_dashing_parameters");
}
void flush(void) {
m_saved.iterate(m_sink);
m_saved.riterate(m_sink);
m_saved.clear();
}
private:
friend i_sink<decorated_path_f_forward_and_backward<SINK>>;
path_data &do_sink(void) {
return m_saved; // so parameters_f_hold sends parameters to m_saved
}
const path_data &do_sink(void) const {
return m_saved; // so parameters_f_hold sends parameters to m_saved
}
friend i_point_decorated_path<decorated_path_f_forward_and_backward<SINK>>;
void do_initial_cap(const R2 &p, const R2 &d) {
m_saved.initial_cap(p, d);
}
void do_terminal_cap(const R2 &d, const R2 &p) {
m_saved.terminal_cap(d, p);
flush();
}
void do_backward_initial_cap(const R2 &p, const R2 &d) {
(void) p; (void) d;
assert(0);
}
void do_backward_terminal_cap(const R2 &d, const R2 &p) {
(void) p; (void) d;
assert(0);
}
void do_initial_butt_cap(const R2 &p, const R2 &d) {
m_saved.initial_butt_cap(p, d);
}
void do_terminal_butt_cap(const R2 &d, const R2 &p) {
m_saved.terminal_butt_cap(d, p);
flush();
}
void do_backward_initial_butt_cap(const R2 &p, const R2 &d) {
(void) p; (void) d;
assert(0);
}
void do_backward_terminal_butt_cap(const R2 &d, const R2 &p) {
(void) p; (void) d;
assert(0);
}
void do_join(const R2 &d0, const R2 &p, const R2 &d1, rvgf w) {
m_saved.join(d0, p, d1, w);
}
void do_inner_join(const R2 &d0, const R2 &p, const R2 &d1, rvgf w) {
m_saved.inner_join(d0, p, d1, w);
}
friend i_point_regular_path<decorated_path_f_forward_and_backward<SINK>>;
void do_begin_regular_contour(const R2 &, const R2 &) {
assert(0); // should have been filtered out
}
void do_end_regular_open_contour(const R2 &, const R2 &) {
assert(0); // should have been filtered out
}
void do_end_regular_closed_contour(const R2 &, const R2 &) {
assert(0); // should have been filtered out
}
void do_begin_segment_piece(const R2 &, const R2 &) {
assert(0); // should have been filtered out
}
void do_end_segment_piece(const R2 &, const R2 &) {
assert(0); // should have been filtered out
}
void do_degenerate_segment(const R2 &p0, const R2 &d, const R2 &p1) {
m_saved.degenerate_segment(p0, d, p1);
}
void do_cusp(const R2 &d0, const R2 &p, const R2 &d1, rvgf w) {
m_saved.cusp(d0, p, d1, w);
}
void do_inner_cusp(const R2 &d0, const R2 &p, const R2 &d1, rvgf w) {
m_saved.inner_cusp(d0, p, d1, w);
}
template <typename PIECE>
void process_segment(rvgf ti, rvgf tf, const PIECE &piece) {
this->sort_parameters();
auto t0 = ti;
for (auto &p: this->parameters()) {
const auto &t = p.second.f;
if (p.first == path_instruction::end_dash_parameter) {
this->forward_parameters(t0, t);
m_saved.end_dash_parameter(t);
piece();
flush();
t0 = tf;
} else if (p.first == path_instruction::begin_dash_parameter) {
m_saved.begin_dash_parameter(t);
t0 = t;
}
}
if (t0 < tf) {
this->forward_parameters(t0, tf);
piece();
}
this->clear_parameters();
}
void do_linear_segment_piece(rvgf ti, rvgf tf, const R2 &p0, const R2 &p1) {
process_segment(ti, tf, [&](void) {
m_saved.linear_segment_piece(ti, tf, p0, p1);
});
}
void do_quadratic_segment_piece(rvgf ti, rvgf tf, const R2 &p0,
const R2 &p1, const R2 &p2) {
process_segment(ti, tf, [&](void) {
m_saved.quadratic_segment_piece(ti, tf, p0, p1, p2);
});
}
void do_rational_quadratic_segment_piece(rvgf ti, rvgf tf, const R3 &p0,
const R3 &p1, const R3 &p2) {
process_segment(ti, tf, [&](void) {
m_saved.rational_quadratic_segment_piece(ti, tf, p0, p1, p2);
});
}
void do_cubic_segment_piece(rvgf ti, rvgf tf, const R2 &p0, const R2 &p1,
const R2 &p2, const R2 &p3) {
process_segment(ti, tf, [&](void) {
m_saved.cubic_segment_piece(ti, tf, p0, p1, p2, p3);
});
}
};
template <typename SINK>
static auto
make_decorated_path_f_forward_and_backward(SINK &&sink) {
return decorated_path_f_forward_and_backward<SINK>{std::forward<SINK>(sink)};
}
} // namespace rvg
#endif