正如你所看见的,很多代码是冗余的。为了支持仿射,透视,双线性转换,
相同的代码出现三次。为了绘制没有填充和填充的图形相同的代码出现两次。
结果导致一个相同的对象经过转换,需要经过6份相同的代码。我应该如何
消除这种代码的冗余?
//----------------------------
switch(trans_mode)
{
case 0: // Affine
if (fill)
{
agg::conv_transform<agg::rounded_rect, agg::trans_affine> trect(rect, mtx);
ras.add_path(trect);
break;
}
else
{
agg::conv_stroke<agg::rounded_rect> stroke(rect);
agg::conv_transform<agg::conv_stroke<agg::rounded_rect> ,
agg::trans_affine> tstroke(stroke,mtx);
ras.add_path(tstroke);
break;
}
break;
case 1: // Perspective
if(fill)
{
agg::trans_perspective persp (persp_param[0],persp_param[1],persp_param[2],
persp_param[3],&persp_param[4]);
agg::conv_transform<agg::rounded_rect,
agg::trans_perspective> trect(rect,persp);
ras.add_path(trect);
break;
}
else
{
agg::conv_stroke<agg::rounded_rect> stroke(rect);
agg::trans_perspective persp (persp_param[0],persp_param[1],persp_param[2],
persp_param[3],&persp_param[4]);
agg::conv_transform<agg::conv_stroke<agg::rounded_rect> ,
agg::trans_perspective> tstroke(stroke,persp);
ras.add_path(tstroke);
break;
}
break;
case 2: // bilinear
if(fill)
{
agg::trans_bilinear persp (persp_param[0],persp_param[1],persp_param[2],
persp_param[3],&persp_param[4]);
agg::conv_transform<agg::rounded_rect, agg::trans_bilinear> trect(rect,persp);
ras.add_path(trect);
break;
}
else
{
agg::conv_stroke<agg::rounded_rect> stroke(rect);
stroke.width(w);
agg::trans_bilinear persp (persp_param[0],persp_param[1],persp_param[2],
persp_param[3],&persp_param[4]);
agg::conv_transform<agg::conv_stroke<agg::rounded_rect> ,
agg::trans_bilinear> tstroke(stroke,persp);
ras.add_path(tstroke);
break;
}
break;
}