33#ifndef  MPL_PATH_H
44#define  MPL_PATH_H 
55
6- #include  < limits> 
7- #include  < math.h> 
8- #include  < vector> 
9- #include  < cmath> 
106#include  < algorithm> 
7+ #include  < array> 
8+ #include  < cmath> 
9+ #include  < limits> 
1110#include  < string> 
11+ #include  < vector> 
1212
1313#include  " agg_conv_contour.h" 
1414#include  " agg_conv_curve.h" 
@@ -1051,15 +1051,14 @@ void cleanup_path(PathIterator &path,
10511051void  quad2cubic (double  x0, double  y0,
10521052                double  x1, double  y1,
10531053                double  x2, double  y2,
1054-                 double  * outx, double  * outy)
1054+                 std::array< double ,  3 > & outx, std::array< double ,  3 > & outy)
10551055{
1056- 
1057-     outx[0 ] = x0 + 2 ./3 . * (x1 - x0);
1058-     outy[0 ] = y0 + 2 ./3 . * (y1 - y0);
1059-     outx[1 ] = outx[0 ] + 1 ./3 . * (x2 - x0);
1060-     outy[1 ] = outy[0 ] + 1 ./3 . * (y2 - y0);
1061-     outx[2 ] = x2;
1062-     outy[2 ] = y2;
1056+     std::get<0 >(outx) = x0 + 2 ./3 . * (x1 - x0);
1057+     std::get<0 >(outy) = y0 + 2 ./3 . * (y1 - y0);
1058+     std::get<1 >(outx) = std::get<0 >(outx) + 1 ./3 . * (x2 - x0);
1059+     std::get<1 >(outy) = std::get<0 >(outy) + 1 ./3 . * (y2 - y0);
1060+     std::get<2 >(outx) = x2;
1061+     std::get<2 >(outy) = y2;
10631062}
10641063
10651064
@@ -1104,27 +1103,27 @@ void __add_number(double val, char format_code, int precision,
11041103template  <class  PathIterator >
11051104bool  __convert_to_string (PathIterator &path,
11061105                         int  precision,
1107-                          char  ** codes,
1106+                          const  std::array<std::string,  5 > & codes,
11081107                         bool  postfix,
11091108                         std::string& buffer)
11101109{
11111110    const  char  format_code = ' f'  ;
11121111
1113-     double  x[ 3 ] ;
1114-     double  y[ 3 ] ;
1112+     std::array< double ,  3 > x ;
1113+     std::array< double ,  3 > y ;
11151114    double  last_x = 0.0 ;
11161115    double  last_y = 0.0 ;
11171116
11181117    unsigned  code;
11191118
1120-     while  ((code = path.vertex (&x[ 0 ] , &y[ 0 ] )) != agg::path_cmd_stop) {
1119+     while  ((code = path.vertex (&std::get< 0 >(x) , &std::get< 0 >(y) )) != agg::path_cmd_stop) {
11211120        if  (code == CLOSEPOLY) {
1122-             buffer += codes[ 4 ] ;
1121+             buffer += std::get< 4 >(codes) ;
11231122        } else  if  (code < 5 ) {
11241123            size_t  size = NUM_VERTICES[code];
11251124
11261125            for  (size_t  i = 1 ; i < size; ++i) {
1127-                 unsigned  subcode = path.vertex (&x[i] , &y[i] );
1126+                 unsigned  subcode = path.vertex (&x. at (i) , &y. at (i) );
11281127                if  (subcode != code) {
11291128                    return  false ;
11301129                }
@@ -1133,29 +1132,29 @@ bool __convert_to_string(PathIterator &path,
11331132            /*  For formats that don't support quad curves, convert to
11341133               cubic curves */  
11351134            if  (code == CURVE3 && codes[code - 1 ][0 ] == ' \0 '  ) {
1136-                 quad2cubic (last_x, last_y, x[ 0 ] , y[ 0 ] , x[ 1 ] , y[ 1 ] , x, y);
1135+                 quad2cubic (last_x, last_y, x. at ( 0 ) , y. at ( 0 ) , x. at ( 1 ) , y. at ( 1 ) , x, y);
11371136                code++;
11381137                size = 3 ;
11391138            }
11401139
11411140            if  (!postfix) {
1142-                 buffer += codes[ code - 1 ] ;
1141+                 buffer += codes. at ( code - 1 ) ;
11431142                buffer += '  '  ;
11441143            }
11451144
11461145            for  (size_t  i = 0 ; i < size; ++i) {
1147-                 __add_number (x[i] , format_code, precision, buffer);
1146+                 __add_number (x. at (i) , format_code, precision, buffer);
11481147                buffer += '  '  ;
1149-                 __add_number (y[i] , format_code, precision, buffer);
1148+                 __add_number (y. at (i) , format_code, precision, buffer);
11501149                buffer += '  '  ;
11511150            }
11521151
11531152            if  (postfix) {
1154-                 buffer += codes[ code - 1 ] ;
1153+                 buffer += codes. at ( code - 1 ) ;
11551154            }
11561155
1157-             last_x = x[ size - 1 ] ;
1158-             last_y = y[ size - 1 ] ;
1156+             last_x = x. at ( size - 1 ) ;
1157+             last_y = y. at ( size - 1 ) ;
11591158        } else  {
11601159            //  Unknown code value
11611160            return  false ;
@@ -1174,7 +1173,7 @@ bool convert_to_string(PathIterator &path,
11741173                       bool  simplify,
11751174                       SketchParams sketch_params,
11761175                       int  precision,
1177-                        char  ** codes,
1176+                        const  std::array<std::string,  5 > & codes,
11781177                       bool  postfix,
11791178                       std::string& buffer)
11801179{
@@ -1211,7 +1210,6 @@ bool convert_to_string(PathIterator &path,
12111210        sketch_t  sketch (curve, sketch_params.scale , sketch_params.length , sketch_params.randomness );
12121211        return  __convert_to_string (sketch, precision, codes, postfix, buffer);
12131212    }
1214- 
12151213}
12161214
12171215template <class  T >
0 commit comments