Skip to content

Commit cb24060

Browse files
committed
Shorten Agg template usage with class template argument deduction.
Many parts of the Agg & path processing pipeline work by constructing nested templated objects that represent steps of the processing pipeline, e.g. (simplified example) ``` agg::conv_transform<mpl::PathIterator> // The processing step. tpath // The name of the result. (path, trans); // The arguments passed to the processing step. PathNanRemover<agg::conv_transform<mpl::PathIterator>> nan_removed (tpath, true, path.has_codes()); ``` The current implementation makes the code shorter by introducing alias typenames for the types at each intermediate step. As of C++17, this can be made simpler and shorter because class template argument deduction ("CTAD") allows not specifying the template arguments (in angle brackets) anymore, i.e. one can write ``` agg::conv_transform tpath(path, trans); PathNanRemover nan_removed(tpath, true, path.has_codes()); ``` and the compiler will auto-fill in the required types. Furthermore, because these steps can be seen as a pipeline (even though they are implemented as the construction of nested objects), it may feel more natural to write them as repeated "function" (constructor) application, i.e. ``` auto tpath = agg::conv_transform{path, trans}; auto nan_removed = PathNanRemover{tpath, true, path.has_codes()}; ``` Perform this transformation whereever applicable.
1 parent 9f7b3dd commit cb24060

File tree

3 files changed

+138
-245
lines changed

3 files changed

+138
-245
lines changed

src/_backend_agg.cpp

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -122,15 +122,6 @@ bool RendererAgg::render_clippath(mpl::PathIterator &clippath,
122122
const agg::trans_affine &clippath_trans,
123123
e_snap_mode snap_mode)
124124
{
125-
typedef agg::conv_transform<mpl::PathIterator> transformed_path_t;
126-
typedef PathNanRemover<transformed_path_t> nan_removed_t;
127-
/* Unlike normal Paths, the clip path cannot be clipped to the Figure bbox,
128-
* because it needs to remain a complete closed path, so there is no
129-
* PathClipper<nan_removed_t> step. */
130-
typedef PathSnapper<nan_removed_t> snapped_t;
131-
typedef PathSimplifier<snapped_t> simplify_t;
132-
typedef agg::conv_curve<simplify_t> curve_t;
133-
134125
bool has_clippath = (clippath.total_vertices() != 0);
135126

136127
if (has_clippath &&
@@ -141,13 +132,19 @@ bool RendererAgg::render_clippath(mpl::PathIterator &clippath,
141132
trans *= agg::trans_affine_translation(0.0, (double)height);
142133

143134
rendererBaseAlphaMask.clear(agg::gray8(0, 0));
144-
transformed_path_t transformed_clippath(clippath, trans);
145-
nan_removed_t nan_removed_clippath(transformed_clippath, true, clippath.has_codes());
146-
snapped_t snapped_clippath(nan_removed_clippath, snap_mode, clippath.total_vertices(), 0.0);
147-
simplify_t simplified_clippath(snapped_clippath,
148-
clippath.should_simplify() && !clippath.has_codes(),
149-
clippath.simplify_threshold());
150-
curve_t curved_clippath(simplified_clippath);
135+
auto transformed_clippath = agg::conv_transform{clippath, trans};
136+
auto nan_removed_clippath = PathNanRemover{
137+
transformed_clippath, true, clippath.has_codes()};
138+
// Unlike normal Paths, the clip path cannot be clipped to the Figure
139+
// bbox, because it needs to remain a complete closed path, so there is
140+
// no PathClipper step after nan-removal.
141+
auto snapped_clippath = PathSnapper{
142+
nan_removed_clippath, snap_mode, clippath.total_vertices(), 0.0};
143+
auto simplified_clippath = PathSimplifier{
144+
snapped_clippath,
145+
clippath.should_simplify() && !clippath.has_codes(),
146+
clippath.simplify_threshold()};
147+
auto curved_clippath = agg::conv_curve{simplified_clippath};
151148
theRasterizer.add_path(curved_clippath);
152149
rendererAlphaMask.color(agg::gray8(255, 255));
153150
agg::render_scanlines(theRasterizer, scanlineAlphaMask, rendererAlphaMask);

0 commit comments

Comments
 (0)