31 inline std::string
fmt_double(
double v,
int precision = 12) {
32 if (std::isnan(v))
return "0.0";
33 if (std::isinf(v))
return v > 0 ?
"1e30" :
"-1e30";
34 std::ostringstream ss;
35 ss << std::setprecision(precision) << std::scientific << v;
36 std::string s = ss.str();
38 auto epos = s.find(
'e');
39 if (epos != std::string::npos) {
40 if (epos + 1 < s.size() && s[epos + 1] !=
'-' && s[epos + 1] !=
'+') {
41 s.insert(epos + 1,
"+");
65 auto pos = s.find(
'e');
66 if (pos != std::string::npos) s[pos] =
'D';
89 using FmtFn = std::string (*)(double, int);
91 return fn(p.x(), 12) +
"," + fn(p.y(), 12) +
"," + fn(p.z(), 12);
105 inline std::string
pad72(
const std::string& s) {
106 std::string result = s;
107 if (result.size() > 72) result.resize(72);
108 result.resize(72,
' ');
131 std::string line =
pad72(data);
133 std::snprintf(seq_buf,
sizeof(seq_buf),
"%c%07d", section_char, seq);
134 line += std::string(seq_buf);
std::string pad72(const std::string &s)
将字符串填充到恰好 72 个字符
std::string fmt_point(const core::Point3D &p, bool use_d=false)
格式化三维点为逗号分隔字符串
std::string format_iges_line(const std::string &data, char section_char, int seq)
格式化 IGES 段落行
std::string fmt_iges_real(double v, int=12)
IGES 格式实数输出
std::string fmt_double(double v, int precision=12)
以 CAD 级别精度格式化双精度浮点数
foundation::Point3D Point3D
双精度三维点(重新导出)