@@ -16,10 +16,6 @@ namespace lib_interval_tree
16
16
{
17
17
namespace
18
18
{
19
- using int_tree_for_draw = interval_tree <interval<int , closed>>;
20
- using int_tree_iterator = int_tree_for_draw::iterator;
21
- using const_int_tree_iterator = int_tree_for_draw::const_iterator;
22
-
23
19
template <unsigned Size>
24
20
struct NumericalPointerEquivalent
25
21
{};
@@ -36,7 +32,8 @@ namespace lib_interval_tree
36
32
using type = unsigned long long ;
37
33
};
38
34
39
- std::string iterCaption (const_int_tree_iterator iter)
35
+ template <typename ... List>
36
+ std::string iterCaption (typename lib_interval_tree::interval_tree <List...>::const_iterator iter)
40
37
{
41
38
auto ival = iter->interval ();
42
39
std::stringstream sstr;
@@ -98,33 +95,36 @@ namespace lib_interval_tree
98
95
{
99
96
return getiterBounds ().getWidth () / 2 . + margin * 2 .;
100
97
}
101
- }
98
+ }
102
99
// #####################################################################################################################
100
+ template <typename ... List>
103
101
struct TreeGriditer
104
102
{
105
- const_int_tree_iterator iter;
103
+ typename lib_interval_tree::interval_tree <List...>::const_iterator iter;
106
104
std::pair <int , int > parentCoords;
107
105
};
106
+ template <typename ... List>
108
107
struct TreeGrid
109
108
{
110
109
// (row-major)
111
110
std::vector < // rows
112
111
std::vector < // columns
113
- boost::optional <TreeGriditer>
112
+ boost::optional <TreeGriditer<List...> >
114
113
>
115
114
> grid;
116
115
int xMax = 0 ;
117
116
int xMin = 0 ;
118
117
int yMax = 0 ;
119
- };
118
+ };
120
119
// #####################################################################################################################
121
- void drawIter (Cairo::DrawContext* ctx, const_int_tree_iterator iter, double x, double y, bool drawPointers)
120
+ template <typename ... List>
121
+ void drawIterator (Cairo::DrawContext* ctx, typename lib_interval_tree::interval_tree <List...>::const_iterator iter, double x, double y, bool drawPointers)
122
122
{
123
123
auto caption = Cairo::Text (
124
124
ctx,
125
125
0 ,
126
126
0 ,
127
- iterCaption (iter),
127
+ iterCaption<List...> (iter),
128
128
{" Arial" , 18 , CAIRO_FONT_WEIGHT_BOLD}
129
129
);
130
130
@@ -212,34 +212,31 @@ namespace lib_interval_tree
212
212
ptr.draw(Cairo::Colors::Yellow);
213
213
}
214
214
*/
215
- }
215
+ }
216
216
// ---------------------------------------------------------------------------------------------------------------------
217
- template <typename iterT>
218
- void drawiter (Cairo::DrawContext* ctx, interval_tree_iterator <iterT> const & iter, double x, double y, bool drawPointers)
219
- {
220
- drawiter (ctx, iter, x, y, drawPointers);
221
- }
222
- // ---------------------------------------------------------------------------------------------------------------------
223
- TreeGrid createGrid (int_tree_for_draw const & tree)
217
+ template <typename ... List>
218
+ TreeGrid<List...> createGrid (lib_interval_tree::interval_tree <List...> const & tree)
224
219
{
225
220
auto root = tree.root ();
226
221
if (root == std::end (tree))
227
222
return {};
228
223
229
- TreeGrid grid;
224
+ TreeGrid<List...> grid;
225
+
226
+ using tree_const_iterator = typename lib_interval_tree::interval_tree <List...>::const_iterator;
230
227
231
- struct _GridPoint
228
+ struct GridPoint
232
229
{
233
- const_int_tree_iterator iter;
234
- const_int_tree_iterator parent;
230
+ tree_const_iterator iter;
231
+ tree_const_iterator parent;
235
232
int x;
236
233
int y;
237
234
};
238
235
239
- std::vector <_GridPoint > gridPoints;
236
+ std::vector <GridPoint > gridPoints;
240
237
241
- std::function <int (const_int_tree_iterator iter)> subtreeSize;
242
- subtreeSize = [&](const_int_tree_iterator iter) {
238
+ std::function <int (tree_const_iterator iter)> subtreeSize;
239
+ subtreeSize = [&](tree_const_iterator iter) {
243
240
if (iter == std::end (tree))
244
241
return 0 ;
245
242
if (iter.left () == std::end (tree) && iter.right () == std::end (tree))
@@ -253,8 +250,8 @@ namespace lib_interval_tree
253
250
return 0 ;
254
251
};
255
252
256
- std::function <void (const_int_tree_iterator , int pX, int pY)> deduceCoordinates;
257
- deduceCoordinates = [&](const_int_tree_iterator iter, int pX, int pY)
253
+ std::function <void (tree_const_iterator , int pX, int pY)> deduceCoordinates;
254
+ deduceCoordinates = [&](tree_const_iterator iter, int pX, int pY)
258
255
{
259
256
int y = pY;
260
257
int x = pX;
@@ -311,19 +308,20 @@ namespace lib_interval_tree
311
308
}
312
309
}
313
310
314
- grid.grid [i.y ][i.x + -grid.xMin ] = {TreeGriditer{i.iter , parentCoords}};
311
+ grid.grid [i.y ][i.x + -grid.xMin ] = {TreeGriditer<List...> {i.iter , parentCoords}};
315
312
}
316
313
317
314
return grid;
318
- }
315
+ }
319
316
// ---------------------------------------------------------------------------------------------------------------------
320
- void drawGrid (Cairo::DrawContext* ctx, TreeGrid const & grid, bool drawPointers, bool drawEmpty)
317
+ template <typename ... List>
318
+ void drawGrid (Cairo::DrawContext* ctx, TreeGrid<List...> const & grid, bool drawPointers, bool drawEmpty)
321
319
{
322
320
auto iterRadius = getiterRadius ();
323
321
auto cellSize = iterRadius * 2 . + gridMargin;
324
322
325
- auto iterX = [&](int x_) {return leftPadding + iterRadius + x_ * cellSize + x_ * xPadding;};
326
- auto iterY = [&](int y_) {return topPadding + iterRadius + y_ * cellSize + y_ * yPadding;};
323
+ auto iterX = [&](auto x_) {return leftPadding + iterRadius + x_ * cellSize + x_ * xPadding;};
324
+ auto iterY = [&](auto y_) {return topPadding + iterRadius + y_ * cellSize + y_ * yPadding;};
327
325
328
326
// Draw Lines
329
327
int y = 0 ;
@@ -358,7 +356,7 @@ namespace lib_interval_tree
358
356
if (cell)
359
357
{
360
358
auto iter = cell.get ().iter ;
361
- drawIter (ctx, iter, iterX (x), iterY (y), drawPointers);
359
+ drawIterator<List...> (ctx, iter, iterX (x), iterY (y), drawPointers);
362
360
}
363
361
else if (drawEmpty)
364
362
{
@@ -375,9 +373,10 @@ namespace lib_interval_tree
375
373
}
376
374
++y;
377
375
}
378
- }
376
+ }
379
377
// ---------------------------------------------------------------------------------------------------------------------
380
- Cairo::Surface createSurface (TreeGrid const & grid)
378
+ template <typename ... List>
379
+ Cairo::Surface createSurface (TreeGrid<List...> const & grid)
381
380
{
382
381
auto iterRadius = getiterRadius ();
383
382
auto cellSize = iterRadius * 2 . + gridMargin;
@@ -388,16 +387,16 @@ namespace lib_interval_tree
388
387
static_cast <int > (leftPadding + (width) * cellSize + (width-1 ) * xPadding + rightPadding),
389
388
static_cast <int > (topPadding + (height) * cellSize + (height-1 ) * yPadding + bottomPadding)
390
389
};
391
- }
390
+ }
392
391
// ---------------------------------------------------------------------------------------------------------------------
393
392
template <typename ... List>
394
- void drawTree (std::string const & fileName, lib_interval_tree::interval_tree <List...> const * tree, bool drawPointers = false , bool drawEmpty = false )
393
+ void drawTree (std::string const & fileName, lib_interval_tree::interval_tree <List...> const & tree, bool drawPointers = false , bool drawEmpty = false )
395
394
{
396
- auto grid = createGrid (* tree);
395
+ auto grid = createGrid (tree);
397
396
auto surface = createSurface (grid);
398
397
Cairo::DrawContext ctx (&surface);
399
- drawGrid (&ctx, grid, drawPointers, drawEmpty);
398
+ drawGrid<List...> (&ctx, grid, drawPointers, drawEmpty);
400
399
surface.saveToFile (fileName);
401
- }
400
+ }
402
401
// ######################################################################################################
403
402
}
0 commit comments