📄 common.cc
字号:
}// Used by dashed_rounded_box.void common_output::dash_arc(const position ¢, double rad, double start_angle, double end_angle, const line_type <, double dash_width, double gap_width, double *offsetp){ double length = (end_angle - start_angle)*rad; double pos = 0.0; for (;;) { if (*offsetp >= dash_width) { double rem = dash_width + gap_width - *offsetp; if (pos + rem > length) { *offsetp += length - pos; break; } else { pos += rem; *offsetp = 0.0; } } else { double rem = dash_width - *offsetp; if (pos + rem > length) { solid_arc(cent, rad, start_angle + pos/rad, end_angle, lt); *offsetp += length - pos; break; } else { solid_arc(cent, rad, start_angle + pos/rad, start_angle + (pos + rem)/rad, lt); pos += rem; *offsetp = dash_width; } } }}// Used by dashed_rounded_box.void common_output::dash_line(const position &start, const position &end, const line_type <, double dash_width, double gap_width, double *offsetp){ distance dist = end - start; double length = hypot(dist); if (length == 0.0) return; double pos = 0.0; for (;;) { if (*offsetp >= dash_width) { double rem = dash_width + gap_width - *offsetp; if (pos + rem > length) { *offsetp += length - pos; break; } else { pos += rem; *offsetp = 0.0; } } else { double rem = dash_width - *offsetp; if (pos + rem > length) { line(start + dist*(pos/length), &end, 1, lt); *offsetp += length - pos; break; } else { position p(start + dist*((pos + rem)/length)); line(start + dist*(pos/length), &p, 1, lt); pos += rem; *offsetp = dash_width; } } }}void common_output::dotted_rounded_box(const position ¢, const distance &dim, double rad, const line_type <){ line_type slt = lt; slt.type = line_type::solid; double hor_length = dim.x + (M_PI/2.0 - 2.0)*rad; int n_hor_dots = int(hor_length/lt.dash_width + .5); double hor_gap_width = (n_hor_dots != 0 ? hor_length/n_hor_dots : lt.dash_width); double vert_length = dim.y + (M_PI/2.0 - 2.0)*rad; int n_vert_dots = int(vert_length/lt.dash_width + .5); double vert_gap_width = (n_vert_dots != 0 ? vert_length/n_vert_dots : lt.dash_width); double epsilon = lt.dash_width/(rad*100.0); double offset = 0.0; dot_arc(cent + position(dim.x/2.0 - rad, -dim.y/2.0 + rad), rad, -M_PI/4.0, 0, slt, vert_gap_width, &offset); dot_line(cent + position(dim.x/2.0, -dim.y/2.0 + rad), cent + position(dim.x/2.0, dim.y/2.0 - rad), slt, vert_gap_width, &offset); dot_arc(cent + position(dim.x/2.0 - rad, dim.y/2.0 - rad), rad, 0, M_PI/4.0 - epsilon, slt, vert_gap_width, &offset); offset = 0.0; dot_arc(cent + position(dim.x/2.0 - rad, dim.y/2.0 - rad), rad, M_PI/4.0, M_PI/2, slt, hor_gap_width, &offset); dot_line(cent + position(dim.x/2.0 - rad, dim.y/2.0), cent + position(-dim.x/2.0 + rad, dim.y/2.0), slt, hor_gap_width, &offset); dot_arc(cent + position(-dim.x/2.0 + rad, dim.y/2.0 - rad), rad, M_PI/2, 3*M_PI/4.0 - epsilon, slt, hor_gap_width, &offset); offset = 0.0; dot_arc(cent + position(-dim.x/2.0 + rad, dim.y/2.0 - rad), rad, 3.0*M_PI/4.0, M_PI, slt, vert_gap_width, &offset); dot_line(cent + position(-dim.x/2.0, dim.y/2.0 - rad), cent + position(-dim.x/2.0, -dim.y/2.0 + rad), slt, vert_gap_width, &offset); dot_arc(cent + position(-dim.x/2.0 + rad, -dim.y/2.0 + rad), rad, M_PI, 5.0*M_PI/4.0 - epsilon, slt, vert_gap_width, &offset); offset = 0.0; dot_arc(cent + position(-dim.x/2.0 + rad, -dim.y/2.0 + rad), rad, 5*M_PI/4.0, 3*M_PI/2.0, slt, hor_gap_width, &offset); dot_line(cent + position(-dim.x/2.0 + rad, -dim.y/2.0), cent + position(dim.x/2.0 - rad, -dim.y/2.0), slt, hor_gap_width, &offset); dot_arc(cent + position(dim.x/2.0 - rad, -dim.y/2.0 + rad), rad, 3*M_PI/2, 7*M_PI/4 - epsilon, slt, hor_gap_width, &offset);}// Used by dotted_rounded_box.void common_output::dot_arc(const position ¢, double rad, double start_angle, double end_angle, const line_type <, double gap_width, double *offsetp){ double length = (end_angle - start_angle)*rad; double pos = 0.0; for (;;) { if (*offsetp == 0.0) { double ang = start_angle + pos/rad; dot(cent + position(cos(ang), sin(ang))*rad, lt); } double rem = gap_width - *offsetp; if (pos + rem > length) { *offsetp += length - pos; break; } else { pos += rem; *offsetp = 0.0; } }}// Used by dotted_rounded_box.void common_output::dot_line(const position &start, const position &end, const line_type <, double gap_width, double *offsetp){ distance dist = end - start; double length = hypot(dist); double pos = 0.0; for (;;) { if (*offsetp == 0.0) dot(start + dist*(pos/length), lt); double rem = gap_width - *offsetp; if (pos + rem > length) { *offsetp += length - pos; break; } else { pos += rem; *offsetp = 0.0; } }}void common_output::solid_rounded_box(const position ¢, const distance &dim, double rad, const line_type <){ position tem = cent - dim/2.0; arc(tem + position(0.0, rad), tem + position(rad, rad), tem + position(rad, 0.0), lt); tem = cent + position(-dim.x/2.0, dim.y/2.0); arc(tem + position(rad, 0.0), tem + position(rad, -rad), tem + position(0.0, -rad), lt); tem = cent + dim/2.0; arc(tem + position(0.0, -rad), tem + position(-rad, -rad), tem + position(-rad, 0.0), lt); tem = cent + position(dim.x/2.0, -dim.y/2.0); arc(tem + position(-rad, 0.0), tem + position(-rad, rad), tem + position(0.0, rad), lt); position end; end = cent + position(-dim.x/2.0, dim.y/2.0 - rad); line(cent - dim/2.0 + position(0.0, rad), &end, 1, lt); end = cent + position(dim.x/2.0 - rad, dim.y/2.0); line(cent + position(-dim.x/2.0 + rad, dim.y/2.0), &end, 1, lt); end = cent + position(dim.x/2.0, -dim.y/2.0 + rad); line(cent + position(dim.x/2.0, dim.y/2.0 - rad), &end, 1, lt); end = cent + position(-dim.x/2.0 + rad, -dim.y/2.0); line(cent + position(dim.x/2.0 - rad, -dim.y/2.0), &end, 1, lt);}void common_output::filled_rounded_box(const position ¢, const distance &dim, double rad, double fill){ line_type ilt; ilt.type = line_type::invisible; circle(cent + position(dim.x/2.0 - rad, dim.y/2.0 - rad), rad, ilt, fill); circle(cent + position(-dim.x/2.0 + rad, dim.y/2.0 - rad), rad, ilt, fill); circle(cent + position(-dim.x/2.0 + rad, -dim.y/2.0 + rad), rad, ilt, fill); circle(cent + position(dim.x/2.0 - rad, -dim.y/2.0 + rad), rad, ilt, fill); position vec[4]; vec[0] = cent + position(dim.x/2.0, dim.y/2.0 - rad); vec[1] = cent + position(-dim.x/2.0, dim.y/2.0 - rad); vec[2] = cent + position(-dim.x/2.0, -dim.y/2.0 + rad); vec[3] = cent + position(dim.x/2.0, -dim.y/2.0 + rad); polygon(vec, 4, ilt, fill); vec[0] = cent + position(dim.x/2.0 - rad, dim.y/2.0); vec[1] = cent + position(-dim.x/2.0 + rad, dim.y/2.0); vec[2] = cent + position(-dim.x/2.0 + rad, -dim.y/2.0); vec[3] = cent + position(dim.x/2.0 - rad, -dim.y/2.0); polygon(vec, 4, ilt, fill);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -