1111#include < cmath>
1212#include < algorithm>
1313#include < functional>
14+ #include < optional>
1415#include < vector>
1516
1617#include " agg_alpha_mask_u8.h"
@@ -123,9 +124,6 @@ class RendererAgg
123124 typedef agg::renderer_base<agg::pixfmt_gray8> renderer_base_alpha_mask_type;
124125 typedef agg::renderer_scanline_aa_solid<renderer_base_alpha_mask_type> renderer_alpha_mask_type;
125126
126- /* TODO: Remove facepair_t */
127- typedef std::pair<bool , agg::rgba> facepair_t ;
128-
129127 RendererAgg (unsigned int width, unsigned int height, double dpi);
130128
131129 virtual ~RendererAgg ();
@@ -248,7 +246,7 @@ class RendererAgg
248246 bool render_clippath (mpl::PathIterator &clippath, const agg::trans_affine &clippath_trans, e_snap_mode snap_mode);
249247
250248 template <class PathIteratorType >
251- void _draw_path (PathIteratorType &path, bool has_clippath, const facepair_t &face, GCAgg &gc);
249+ void _draw_path (PathIteratorType &path, bool has_clippath, const std::optional<agg::rgba> &face, GCAgg &gc);
252250
253251 template <class PathIterator ,
254252 class PathGenerator ,
@@ -295,7 +293,7 @@ class RendererAgg
295293
296294template <class path_t >
297295inline void
298- RendererAgg::_draw_path (path_t &path, bool has_clippath, const facepair_t &face, GCAgg &gc)
296+ RendererAgg::_draw_path (path_t &path, bool has_clippath, const std::optional<agg::rgba> &face, GCAgg &gc)
299297{
300298 typedef agg::conv_stroke<path_t > stroke_t ;
301299 typedef agg::conv_dash<path_t > dash_t ;
@@ -306,29 +304,29 @@ RendererAgg::_draw_path(path_t &path, bool has_clippath, const facepair_t &face,
306304 typedef agg::renderer_scanline_bin_solid<amask_ren_type> amask_bin_renderer_type;
307305
308306 // Render face
309- if (face. first ) {
307+ if (face) {
310308 theRasterizer.add_path (path);
311309
312310 if (gc.isaa ) {
313311 if (has_clippath) {
314312 pixfmt_amask_type pfa (pixFmt, alphaMask);
315313 amask_ren_type r (pfa);
316314 amask_aa_renderer_type ren (r);
317- ren.color (face. second );
315+ ren.color (* face);
318316 agg::render_scanlines (theRasterizer, scanlineAlphaMask, ren);
319317 } else {
320- rendererAA.color (face. second );
318+ rendererAA.color (* face);
321319 agg::render_scanlines (theRasterizer, slineP8, rendererAA);
322320 }
323321 } else {
324322 if (has_clippath) {
325323 pixfmt_amask_type pfa (pixFmt, alphaMask);
326324 amask_ren_type r (pfa);
327325 amask_bin_renderer_type ren (r);
328- ren.color (face. second );
326+ ren.color (* face);
329327 agg::render_scanlines (theRasterizer, scanlineAlphaMask, ren);
330328 } else {
331- rendererBin.color (face. second );
329+ rendererBin.color (* face);
332330 agg::render_scanlines (theRasterizer, slineP8, rendererBin);
333331 }
334332 }
@@ -458,7 +456,10 @@ RendererAgg::draw_path(GCAgg &gc, PathIterator &path, agg::trans_affine &trans,
458456 typedef agg::conv_curve<simplify_t > curve_t ;
459457 typedef Sketch<curve_t > sketch_t ;
460458
461- facepair_t face (color.a != 0.0 , color);
459+ std::optional<agg::rgba> face;
460+ if (color.a != 0.0 ) {
461+ face = color;
462+ }
462463
463464 theRasterizer.reset_clipping ();
464465 rendererBase.reset_clipping (true );
@@ -467,7 +468,7 @@ RendererAgg::draw_path(GCAgg &gc, PathIterator &path, agg::trans_affine &trans,
467468
468469 trans *= agg::trans_affine_scaling (1.0 , -1.0 );
469470 trans *= agg::trans_affine_translation (0.0 , (double )height);
470- bool clip = !face. first && !gc.has_hatchpath ();
471+ bool clip = !face && !gc.has_hatchpath ();
471472 bool simplify = path.should_simplify () && clip;
472473 double snapping_linewidth = points_to_pixels (gc.linewidth );
473474 if (gc.color .a == 0.0 ) {
@@ -529,7 +530,10 @@ inline void RendererAgg::draw_markers(GCAgg &gc,
529530 curve_t path_curve (path_snapped);
530531 path_curve.rewind (0 );
531532
532- facepair_t face (color.a != 0.0 , color);
533+ std::optional<agg::rgba> face;
534+ if (color.a != 0.0 ) {
535+ face = color;
536+ }
533537
534538 // maxim's suggestions for cached scanlines
535539 agg::scanline_storage_aa8 scanlines;
@@ -541,7 +545,7 @@ inline void RendererAgg::draw_markers(GCAgg &gc,
541545 try
542546 {
543547 std::vector<agg::int8u> fillBuffer;
544- if (face. first ) {
548+ if (face) {
545549 theRasterizer.add_path (marker_path_curve);
546550 agg::render_scanlines (theRasterizer, slineP8, scanlines);
547551 fillBuffer.resize (scanlines.byte_size ());
@@ -605,8 +609,8 @@ inline void RendererAgg::draw_markers(GCAgg &gc,
605609 amask_ren_type r (pfa);
606610 amask_aa_renderer_type ren (r);
607611
608- if (face. first ) {
609- ren.color (face. second );
612+ if (face) {
613+ ren.color (* face);
610614 sa.init (fillBuffer.data (), fillBuffer.size (), x, y);
611615 agg::render_scanlines (sa, sl, ren);
612616 }
@@ -633,8 +637,8 @@ inline void RendererAgg::draw_markers(GCAgg &gc,
633637 continue ;
634638 }
635639
636- if (face. first ) {
637- rendererAA.color (face. second );
640+ if (face) {
641+ rendererAA.color (* face);
638642 sa.init (fillBuffer.data (), fillBuffer.size (), x, y);
639643 agg::render_scanlines (sa, sl, rendererAA);
640644 }
@@ -936,10 +940,9 @@ inline void RendererAgg::_draw_path_collection_generic(GCAgg &gc,
936940
937941 // Set some defaults, assuming no face or edge
938942 gc.linewidth = 0.0 ;
939- facepair_t face;
940- face.first = Nfacecolors != 0 ;
943+ std::optional<agg::rgba> face;
941944 agg::trans_affine trans;
942- bool do_clip = !face. first && !gc.has_hatchpath ();
945+ bool do_clip = Nfacecolors == 0 && !gc.has_hatchpath ();
943946
944947 for (int i = 0 ; i < (int )N; ++i) {
945948 typename PathGenerator::path_iterator path = path_generator (i);
@@ -970,7 +973,7 @@ inline void RendererAgg::_draw_path_collection_generic(GCAgg &gc,
970973
971974 if (Nfacecolors) {
972975 int ic = i % Nfacecolors;
973- face.second = agg::rgba (facecolors (ic, 0 ), facecolors (ic, 1 ), facecolors (ic, 2 ), facecolors (ic, 3 ));
976+ face.emplace (facecolors (ic, 0 ), facecolors (ic, 1 ), facecolors (ic, 2 ), facecolors (ic, 3 ));
974977 }
975978
976979 if (Nedgecolors) {
0 commit comments