Skip to content

Commit 30d5068

Browse files
committed
Adapt more descriptive variable names
1 parent 8ecfae0 commit 30d5068

File tree

3 files changed

+112
-92
lines changed

3 files changed

+112
-92
lines changed

test/extension/numeric/convolve.cpp

Lines changed: 40 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -129,25 +129,27 @@ struct test_image_5x5_kernel_1x9_boundary_extend_zero
129129
auto img_view = gil::view(img);
130130
image_t img_out(img), img_expected_row(img_view.width(), img_view.height());
131131
image_t img_expected_col(img_view.width(), img_view.height());
132+
unsigned int const kernel_shift_offset = 2;
132133

133134
for (std::ptrdiff_t y = 0; y < img_view.height(); ++y)
134135
{
135136
auto img_it = img_view.row_begin(y);
136137
auto img_expected_row_it = gil::view(img_expected_row).row_begin(y);
137-
for (std::ptrdiff_t x = 2; x < img_view.width(); ++x)
138+
for (std::ptrdiff_t x = kernel_shift_offset; x < img_view.width(); ++x)
138139
img_expected_row_it[x] = img_it[x - 2];
139140
}
140141
for (std::ptrdiff_t x = 0; x < img_view.width(); ++x)
141142
{
142143
auto img_expected_row_it = gil::view(img_expected_row).col_begin(x);
143144
auto img_expected_col_it = gil::view(img_expected_col).col_begin(x);
144-
for (std::ptrdiff_t y = 2; y < img_view.height(); ++y)
145+
for (std::ptrdiff_t y = kernel_shift_offset; y < img_view.height(); ++y)
145146
img_expected_col_it[y] = img_expected_row_it[y - 2];
146147
}
147148

148-
auto const kernel = fixture::create_kernel<channel_t>({0, 0, 0, 0, 0, 0, 1, 0, 0});
149-
gil::detail::convolve_1d<pixel_t>(gil::const_view(img_out), kernel, gil::view(img_out),
150-
boost::gil::boundary_option::extend_zero);
149+
auto const kernel_shift_by_two = fixture::create_kernel<channel_t>(
150+
{0, 0, 0, 0, 0, 0, 1, 0, 0});
151+
gil::detail::convolve_1d<pixel_t>(gil::const_view(img_out), kernel_shift_by_two,
152+
gil::view(img_out), boost::gil::boundary_option::extend_zero);
151153

152154
BOOST_TEST(gil::equal_pixels(gil::const_view(img_out), gil::const_view(img_expected_col)));
153155
}
@@ -169,12 +171,13 @@ struct test_image_5x5_kernel_1x9_boundary_extend_constant
169171
auto img = fixture::generate_image<image_t>(5, 5, fixture::random_value<channel_t>{});
170172
auto img_view = gil::view(img);
171173
image_t img_out(img), img_expected_row(img);
174+
unsigned int const kernel_shift_offset = 2;
172175

173176
for (std::ptrdiff_t y = 0; y < img_view.height(); ++y)
174177
{
175178
auto img_it = img_view.row_begin(y);
176179
auto img_expected_row_it = gil::view(img_expected_row).row_begin(y);
177-
for (std::ptrdiff_t x = 2; x < img_view.width(); ++x)
180+
for (std::ptrdiff_t x = kernel_shift_offset; x < img_view.width(); ++x)
178181
img_expected_row_it[x] = img_it[x - 2];
179182
img_expected_row_it[1] = img_it[0];
180183
}
@@ -183,14 +186,14 @@ struct test_image_5x5_kernel_1x9_boundary_extend_constant
183186
{
184187
auto img_expected_row_it = gil::view(img_expected_row).col_begin(x);
185188
auto img_expected_col_it = gil::view(img_expected_col).col_begin(x);
186-
for (std::ptrdiff_t y = 2; y < img_view.height(); ++y)
189+
for (std::ptrdiff_t y = kernel_shift_offset; y < img_view.height(); ++y)
187190
img_expected_col_it[y] = img_expected_row_it[y - 2];
188191
img_expected_col_it[1] = img_expected_row_it[0];
189192
}
190193

191-
auto const kernel = fixture::create_kernel<channel_t>({0, 0, 0, 0, 0, 0, 1, 0, 0});
192-
gil::detail::convolve_1d<pixel_t>(gil::const_view(img_out), kernel, gil::view(img_out),
193-
boost::gil::boundary_option::extend_constant);
194+
auto const kernel_shift_by_two = fixture::create_kernel<channel_t>({0, 0, 0, 0, 0, 0, 1, 0, 0});
195+
gil::detail::convolve_1d<pixel_t>(gil::const_view(img_out), kernel_shift_by_two,
196+
gil::view(img_out), boost::gil::boundary_option::extend_constant);
194197

195198
BOOST_TEST(gil::equal_pixels(gil::const_view(img_out), gil::const_view(img_expected_col)));
196199
}
@@ -201,7 +204,7 @@ struct test_image_5x5_kernel_1x9_boundary_extend_constant
201204
}
202205
};
203206

204-
struct test_image_5x5_kernel_1x9_boundary_output_zero
207+
struct test_image_5x5_kernel_1x3_boundary_output_zero
205208
{
206209
template <typename Image>
207210
void operator()(Image const&)
@@ -213,36 +216,37 @@ struct test_image_5x5_kernel_1x9_boundary_output_zero
213216
auto img_view = gil::view(img);
214217
image_t img_out(img), img_expected_row(img_view.width(), img_view.height());
215218
image_t img_expected_col(img_view.width(), img_view.height());
219+
unsigned int const kernel_shift_offset = 1;
216220

217221
for (std::ptrdiff_t y = 0; y < img_view.height(); ++y)
218222
{
219223
auto img_it = img_view.row_begin(y);
220224
auto img_expected_row_it = gil::view(img_expected_row).row_begin(y);
221-
for (std::ptrdiff_t x = 1; x < img_view.width() - 1; ++x)
225+
for (std::ptrdiff_t x = kernel_shift_offset; x < img_view.width() - 1; ++x)
222226
img_expected_row_it[x] = img_it[x - 1];
223227
}
224228
for (std::ptrdiff_t x = 0; x < img_view.width(); ++x)
225229
{
226230
auto img_expected_row_it = gil::view(img_expected_row).col_begin(x);
227231
auto img_expected_col_it = gil::view(img_expected_col).col_begin(x);
228-
for (std::ptrdiff_t y = 1; y < img_view.height() - 1; ++y)
232+
for (std::ptrdiff_t y = kernel_shift_offset; y < img_view.height() - 1; ++y)
229233
img_expected_col_it[y] = img_expected_row_it[y - 1];
230234
}
231235

232-
auto const kernel = fixture::create_kernel<channel_t>({0, 0, 1});
233-
gil::detail::convolve_1d<pixel_t>(gil::const_view(img_out), kernel, gil::view(img_out),
234-
boost::gil::boundary_option::output_zero);
236+
auto const kernel_shift_by_one = fixture::create_kernel<channel_t>({0, 0, 1});
237+
gil::detail::convolve_1d<pixel_t>(gil::const_view(img_out), kernel_shift_by_one,
238+
gil::view(img_out), boost::gil::boundary_option::output_zero);
235239

236240
BOOST_TEST(gil::equal_pixels(gil::const_view(img_out), gil::const_view(img_expected_col)));
237241
}
238242
static void run()
239243
{
240244
boost::mp11::mp_for_each<fixture::image_types>(
241-
test_image_5x5_kernel_1x9_boundary_output_zero{});
245+
test_image_5x5_kernel_1x3_boundary_output_zero{});
242246
}
243247
};
244248

245-
struct test_image_5x5_kernel_1x9_boundary_output_ignore
249+
struct test_image_5x5_kernel_1x3_boundary_output_ignore
246250
{
247251
template <typename Image>
248252
void operator()(Image const&)
@@ -253,37 +257,38 @@ struct test_image_5x5_kernel_1x9_boundary_output_ignore
253257
auto img = fixture::generate_image<image_t>(5, 5, fixture::random_value<channel_t>{});
254258
auto img_view = gil::view(img);
255259
image_t img_out(img), img_expected_row(img);
260+
unsigned int const kernel_shift_offset = 1;
256261

257262
for (std::ptrdiff_t y = 0; y < img_view.height(); ++y)
258263
{
259264
auto img_it = img_view.row_begin(y);
260265
auto img_expected_row_it = gil::view(img_expected_row).row_begin(y);
261-
for (std::ptrdiff_t x = 1; x < img_view.width() - 1; ++x)
266+
for (std::ptrdiff_t x = kernel_shift_offset; x < img_view.width() - 1; ++x)
262267
img_expected_row_it[x] = img_it[x - 1];
263268
}
264269
image_t img_expected_col(img_expected_row);
265270
for (std::ptrdiff_t x = 0; x < img_view.width(); ++x)
266271
{
267272
auto img_expected_row_it = gil::view(img_expected_row).col_begin(x);
268273
auto img_expected_col_it = gil::view(img_expected_col).col_begin(x);
269-
for (std::ptrdiff_t y = 1; y < img_view.height() - 1; ++y)
274+
for (std::ptrdiff_t y = kernel_shift_offset; y < img_view.height() - 1; ++y)
270275
img_expected_col_it[y] = img_expected_row_it[y - 1];
271276
}
272277

273-
auto const kernel = fixture::create_kernel<channel_t>({0, 0, 1});
274-
gil::detail::convolve_1d<pixel_t>(gil::const_view(img_out), kernel, gil::view(img_out),
275-
gil::boundary_option::output_ignore);
278+
auto const kernel_shift_by_one = fixture::create_kernel<channel_t>({0, 0, 1});
279+
gil::detail::convolve_1d<pixel_t>(gil::const_view(img_out), kernel_shift_by_one,
280+
gil::view(img_out), gil::boundary_option::output_ignore);
276281

277282
BOOST_TEST(gil::equal_pixels(gil::const_view(img_out), gil::const_view(img_expected_col)));
278283
}
279284
static void run()
280285
{
281286
boost::mp11::mp_for_each<fixture::image_types>(
282-
test_image_5x5_kernel_1x9_boundary_output_ignore{});
287+
test_image_5x5_kernel_1x3_boundary_output_ignore{});
283288
}
284289
};
285290

286-
struct test_image_5x5_kernel_1x9_boundary_extend_padded
291+
struct test_image_5x5_kernel_1x3_boundary_extend_padded
287292
{
288293
template <typename Image>
289294
void operator()(Image const&)
@@ -294,26 +299,27 @@ struct test_image_5x5_kernel_1x9_boundary_extend_padded
294299
auto img = fixture::generate_image<image_t>(5, 5, fixture::random_value<channel_t>{});
295300
auto img_view = gil::view(img);
296301
image_t img_out(img), img_expected_row(img);
302+
unsigned int const kernel_shift_offset = 1;
297303

298304
for (std::ptrdiff_t y = 0; y < img_view.height(); ++y)
299305
{
300306
auto img_it = img_view.row_begin(y);
301307
auto img_expected_row_it = gil::view(img_expected_row).row_begin(y);
302-
for (std::ptrdiff_t x = 1; x < img_view.width(); ++x)
308+
for (std::ptrdiff_t x = kernel_shift_offset; x < img_view.width(); ++x)
303309
img_expected_row_it[x] = img_it[x - 1];
304310
}
305311
image_t img_expected_col(img_expected_row);
306312
for (std::ptrdiff_t x = 0; x < img_view.width(); ++x)
307313
{
308314
auto img_expected_row_it = gil::view(img_expected_row).col_begin(x);
309315
auto img_expected_col_it = gil::view(img_expected_col).col_begin(x);
310-
for (std::ptrdiff_t y = 1; y < img_view.width(); ++y)
316+
for (std::ptrdiff_t y = kernel_shift_offset; y < img_view.width(); ++y)
311317
img_expected_col_it[y] = img_expected_row_it[y - 1];
312318
}
313319

314-
auto const kernel = fixture::create_kernel<channel_t>({0, 0, 1});
315-
gil::detail::convolve_1d<pixel_t>(gil::const_view(img_out), kernel, gil::view(img_out),
316-
gil::boundary_option::extend_padded);
320+
auto const kernel_shift_by_one = fixture::create_kernel<channel_t>({0, 0, 1});
321+
gil::detail::convolve_1d<pixel_t>(gil::const_view(img_out), kernel_shift_by_one,
322+
gil::view(img_out), gil::boundary_option::extend_padded);
317323

318324
// First row and first column of "img_out" and "img_expected_col" are intentionally made
319325
// similar.
@@ -333,7 +339,7 @@ struct test_image_5x5_kernel_1x9_boundary_extend_padded
333339
static void run()
334340
{
335341
boost::mp11::mp_for_each<fixture::image_types>(
336-
test_image_5x5_kernel_1x9_boundary_extend_padded{});
342+
test_image_5x5_kernel_1x3_boundary_extend_padded{});
337343
}
338344
};
339345

@@ -346,8 +352,8 @@ int main()
346352

347353
test_image_5x5_kernel_1x9_boundary_extend_zero::run();
348354
test_image_5x5_kernel_1x9_boundary_extend_constant::run();
349-
test_image_5x5_kernel_1x9_boundary_output_zero::run();
350-
test_image_5x5_kernel_1x9_boundary_output_ignore::run();
351-
test_image_5x5_kernel_1x9_boundary_extend_padded::run();
355+
test_image_5x5_kernel_1x3_boundary_output_zero::run();
356+
test_image_5x5_kernel_1x3_boundary_output_ignore::run();
357+
test_image_5x5_kernel_1x3_boundary_extend_padded::run();
352358
return ::boost::report_errors();
353359
}

test/extension/numeric/convolve_cols.cpp

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -76,18 +76,20 @@ struct test_image_5x5_kernel_1x9_boundary_extend_zero
7676
auto img = fixture::generate_image<image_t>(5, 5, fixture::random_value<channel_t>{});
7777
auto img_view = gil::view(img);
7878
image_t img_out(img), img_expected(img_view.width(), img_view.height());
79+
unsigned int const kernel_shift_offset = 2;
7980

8081
for (std::ptrdiff_t x = 0; x < img_view.width(); ++x)
8182
{
8283
auto img_it = img_view.col_begin(x);
8384
auto img_expected_it = gil::view(img_expected).col_begin(x);
84-
for (std::ptrdiff_t y = 2; y < img_view.height(); ++y)
85+
for (std::ptrdiff_t y = kernel_shift_offset; y < img_view.height(); ++y)
8586
img_expected_it[y] = img_it[y - 2];
8687
}
8788

88-
auto const kernel = fixture::create_kernel<channel_t>({0, 0, 0, 0, 0, 0, 1, 0, 0});
89-
gil::convolve_cols<pixel_t>(gil::const_view(img_out), kernel, gil::view(img_out),
90-
gil::boundary_option::extend_zero);
89+
auto const kernel_shift_by_two = fixture::create_kernel<channel_t>(
90+
{0, 0, 0, 0, 0, 0, 1, 0, 0});
91+
gil::convolve_cols<pixel_t>(gil::const_view(img_out), kernel_shift_by_two,
92+
gil::view(img_out), gil::boundary_option::extend_zero);
9193
BOOST_TEST(gil::equal_pixels(gil::const_view(img_out), gil::const_view(img_expected)));
9294
}
9395
static void run()
@@ -108,18 +110,20 @@ struct test_image_5x5_kernel_1x9_boundary_extend_constant
108110
auto img = fixture::generate_image<image_t>(5, 5, fixture::random_value<channel_t>{});
109111
auto img_view = gil::view(img);
110112
image_t img_out(img), img_expected(img);
113+
unsigned int const kernel_shift_offset = 2;
111114

112115
for (std::ptrdiff_t x = 0; x < img_view.width(); ++x)
113116
{
114117
auto img_it = img_view.col_begin(x);
115118
auto img_expected_it = gil::view(img_expected).col_begin(x);
116-
for (std::ptrdiff_t y = 2; y < img_view.height(); ++y)
119+
for (std::ptrdiff_t y = kernel_shift_offset; y < img_view.height(); ++y)
117120
img_expected_it[y] = img_it[y - 2];
118121
img_expected_it[1] = img_it[0];
119122
}
120-
auto const kernel = fixture::create_kernel<channel_t>({0, 0, 0, 0, 0, 0, 1, 0, 0});
121-
gil::convolve_cols<pixel_t>(gil::const_view(img_out), kernel, gil::view(img_out),
122-
gil::boundary_option::extend_constant);
123+
auto const kernel_shift_by_two = fixture::create_kernel<channel_t>(
124+
{0, 0, 0, 0, 0, 0, 1, 0, 0});
125+
gil::convolve_cols<pixel_t>(gil::const_view(img_out), kernel_shift_by_two,
126+
gil::view(img_out), gil::boundary_option::extend_constant);
123127

124128
BOOST_TEST(gil::equal_pixels(gil::const_view(img_out), gil::const_view(img_expected)));
125129
}
@@ -130,7 +134,7 @@ struct test_image_5x5_kernel_1x9_boundary_extend_constant
130134
}
131135
};
132136

133-
struct test_image_5x5_kernel_1x9_boundary_output_zero
137+
struct test_image_5x5_kernel_1x3_boundary_output_zero
134138
{
135139
template <typename Image>
136140
void operator()(Image const&)
@@ -141,29 +145,30 @@ struct test_image_5x5_kernel_1x9_boundary_output_zero
141145
auto img = fixture::generate_image<image_t>(5, 5, fixture::random_value<channel_t>{});
142146
auto img_view = gil::view(img);
143147
image_t img_out(img), img_expected(img_view.width(), img_view.height());
148+
unsigned int const kernel_shift_offset = 1;
144149

145150
for (std::ptrdiff_t x = 0; x < img_view.width(); ++x)
146151
{
147152
auto img_it = img_view.col_begin(x);
148153
auto img_expected_it = gil::view(img_expected).col_begin(x);
149-
for (std::ptrdiff_t y = 1; y < img_view.height() - 1; ++y)
154+
for (std::ptrdiff_t y = kernel_shift_offset; y < img_view.height() - 1; ++y)
150155
img_expected_it[y] = img_it[y - 1];
151156
}
152157

153-
auto const kernel = fixture::create_kernel<channel_t>({0, 0, 1});
154-
gil::convolve_cols<pixel_t>(gil::const_view(img_out), kernel, gil::view(img_out),
155-
gil::boundary_option::output_zero);
158+
auto const kernel_shift_by_one = fixture::create_kernel<channel_t>({0, 0, 1});
159+
gil::convolve_cols<pixel_t>(gil::const_view(img_out), kernel_shift_by_one,
160+
gil::view(img_out), gil::boundary_option::output_zero);
156161

157162
BOOST_TEST(gil::equal_pixels(gil::const_view(img_out), gil::const_view(img_expected)));
158163
}
159164
static void run()
160165
{
161166
boost::mp11::mp_for_each<fixture::image_types>(
162-
test_image_5x5_kernel_1x9_boundary_output_zero{});
167+
test_image_5x5_kernel_1x3_boundary_output_zero{});
163168
}
164169
};
165170

166-
struct test_image_5x5_kernel_1x9_boundary_output_ignore
171+
struct test_image_5x5_kernel_1x3_boundary_output_ignore
167172
{
168173
template <typename Image>
169174
void operator()(Image const&)
@@ -174,29 +179,30 @@ struct test_image_5x5_kernel_1x9_boundary_output_ignore
174179
auto img = fixture::generate_image<image_t>(5, 5, fixture::random_value<channel_t>{});
175180
auto img_view = gil::view(img);
176181
image_t img_out(img), img_expected(img);
182+
unsigned int const kernel_shift_offset = 1;
177183

178184
for (std::ptrdiff_t x = 0; x < img_view.width(); ++x)
179185
{
180186
auto img_it = img_view.col_begin(x);
181187
auto img_expected_it = gil::view(img_expected).col_begin(x);
182-
for (std::ptrdiff_t y = 1; y < img_view.height() - 1; ++y)
188+
for (std::ptrdiff_t y = kernel_shift_offset; y < img_view.height() - 1; ++y)
183189
img_expected_it[y] = img_it[y - 1];
184190
}
185191

186-
auto const kernel = fixture::create_kernel<channel_t>({0, 0, 1});
187-
gil::convolve_cols<pixel_t>(gil::const_view(img_out), kernel, gil::view(img_out),
188-
gil::boundary_option::output_ignore);
192+
auto const kernel_shift_by_one = fixture::create_kernel<channel_t>({0, 0, 1});
193+
gil::convolve_cols<pixel_t>(gil::const_view(img_out), kernel_shift_by_one,
194+
gil::view(img_out), gil::boundary_option::output_ignore);
189195

190196
BOOST_TEST(gil::equal_pixels(gil::const_view(img_out), gil::const_view(img_expected)));
191197
}
192198
static void run()
193199
{
194200
boost::mp11::mp_for_each<fixture::image_types>(
195-
test_image_5x5_kernel_1x9_boundary_output_ignore{});
201+
test_image_5x5_kernel_1x3_boundary_output_ignore{});
196202
}
197203
};
198204

199-
struct test_image_5x5_kernel_1x9_boundary_extend_padded
205+
struct test_image_5x5_kernel_1x3_boundary_extend_padded
200206
{
201207
template <typename Image>
202208
void operator()(Image const&)
@@ -207,18 +213,19 @@ struct test_image_5x5_kernel_1x9_boundary_extend_padded
207213
auto img = fixture::generate_image<image_t>(5, 5, fixture::random_value<channel_t>{});
208214
auto img_view = gil::view(img);
209215
image_t img_out(img), img_expected(img);
216+
unsigned int const kernel_shift_offset = 1;
210217

211218
for (std::ptrdiff_t x = 0; x < img_view.width(); ++x)
212219
{
213220
auto img_it = img_view.col_begin(x);
214221
auto img_expected_it = gil::view(img_expected).col_begin(x);
215-
for (std::ptrdiff_t y = 1; y < img_view.width(); ++y)
222+
for (std::ptrdiff_t y = kernel_shift_offset; y < img_view.width(); ++y)
216223
img_expected_it[y] = img_it[y - 1];
217224
}
218225

219-
auto const kernel = fixture::create_kernel<channel_t>({0, 0, 1});
220-
gil::convolve_cols<pixel_t>(gil::const_view(img_out), kernel, gil::view(img_out),
221-
gil::boundary_option::extend_padded);
226+
auto const kernel_shift_by_one = fixture::create_kernel<channel_t>({0, 0, 1});
227+
gil::convolve_cols<pixel_t>(gil::const_view(img_out), kernel_shift_by_one,
228+
gil::view(img_out), gil::boundary_option::extend_padded);
222229

223230
// First column of "img_out" and "img_expected" is intentionally made similar.
224231
auto img_out_it = gil::view(img_out).row_begin(0);
@@ -231,7 +238,7 @@ struct test_image_5x5_kernel_1x9_boundary_extend_padded
231238
static void run()
232239
{
233240
boost::mp11::mp_for_each<fixture::image_types>(
234-
test_image_5x5_kernel_1x9_boundary_extend_padded{});
241+
test_image_5x5_kernel_1x3_boundary_extend_padded{});
235242
}
236243
};
237244

@@ -241,9 +248,9 @@ int main()
241248
test_image_1x1_kernel_3x3_identity::run();
242249
test_image_5x5_kernel_1x9_boundary_extend_zero::run();
243250
test_image_5x5_kernel_1x9_boundary_extend_constant::run();
244-
test_image_5x5_kernel_1x9_boundary_output_zero::run();
245-
test_image_5x5_kernel_1x9_boundary_output_ignore::run();
246-
test_image_5x5_kernel_1x9_boundary_extend_padded::run();
251+
test_image_5x5_kernel_1x3_boundary_output_zero::run();
252+
test_image_5x5_kernel_1x3_boundary_output_ignore::run();
253+
test_image_5x5_kernel_1x3_boundary_extend_padded::run();
247254

248255
return ::boost::report_errors();
249256
}

0 commit comments

Comments
 (0)