- VDE-1362: make_cone faceted 分支某端半径 < vertex_merge 时走 apex 路径, 侧面 segs 三角 + 1 端盖 = segs+1 面,χ=2 闭合流形;旧实现顶环收缩为重合 顶点仍建四边形,得 F=66/V=65/E=128、χ=3 奇数,validate().valid=false 但 体积近似正确(隐性坏体)。阈值严格小于,r2>=1e-6 保持原 66 面圆台表示。 - VDE-1363: rebuild_single_shell 把 Face::id 写入 shell.faces(VDE-1282 约定 为数组下标),封盖重建后 is_valid()=false、bad shell face idx 越界;改为按 faces_ 下标填充,全仓其余写入点均为下标(verifier 235 P2-1)。 - 测试:4 例 faceted cone(顶锥/底锥/容差/中心偏移)+ 1 例封盖壳面索引, 圆锥快照补面数/valid/wt;注册 8,466 -> 8,471,全量 8,471 执行 / 8,433 passed / 0 failed / 38 SKIP / 475.70 s。 - kernel 审计套件随上游 API 修复:audit_formats 三处 fs::path 流构造改 .string()、audit_curves 球面 tess 改账面守恒断言;384 PASS / 0 FAIL。 - 文档:报告 236、报告 234 §11 勘误、报告 235(verifier 随版入库)、 CHANGELOG/docs 索引更新;release --check 14/14、--report-check PASS。
934 lines
46 KiB
C++
934 lines
46 KiB
C++
// C-7 audit probe: non-DWG data-exchange format families (STEP / IGES / XT /
|
||
// SAT / JT / 3MF / glTF / point cloud / PDF3D) - read/write/degradation/cancel
|
||
// honesty. One check = one [PASS]/[FAIL]/[UNKNOWN] line; isolated try/catch;
|
||
// temp files under %TEMP%, cleaned up afterwards.
|
||
//
|
||
// Build: see run_audit.ps1 (links <BuildDir>/src/libvde_*.a).
|
||
#include <atomic>
|
||
#include <chrono>
|
||
#include <cmath>
|
||
#include <cstdarg>
|
||
#include <cstdint>
|
||
#include <cstdio>
|
||
#include "vde/fs_compat.h"
|
||
#include <fstream>
|
||
#include <string>
|
||
#include <vector>
|
||
|
||
#include "vde/core/point.h"
|
||
#include "vde/brep/modeling.h"
|
||
#include "vde/brep/brep_validate.h"
|
||
#include "vde/brep/measure.h"
|
||
#include "vde/brep/step_import.h"
|
||
#include "vde/brep/step_export.h"
|
||
#include "vde/brep/iges_import.h"
|
||
#include "vde/brep/iges_export.h"
|
||
#include "vde/foundation/industrial_formats.h"
|
||
#include "vde/foundation/io_pdf3d.h"
|
||
#include "vde/foundation/format_detect.h"
|
||
#include "vde/foundation/prc_import.h"
|
||
#include "vde/foundation/io_3mf.h"
|
||
#include "vde/foundation/io_gltf.h"
|
||
#include "vde/mesh/point_cloud.h"
|
||
|
||
using namespace vde;
|
||
using namespace vde::core;
|
||
using vde::brep::BrepModel;
|
||
|
||
namespace {
|
||
|
||
int g_pass = 0, g_fail = 0, g_unk = 0, g_total = 0;
|
||
double g_ms = 0.0;
|
||
std::vector<std::string> g_fails;
|
||
std::string g_group = "all";
|
||
std::string g_base = ".";
|
||
|
||
std::string fmt(const char* f, ...) {
|
||
char buf[1024];
|
||
va_list ap;
|
||
va_start(ap, f);
|
||
vsnprintf(buf, sizeof(buf), f, ap);
|
||
va_end(ap);
|
||
return std::string(buf);
|
||
}
|
||
|
||
bool want(const char* g) { return g_group == "all" || g_group == g; }
|
||
using Ret = std::pair<bool, std::string>;
|
||
Ret ok(const std::string& ev) { return {true, ev}; }
|
||
Ret bad(const std::string& ev) { return {false, ev}; }
|
||
|
||
template <typename Fn>
|
||
void check(const char* name, Fn fn) {
|
||
std::fprintf(stderr, "[RUN] %s\n", name);
|
||
std::fflush(stderr);
|
||
auto t0 = std::chrono::steady_clock::now();
|
||
Ret r{false, "no-result"};
|
||
try {
|
||
r = fn();
|
||
} catch (const std::exception& e) {
|
||
r = bad(std::string("exception: ") + e.what());
|
||
} catch (...) {
|
||
r = bad("unknown exception");
|
||
}
|
||
const double ms =
|
||
std::chrono::duration<double, std::milli>(std::chrono::steady_clock::now() - t0)
|
||
.count();
|
||
++g_total;
|
||
g_ms += ms;
|
||
if (r.first) {
|
||
++g_pass;
|
||
std::printf("[PASS] %s: %s (%.1fms)\n", name, r.second.c_str(), ms);
|
||
} else {
|
||
++g_fail;
|
||
g_fails.push_back(name);
|
||
std::printf("[FAIL] %s: %s (%.1fms)\n", name, r.second.c_str(), ms);
|
||
}
|
||
std::fflush(stdout);
|
||
}
|
||
void unknown(const char* name, const std::string& why) {
|
||
++g_total;
|
||
++g_unk;
|
||
std::printf("[UNKNOWN] %s: %s\n", name, why.c_str());
|
||
std::fflush(stdout);
|
||
}
|
||
|
||
vde::fs::path tmp(const char* name) {
|
||
auto p = vde::fs::temp_directory_path() / "vde_audit_fmt";
|
||
vde::fs::create_directories(p);
|
||
return p / name;
|
||
}
|
||
bool exists_nonempty(const vde::fs::path& p) {
|
||
std::error_code ec;
|
||
if (!vde::fs::exists(p, ec)) return false;
|
||
return vde::fs::file_size(p, ec) > 0;
|
||
}
|
||
void clean(const vde::fs::path& p) {
|
||
std::error_code ec;
|
||
vde::fs::remove(p, ec);
|
||
}
|
||
bool read_text(const vde::fs::path& p, std::string* out) {
|
||
std::ifstream f(p.string(), std::ios::binary);
|
||
if (!f) return false;
|
||
*out = std::string((std::istreambuf_iterator<char>(f)),
|
||
std::istreambuf_iterator<char>());
|
||
return true;
|
||
}
|
||
|
||
BrepModel box10() { return brep::make_box(10.0, 10.0, 10.0); }
|
||
|
||
double volume_of(const BrepModel& m) { return std::abs(m.body_volume()); }
|
||
|
||
} // namespace
|
||
|
||
int main(int argc, char** argv) {
|
||
if (argc > 1) g_group = argv[1];
|
||
if (argc > 2) g_base = argv[2];
|
||
std::printf("=== C-7 audit: format families (group=%s, base=%s) ===\n",
|
||
g_group.c_str(), g_base.c_str());
|
||
using namespace vde;
|
||
|
||
// ------------------------------------------------------------------- STEP
|
||
if (want("step")) {
|
||
check("step.import_from_string.roundtrip", [] {
|
||
const BrepModel box = box10();
|
||
const std::string step = brep::export_step({box});
|
||
auto bodies = brep::import_step_from_string(step);
|
||
if (bodies.size() != 1u)
|
||
return bad(fmt("bodies=%zu expect 1", bodies.size()));
|
||
const double v = volume_of(bodies[0]);
|
||
const double rel = std::abs(v - 1000.0) / 1000.0;
|
||
return (rel < 1e-6 && brep::step_last_error() == brep::StepError::Ok)
|
||
? ok(fmt("vol=%.6f rel=%.2e faces=%zu", v, rel,
|
||
bodies[0].num_faces()))
|
||
: bad(fmt("vol=%.6f rel=%.2e err=%d", v, rel,
|
||
static_cast<int>(brep::step_last_error())));
|
||
});
|
||
check("step.export_file.import_file", [] {
|
||
const auto p = tmp("audit_box.stp");
|
||
clean(p);
|
||
if (!brep::export_step_file(p.string(), {box10()}))
|
||
return bad("export_step_file failed");
|
||
if (!exists_nonempty(p)) return bad("STEP file missing/empty");
|
||
auto bodies = brep::import_step(p.string());
|
||
clean(p);
|
||
return (bodies.size() == 1u && bodies[0].num_faces() == 6u)
|
||
? ok(fmt("roundtrip bodies=1 faces=6"))
|
||
: bad(fmt("bodies=%zu faces=%zu", bodies.size(),
|
||
bodies.empty() ? 0 : bodies[0].num_faces()));
|
||
});
|
||
check("step.corrupt_input_honest", [] {
|
||
auto bodies = brep::import_step_from_string("garbage not a step file");
|
||
const auto err = brep::step_last_error();
|
||
if (!bodies.empty()) return bad("corrupt input produced bodies");
|
||
if (err == brep::StepError::Ok)
|
||
return bad("corrupt input reported Ok error");
|
||
return ok(fmt("empty bodies + StepError=%d", static_cast<int>(err)));
|
||
});
|
||
check("step.missing_file_honest", [] {
|
||
auto bodies = brep::import_step((tmp("missing_xyz.stp")).string());
|
||
return bodies.empty() ? ok("missing file -> empty bodies")
|
||
: bad("missing file produced bodies");
|
||
});
|
||
check("step.import_cancel_honest", [] {
|
||
const auto p = tmp("audit_cancel.stp");
|
||
clean(p);
|
||
brep::export_step_file(p.string(), {box10()});
|
||
std::atomic<bool> cancel{true};
|
||
brep::StepImportOptions opts;
|
||
opts.cancel = &cancel;
|
||
auto bodies = brep::import_step(p.string(), opts);
|
||
const auto err = brep::step_last_error();
|
||
clean(p);
|
||
if (!bodies.empty()) return bad("cancelled import returned bodies");
|
||
return (err == brep::StepError::Cancelled)
|
||
? ok("pre-cancelled import -> empty bodies + Cancelled")
|
||
: bad(fmt("cancel not honoured: StepError=%d",
|
||
static_cast<int>(err)));
|
||
});
|
||
check("step.ap242.pmi_roundtrip", [] {
|
||
vde::io::StepPMIAnnotation a1;
|
||
a1.type = "linear_dimension";
|
||
a1.id = "PMI-1";
|
||
a1.description = "thickness";
|
||
a1.nominal_value = 10.0;
|
||
a1.upper_tolerance = 0.1;
|
||
a1.lower_tolerance = 0.1;
|
||
vde::io::StepPMIAnnotation a2;
|
||
a2.type = "diameter_dimension";
|
||
a2.id = "PMI-2";
|
||
a2.description = "hole";
|
||
a2.nominal_value = 6.0;
|
||
vde::io::StepAP242Options opts;
|
||
const std::string text = vde::io::export_step_ap242({box10()}, {a1, a2}, opts);
|
||
if (text.find("AP242") == std::string::npos)
|
||
return bad("AP242 export missing schema string");
|
||
auto imp = vde::io::import_step_ap242_from_string(text);
|
||
if (imp.bodies.empty()) return bad("AP242 import produced no bodies");
|
||
return (imp.annotations.size() == 2u)
|
||
? ok(fmt("AP242 roundtrip: bodies=%zu PMI=%zu", imp.bodies.size(),
|
||
imp.annotations.size()))
|
||
: bad(fmt("AP242 PMI lost: %zu expect 2", imp.annotations.size()));
|
||
});
|
||
}
|
||
|
||
// ------------------------------------------------------------------- IGES
|
||
if (want("iges")) {
|
||
check("iges.export_string", [] {
|
||
const std::string iges = brep::export_iges({box10()});
|
||
if (iges.size() < 100) return bad(fmt("export_iges too short: %zu", iges.size()));
|
||
if (iges.find("S 1") == std::string::npos &&
|
||
iges.find("S ") == std::string::npos)
|
||
return bad("missing IGES Start section marker");
|
||
return ok(fmt("export_iges size=%zu", iges.size()));
|
||
});
|
||
check("iges.file_roundtrip", [] {
|
||
const auto p = tmp("audit_box.igs");
|
||
clean(p);
|
||
if (!brep::export_iges_file(p.string(), {box10()}))
|
||
return bad("export_iges_file failed");
|
||
if (!exists_nonempty(p)) return bad("IGES file missing");
|
||
auto bodies = brep::import_iges(p.string());
|
||
clean(p);
|
||
if (bodies.empty()) return bad("import_iges -> empty");
|
||
return (bodies[0].num_faces() >= 6u)
|
||
? ok(fmt("roundtrip bodies=%zu faces=%zu", bodies.size(),
|
||
bodies[0].num_faces()))
|
||
: bad(fmt("faces=%zu expect >=6", bodies[0].num_faces()));
|
||
});
|
||
check("iges.corrupt_input_honest", [] {
|
||
auto bodies = brep::import_iges_from_string("not an iges file");
|
||
return bodies.empty() ? ok("corrupt input -> empty bodies (no crash)")
|
||
: bad(fmt("corrupt input -> %zu bodies", bodies.size()));
|
||
});
|
||
check("iges.missing_file_honest", [] {
|
||
auto bodies = brep::import_iges((tmp("missing_xyz.igs")).string());
|
||
return bodies.empty() ? ok("missing file -> empty bodies")
|
||
: bad("missing file produced bodies");
|
||
});
|
||
}
|
||
|
||
// -------------------------------------------------------------- XT / SAT / JT
|
||
if (want("xt")) {
|
||
check("xt.export_file", [] {
|
||
const auto p = tmp("audit_box.x_t");
|
||
clean(p);
|
||
if (!vde::io::export_parasolid_xt(box10(), p.string()))
|
||
return bad("export_parasolid_xt failed");
|
||
return exists_nonempty(p) ? ok(fmt("x_t size=%llu",
|
||
(unsigned long long)vde::fs::file_size(p)))
|
||
: bad("x_t missing/empty");
|
||
});
|
||
check("xt.import_roundtrip", [] {
|
||
const auto p = tmp("audit_box.x_t");
|
||
clean(p);
|
||
vde::io::export_parasolid_xt(box10(), p.string());
|
||
auto back = vde::io::import_parasolid_xt(p.string());
|
||
clean(p);
|
||
const double v = volume_of(back);
|
||
const double rel = std::abs(v - 1000.0) / 1000.0;
|
||
if (back.num_faces() != 6u || rel > 1e-2)
|
||
return bad(fmt("XT roundtrip faces=%zu verts=%zu edges=%zu vol=%.3f "
|
||
"rel=%.3f (10x10x10 box expected 6 faces vol=1000)",
|
||
back.num_faces(), back.num_vertices(), back.num_edges(), v,
|
||
rel));
|
||
return ok(fmt("XT roundtrip faces=6 vol=%.6f", v));
|
||
});
|
||
check("xt.corrupt_input_honest", [] {
|
||
const auto p = tmp("audit_bad.x_t");
|
||
std::ofstream(p.c_str(), std::ios::binary) << "garbage parasolid";
|
||
auto back = vde::io::import_parasolid_xt(p.string());
|
||
clean(p);
|
||
return (back.num_faces() == 0) ? ok("corrupt XT -> empty body (no crash)")
|
||
: bad(fmt("corrupt XT -> %zu faces",
|
||
back.num_faces()));
|
||
});
|
||
}
|
||
if (want("sat")) {
|
||
check("sat.export_file", [] {
|
||
const auto p = tmp("audit_box.sat");
|
||
clean(p);
|
||
if (!vde::io::export_acis_sat(box10(), p.string()))
|
||
return bad("export_acis_sat failed");
|
||
return exists_nonempty(p) ? ok(fmt("sat size=%llu",
|
||
(unsigned long long)vde::fs::file_size(p)))
|
||
: bad("sat missing/empty");
|
||
});
|
||
check("sat.import_roundtrip", [] {
|
||
const auto p = tmp("audit_box.sat");
|
||
clean(p);
|
||
vde::io::export_acis_sat(box10(), p.string());
|
||
auto back = vde::io::import_acis_sat(p.string());
|
||
clean(p);
|
||
const double v = volume_of(back);
|
||
const double rel = std::abs(v - 1000.0) / 1000.0;
|
||
if (back.num_faces() != 6u || rel > 1e-2)
|
||
return bad(fmt("SAT roundtrip faces=%zu verts=%zu edges=%zu vol=%.3f "
|
||
"rel=%.3f (10x10x10 box expected 6 faces vol=1000)",
|
||
back.num_faces(), back.num_vertices(), back.num_edges(), v,
|
||
rel));
|
||
return ok(fmt("SAT roundtrip faces=6 vol=%.6f", v));
|
||
});
|
||
check("sat.corrupt_input_honest", [] {
|
||
const auto p = tmp("audit_bad.sat");
|
||
std::ofstream(p.c_str(), std::ios::binary) << "not a sat file";
|
||
auto back = vde::io::import_acis_sat(p.string());
|
||
clean(p);
|
||
return (back.num_faces() == 0) ? ok("corrupt SAT -> empty body (no crash)")
|
||
: bad(fmt("corrupt SAT -> %zu faces",
|
||
back.num_faces()));
|
||
});
|
||
}
|
||
if (want("jt")) {
|
||
check("jt.export_file", [] {
|
||
const auto p = tmp("audit_box.jt");
|
||
clean(p);
|
||
if (!vde::io::export_jt(box10(), p.string()))
|
||
return bad("export_jt failed");
|
||
if (!exists_nonempty(p)) return bad("jt missing/empty");
|
||
std::string head;
|
||
std::ifstream f(p.string(), std::ios::binary);
|
||
head.assign(80, '\0');
|
||
f.read(&head[0], 80);
|
||
return (head.find("JT") != std::string::npos)
|
||
? ok("jt file written with JT version marker")
|
||
: bad("JT marker not found in header");
|
||
});
|
||
check("jt.import_roundtrip", [] {
|
||
const auto p = tmp("audit_box.jt");
|
||
clean(p);
|
||
vde::io::export_jt(box10(), p.string());
|
||
auto back = vde::io::import_jt(p.string());
|
||
clean(p);
|
||
const double v = volume_of(back);
|
||
const double rel = std::abs(v - 1000.0) / 1000.0;
|
||
if (back.num_faces() != 6u || rel > 1e-2)
|
||
return bad(fmt("JT roundtrip faces=%zu verts=%zu edges=%zu vol=%.3f "
|
||
"rel=%.3f (10x10x10 box expected 6 faces vol=1000)",
|
||
back.num_faces(), back.num_vertices(), back.num_edges(), v,
|
||
rel));
|
||
return ok(fmt("JT roundtrip faces=6 vol=%.6f", v));
|
||
});
|
||
check("jt.corrupt_input_honest", [] {
|
||
const auto p = tmp("audit_bad.jt");
|
||
std::ofstream(p.c_str(), std::ios::binary) << "garbage jt";
|
||
bool threw = false;
|
||
std::string what;
|
||
try {
|
||
auto back = vde::io::import_jt(p.string());
|
||
(void)back;
|
||
} catch (const std::runtime_error& e) {
|
||
threw = true;
|
||
what = e.what();
|
||
}
|
||
clean(p);
|
||
return threw ? ok(fmt("corrupt JT -> documented runtime_error ('%s')",
|
||
what.c_str()))
|
||
: bad("corrupt JT did not report failure");
|
||
});
|
||
}
|
||
|
||
// ------------------------------------------- XT / SAT / JT 曲线体往返(C-7b)
|
||
if (want("xt")) {
|
||
check("xt.curve_body_roundtrip", [] {
|
||
// 解析圆柱(4 段精确圆柱面 + 圆边)往返:体积 rel 0、valid、无降级
|
||
const auto base = brep::make_cylinder(5.0, 10.0, 0);
|
||
const double ev = M_PI * 25.0 * 10.0;
|
||
const auto p = tmp("audit_cyl.x_t");
|
||
clean(p);
|
||
if (!vde::io::export_parasolid_xt(base, p.string()))
|
||
return bad("export_parasolid_xt(curve body) failed");
|
||
auto back = vde::io::import_parasolid_xt(p.string());
|
||
clean(p);
|
||
const double v = std::abs(brep::analytic_measure(back).volume);
|
||
const double rel = std::abs(v - ev) / ev;
|
||
const bool valid = brep::validate(back).valid;
|
||
if (rel > 1e-3 || !valid)
|
||
return bad(fmt("F=%zu V=%zu vol=%.4f exp=%.4f rel=%.2e valid=%d",
|
||
back.num_faces(), back.num_vertices(), v, ev, rel,
|
||
(int)valid));
|
||
return ok(fmt("curve-body roundtrip F=%zu vol=%.4f rel=%.2e valid=1",
|
||
back.num_faces(), v, rel));
|
||
});
|
||
}
|
||
if (want("sat")) {
|
||
check("sat.curve_body_roundtrip", [] {
|
||
const auto base = brep::make_cylinder(5.0, 10.0, 0);
|
||
const double ev = M_PI * 25.0 * 10.0;
|
||
const auto p = tmp("audit_cyl.sat");
|
||
clean(p);
|
||
if (!vde::io::export_acis_sat(base, p.string()))
|
||
return bad("export_acis_sat(curve body) failed");
|
||
auto back = vde::io::import_acis_sat(p.string());
|
||
clean(p);
|
||
const double v = std::abs(brep::analytic_measure(back).volume);
|
||
const double rel = std::abs(v - ev) / ev;
|
||
const bool valid = brep::validate(back).valid;
|
||
if (rel > 1e-3 || !valid)
|
||
return bad(fmt("F=%zu V=%zu vol=%.4f exp=%.4f rel=%.2e valid=%d",
|
||
back.num_faces(), back.num_vertices(), v, ev, rel,
|
||
(int)valid));
|
||
return ok(fmt("curve-body roundtrip F=%zu vol=%.4f rel=%.2e valid=1",
|
||
back.num_faces(), v, rel));
|
||
});
|
||
}
|
||
if (want("jt")) {
|
||
check("jt.curve_body_roundtrip", [] {
|
||
const auto base = brep::make_cylinder(5.0, 10.0, 0);
|
||
const double ev = M_PI * 25.0 * 10.0;
|
||
const auto p = tmp("audit_cyl.jt");
|
||
clean(p);
|
||
if (!vde::io::export_jt(base, p.string()))
|
||
return bad("export_jt(curve body) failed");
|
||
auto back = vde::io::import_jt(p.string());
|
||
clean(p);
|
||
const double v = std::abs(brep::analytic_measure(back).volume);
|
||
const double rel = std::abs(v - ev) / ev;
|
||
const bool valid = brep::validate(back).valid;
|
||
if (rel > 1e-3 || !valid)
|
||
return bad(fmt("F=%zu V=%zu vol=%.4f exp=%.4f rel=%.2e valid=%d",
|
||
back.num_faces(), back.num_vertices(), v, ev, rel,
|
||
(int)valid));
|
||
return ok(fmt("curve-body roundtrip F=%zu vol=%.4f rel=%.2e valid=1",
|
||
back.num_faces(), v, rel));
|
||
});
|
||
}
|
||
// -------------------------------------------------------------------- 3MF
|
||
if (want("3mf")) {
|
||
check("3mf.write_read.roundtrip", [] {
|
||
mesh::HalfedgeMesh m;
|
||
std::vector<Point3D> v = {{0, 0, 0}, {10, 0, 0}, {0, 10, 0}, {0, 0, 10}};
|
||
std::vector<std::array<int, 3>> t = {{0, 2, 1}, {0, 1, 3}, {0, 3, 2},
|
||
{1, 2, 3}};
|
||
m.build_from_triangles(v, t);
|
||
foundation::ThreeMFMesh tm;
|
||
tm.mesh = m;
|
||
tm.name = "tet";
|
||
const auto p = tmp("audit_tet.3mf");
|
||
clean(p);
|
||
if (!foundation::write_3mf(p.string(), {tm}, "VDE-Audit"))
|
||
return bad("write_3mf failed");
|
||
auto loaded = foundation::read_3mf(p.string());
|
||
clean(p);
|
||
return (loaded.size() == 1u && loaded[0].mesh.num_vertices() == 4u &&
|
||
loaded[0].mesh.num_faces() == 4u)
|
||
? ok("3MF stored roundtrip: 1 mesh, 4v/4f")
|
||
: bad(fmt("loaded=%zu v=%zu f=%zu", loaded.size(),
|
||
loaded.empty() ? 0 : loaded[0].mesh.num_vertices(),
|
||
loaded.empty() ? 0 : loaded[0].mesh.num_faces()));
|
||
});
|
||
// Compression API (write_3mf_ex/read_3mf_ex) + task-74 built-in deflate:
|
||
// enabled by -DAUDIT_NEW_API at the freeze build.
|
||
#ifdef AUDIT_NEW_API
|
||
// task-74 (A-9c):内置 deflate 写出已实现(ZIP method=8 + raw deflate,
|
||
// 固定 Huffman + LZ77,零外部依赖)——验证 stored vs deflate 压缩率与回读一致性,
|
||
// bzip2(12)/lzma(14) 仍必须诚实 Unsupported。
|
||
check("3mf.deflate_roundtrip_ratio", [] {
|
||
foundation::ThreeMFMesh tm;
|
||
tm.mesh = brep::make_sphere(10.0, 32, 16).to_mesh(0.2);
|
||
tm.name = "sphere";
|
||
const auto ps = tmp("audit_stored.3mf");
|
||
const auto pd = tmp("audit_deflate.3mf");
|
||
clean(ps);
|
||
clean(pd);
|
||
foundation::ThreeMFWriteOptions so;
|
||
so.compression = foundation::ThreeMFCompression::Stored;
|
||
foundation::ThreeMFWriteOptions dop;
|
||
dop.compression = foundation::ThreeMFCompression::Deflate;
|
||
const auto rs = foundation::write_3mf_ex(ps.string(), {tm}, so);
|
||
const auto rdo = foundation::write_3mf_ex(pd.string(), {tm}, dop);
|
||
std::error_code ec;
|
||
const auto szs = vde::fs::file_size(ps, ec);
|
||
const auto szd = vde::fs::file_size(pd, ec);
|
||
const auto back = foundation::read_3mf_ex(pd.string());
|
||
clean(ps);
|
||
clean(pd);
|
||
if (!rs.ok() || !rdo.ok())
|
||
return bad(fmt("write stored=%d deflate=%d message='%s'",
|
||
(int)rs.ok(), (int)rdo.ok(), rdo.message.c_str()));
|
||
if (szd == 0 || szs == 0)
|
||
return bad("empty 3mf file (stored/deflate)");
|
||
const double ratio = static_cast<double>(szs) / static_cast<double>(szd);
|
||
if (ratio < 1.5)
|
||
return bad(fmt("deflate ratio=%.2fx stored=%llu deflate=%llu (expect >=1.5x)",
|
||
ratio, (unsigned long long)szs, (unsigned long long)szd));
|
||
if (!back.ok || back.meshes.empty() || back.meshes[0].mesh.num_faces() == 0)
|
||
return bad(fmt("deflate readback failed: ok=%d meshes=%zu",
|
||
(int)back.ok, back.meshes.size()));
|
||
return ok(fmt("deflate method=8: stored=%lluB deflate=%lluB ratio=%.2fx "
|
||
"readback v=%zu f=%zu",
|
||
(unsigned long long)szs, (unsigned long long)szd, ratio,
|
||
back.meshes[0].mesh.num_vertices(),
|
||
back.meshes[0].mesh.num_faces()));
|
||
});
|
||
check("3mf.bzip2_lzma_unsupported", [] {
|
||
foundation::ThreeMFMesh tm;
|
||
{
|
||
mesh::HalfedgeMesh m;
|
||
std::vector<Point3D> v = {{0, 0, 0}, {1, 0, 0}, {0, 1, 0}, {0, 0, 1}};
|
||
std::vector<std::array<int, 3>> t = {{0, 2, 1}, {0, 1, 3}, {0, 3, 2},
|
||
{1, 2, 3}};
|
||
m.build_from_triangles(v, t);
|
||
tm.mesh = m;
|
||
tm.name = "tet";
|
||
}
|
||
auto probe = [&](foundation::ThreeMFCompression c, const char* name) {
|
||
const auto p = tmp(name);
|
||
clean(p);
|
||
foundation::ThreeMFWriteOptions o;
|
||
o.compression = c;
|
||
o.allow_stored_fallback = false;
|
||
const auto r = foundation::write_3mf_ex(p.string(), {tm}, o);
|
||
const bool file_written = exists_nonempty(p);
|
||
clean(p);
|
||
return std::make_pair(r.status, file_written);
|
||
};
|
||
const auto b = probe(foundation::ThreeMFCompression::Bzip2, "audit_bzip2.3mf");
|
||
const auto l = probe(foundation::ThreeMFCompression::Lzma, "audit_lzma.3mf");
|
||
const bool all_ok = b.first == foundation::ThreeMFWriteStatus::Unsupported &&
|
||
l.first == foundation::ThreeMFWriteStatus::Unsupported &&
|
||
!b.second && !l.second;
|
||
if (!all_ok)
|
||
return bad(fmt("bzip2(status=%d file=%d) lzma(status=%d file=%d)",
|
||
(int)b.first, (int)b.second, (int)l.first, (int)l.second));
|
||
return ok("bzip2(12)/lzma(14) -> Unsupported, no partial file");
|
||
});
|
||
#else
|
||
unknown("3mf.deflate_roundtrip_ratio",
|
||
"write_3mf_ex/ThreeMFWriteOptions(task-74 内置 deflate)为冻结后 API;"
|
||
"本探针按旧树 API 编译,冻结批次用 -DAUDIT_NEW_API 覆盖");
|
||
unknown("3mf.bzip2_lzma_unsupported",
|
||
"write_3mf_ex 为冻结后 API;冻结批次用 -DAUDIT_NEW_API 覆盖");
|
||
#endif
|
||
|
||
#ifdef AUDIT_NEW_API
|
||
check("3mf.missing_file_honest", [] {
|
||
auto res = foundation::read_3mf_ex(tmp("missing_xyz.3mf").string());
|
||
auto plain = foundation::read_3mf(tmp("missing_xyz.3mf").string());
|
||
return (!res.ok && plain.empty())
|
||
? ok("missing 3MF -> not ok / empty (honest)")
|
||
: bad("missing 3MF not reported honestly");
|
||
});
|
||
#else
|
||
check("3mf.missing_file_honest", [] {
|
||
auto plain = foundation::read_3mf(tmp("missing_xyz.3mf").string());
|
||
return plain.empty() ? ok("missing 3MF -> empty (honest, old API)")
|
||
: bad("missing 3MF produced meshes");
|
||
});
|
||
#endif
|
||
}
|
||
|
||
// ------------------------------------------------------------------- glTF
|
||
if (want("gltf")) {
|
||
check("gltf.write_json_and_import", [] {
|
||
mesh::HalfedgeMesh m;
|
||
std::vector<Point3D> v = {{0, 0, 0}, {2, 0, 0}, {0, 2, 0}, {0, 0, 2}};
|
||
std::vector<std::array<int, 3>> t = {{0, 2, 1}, {0, 1, 3}, {0, 3, 2},
|
||
{1, 2, 3}};
|
||
m.build_from_triangles(v, t);
|
||
foundation::GltfOptions opt;
|
||
opt.binary = false;
|
||
const auto p = tmp("audit_tet.gltf");
|
||
clean(p);
|
||
if (!foundation::write_gltf(p.string(), m, opt))
|
||
return bad("write_gltf(json) failed");
|
||
std::string text;
|
||
read_text(p, &text);
|
||
clean(p);
|
||
if (text.find("\"asset\"") == std::string::npos ||
|
||
text.find("\"meshes\"") == std::string::npos)
|
||
return bad("glTF JSON missing asset/meshes");
|
||
return ok(fmt("glTF JSON size=%zu with asset/meshes", text.size()));
|
||
});
|
||
check("gltf.binary_export", [] {
|
||
mesh::HalfedgeMesh m;
|
||
std::vector<Point3D> v = {{0, 0, 0}, {2, 0, 0}, {0, 2, 0}, {0, 0, 2}};
|
||
std::vector<std::array<int, 3>> t = {{0, 2, 1}, {0, 1, 3}, {0, 3, 2},
|
||
{1, 2, 3}};
|
||
m.build_from_triangles(v, t);
|
||
foundation::GltfOptions opt;
|
||
opt.binary = true;
|
||
const auto p = tmp("audit_tet.glb");
|
||
clean(p);
|
||
if (!foundation::write_gltf(p.string(), m, opt))
|
||
return bad("write_gltf(glb) failed");
|
||
std::ifstream f(p.string(), std::ios::binary);
|
||
char magic[4] = {};
|
||
f.read(magic, 4);
|
||
clean(p);
|
||
return (std::string(magic, 4) == "glTF")
|
||
? ok("GLB magic 'glTF' ok")
|
||
: bad("GLB magic mismatch");
|
||
});
|
||
check("gltf.cancel_honest", [] {
|
||
const auto p = tmp("audit_cancel.glb");
|
||
clean(p);
|
||
std::atomic<bool> cancel{true};
|
||
foundation::GltfExportOptions opts;
|
||
opts.cancel = &cancel;
|
||
const bool okw = foundation::write_brep_gltf(p.string(), box10(), opts);
|
||
const bool written = exists_nonempty(p);
|
||
clean(p);
|
||
return (!okw && !written)
|
||
? ok("pre-cancelled glTF export -> false, no file")
|
||
: bad(fmt("cancel not honoured: ok=%d written=%d", (int)okw,
|
||
(int)written));
|
||
});
|
||
}
|
||
|
||
// -------------------------------------------------------------- point cloud
|
||
if (want("pcl")) {
|
||
auto sample_cloud = [] {
|
||
mesh::PointCloud pc;
|
||
for (int i = 0; i < 8; ++i)
|
||
pc.vertices.emplace_back(i * 0.5, i * 0.25, i * 0.1);
|
||
return pc;
|
||
};
|
||
#ifdef AUDIT_NEW_API
|
||
check("pcl.las_roundtrip", [&] {
|
||
const mesh::PointCloud pc = sample_cloud();
|
||
const auto p = tmp("audit_pc.las");
|
||
clean(p);
|
||
auto wr = pc.save_las(p.string());
|
||
if (!wr.ok()) return bad("save_las: " + wr.message);
|
||
auto back = mesh::PointCloud::load_las(p.string());
|
||
clean(p);
|
||
return (back.size() == pc.size())
|
||
? ok(fmt("LAS roundtrip %zu points", back.size()))
|
||
: bad(fmt("LAS roundtrip %zu vs %zu", back.size(), pc.size()));
|
||
});
|
||
#else
|
||
unknown("pcl.las_roundtrip",
|
||
"save_las 为冻结构建树之后新增 API(旧树仅 load_las / save_ply);"
|
||
"冻结批次可用 -DAUDIT_NEW_API 启用(已预留分支)");
|
||
#endif
|
||
#ifdef AUDIT_NEW_API
|
||
check("pcl.laz_roundtrip", [&] {
|
||
const mesh::PointCloud pc = sample_cloud();
|
||
const auto p = tmp("audit_pc.laz");
|
||
clean(p);
|
||
auto wr = pc.save_laz(p.string());
|
||
if (!wr.ok()) return bad("save_laz: " + wr.message);
|
||
auto back = mesh::PointCloud::load_las(p.string());
|
||
clean(p);
|
||
if (back.size() != pc.size())
|
||
return bad(fmt("LAZ roundtrip %zu vs %zu", back.size(), pc.size()));
|
||
double max_dev = 0.0;
|
||
for (size_t i = 0; i < pc.size() && i < back.size(); ++i) {
|
||
const core::Point3D a = pc.vertices[i];
|
||
const core::Point3D b = back.vertices[i];
|
||
max_dev = std::max(max_dev, std::sqrt((a.x()-b.x())*(a.x()-b.x()) +
|
||
(a.y()-b.y())*(a.y()-b.y()) +
|
||
(a.z()-b.z())*(a.z()-b.z())));
|
||
}
|
||
if (max_dev > 5e-7)
|
||
return bad(fmt("LAZ roundtrip %zu points max_dev=%.2e", back.size(), max_dev));
|
||
return ok(fmt("LAZ roundtrip %zu points max_dev=%.2e", back.size(), max_dev));
|
||
});
|
||
#else
|
||
unknown("pcl.laz_roundtrip",
|
||
"save_laz 为 Phase4 新增 API,需 -DAUDIT_NEW_API 启用");
|
||
#endif
|
||
check("pcl.ply_roundtrip", [&] {
|
||
const mesh::PointCloud pc = sample_cloud();
|
||
const auto p = tmp("audit_pc.ply");
|
||
clean(p);
|
||
if (!pc.save_ply(p.string())) return bad("save_ply failed");
|
||
auto back = mesh::PointCloud::load_ply(p.string());
|
||
clean(p);
|
||
return (back.size() == pc.size())
|
||
? ok(fmt("PLY roundtrip %zu points", back.size()))
|
||
: bad(fmt("PLY roundtrip %zu vs %zu", back.size(), pc.size()));
|
||
});
|
||
check("pcl.missing_file_honest", [] {
|
||
bool threw = false;
|
||
std::string what;
|
||
size_t n = 0;
|
||
try {
|
||
auto back = mesh::PointCloud::load_las(tmp("missing_xyz.las").string());
|
||
n = back.size();
|
||
} catch (const std::runtime_error& e) {
|
||
threw = true;
|
||
what = e.what();
|
||
}
|
||
if (threw) return ok(fmt("missing LAS -> runtime_error ('%s'); "
|
||
"头文件未声明 @throws(文档缺口)", what.c_str()));
|
||
return n == 0 ? ok("missing LAS -> empty cloud") : bad("missing LAS produced points");
|
||
});
|
||
}
|
||
|
||
// ---------------------------------------------------------------- PDF3D
|
||
if (want("pdf")) {
|
||
check("pdf3d.export_bytes", [] {
|
||
auto bytes = vde::io::export_pdf3d(box10());
|
||
if (bytes.size() < 100) return bad(fmt("pdf bytes=%zu too small", bytes.size()));
|
||
const std::string head(bytes.begin(), bytes.begin() + 4);
|
||
return (head == "%PDF") ? ok(fmt("PDF3D %zu bytes, %%PDF header", bytes.size()))
|
||
: bad("PDF3D missing %PDF header");
|
||
});
|
||
check("pdf3d.export_file", [] {
|
||
const auto p = tmp("audit_box.pdf");
|
||
clean(p);
|
||
if (!vde::io::export_pdf3d_file(p.string(), box10()))
|
||
return bad("export_pdf3d_file failed");
|
||
const bool okfile = exists_nonempty(p);
|
||
clean(p);
|
||
return okfile ? ok("PDF3D file written non-empty")
|
||
: bad("PDF3D file missing/empty");
|
||
});
|
||
check("pdf3d.import_u3d_bytes", [] {
|
||
// A-9b:U3D 导入(export_pdf3d 写出 U3D 网格 → import_pdf3d 解析)
|
||
auto bytes = vde::io::export_pdf3d(box10());
|
||
auto r = vde::io::import_pdf3d(bytes);
|
||
const double v = std::abs(brep::analytic_measure(r.body).volume);
|
||
const double rel = std::abs(v - 1000.0) / 1000.0;
|
||
if (!r.success || r.container != vde::io::Pdf3dContainerType::U3D ||
|
||
r.num_triangles == 0 || r.body.num_faces() == 0 || rel > 1e-3)
|
||
return bad(fmt("success=%d container=%d verts=%zu tris=%zu faces=%zu "
|
||
"vol=%.3f rel=%.2e objs=%zu",
|
||
(int)r.success, (int)r.container, r.num_vertices,
|
||
r.num_triangles, r.body.num_faces(), v, rel, r.pdf_objects));
|
||
return ok(fmt("U3D import: verts=%zu tris=%zu faces=%zu vol=%.3f rel=%.2e "
|
||
"(pdf objs=%zu streams=%zu)",
|
||
r.num_vertices, r.num_triangles, r.body.num_faces(), v, rel,
|
||
r.pdf_objects, r.pdf_streams));
|
||
});
|
||
check("pdf3d.import_u3d_file", [] {
|
||
const auto p = tmp("audit_box.pdf");
|
||
clean(p);
|
||
if (!vde::io::export_pdf3d_file(p.string(), box10()))
|
||
return bad("export_pdf3d_file failed");
|
||
auto r = vde::io::import_pdf3d_file(p.string());
|
||
clean(p);
|
||
if (!r.success || r.container != vde::io::Pdf3dContainerType::U3D ||
|
||
r.num_triangles == 0)
|
||
return bad(fmt("success=%d container=%d verts=%zu tris=%zu",
|
||
(int)r.success, (int)r.container, r.num_vertices,
|
||
r.num_triangles));
|
||
return ok(fmt("U3D file import: verts=%zu tris=%zu", r.num_vertices,
|
||
r.num_triangles));
|
||
});
|
||
check("pdf3d.prc_malformed_honest", [] {
|
||
// PRC 容器必须"明确不支持"(success=false + container=PRC + 诊断),不得静默失败
|
||
auto bytes = vde::io::export_pdf3d(box10());
|
||
bool patched = false;
|
||
for (size_t i = 0; i + 4 < bytes.size(); ++i) {
|
||
if (bytes[i] == 'U' && bytes[i + 1] == '3' && bytes[i + 2] == 'D' &&
|
||
bytes[i + 3] == ' ') {
|
||
bytes[i] = 'P';
|
||
bytes[i + 1] = 'R';
|
||
bytes[i + 2] = 'C';
|
||
bytes[i + 3] = ' ';
|
||
patched = true;
|
||
break;
|
||
}
|
||
}
|
||
if (!patched) return bad("U3D magic not found in exported PDF stream");
|
||
auto r = vde::io::import_pdf3d(bytes);
|
||
if (r.success || r.container != vde::io::Pdf3dContainerType::PRC ||
|
||
r.error.empty())
|
||
return bad(fmt("patched=%d success=%d container=%d error='%s'",
|
||
(int)patched, (int)r.success, (int)r.container,
|
||
r.error.c_str()));
|
||
return ok(fmt("malformed PRC honestly diagnosed: success=0 container=PRC error='%s'",
|
||
r.error.c_str()));
|
||
});
|
||
#ifdef AUDIT_NEW_API
|
||
check("pdf3d.prc_import_tess", [] {
|
||
// Phase4 task-88: minimal uncompressed 3D tessellation PRC must import.
|
||
std::vector<vde::core::Point3D> verts = {
|
||
vde::core::Point3D(0, 0, 0), vde::core::Point3D(1, 0, 0),
|
||
vde::core::Point3D(0, 1, 0), vde::core::Point3D(0, 0, 1)};
|
||
std::vector<std::array<int, 3>> tris = {{0, 1, 2}, {0, 1, 3},
|
||
{0, 2, 3}, {1, 2, 3}};
|
||
std::vector<uint8_t> prc;
|
||
std::string err;
|
||
if (!vde::io::prc_detail::build_minimal_prc(verts, tris, false, prc, err))
|
||
return bad("build_minimal_prc failed: " + err);
|
||
auto r = vde::io::import_pdf3d_prc(prc);
|
||
const double vol = std::abs(vde::brep::analytic_measure(r.body).volume);
|
||
const double exp = 1.0 / 6.0;
|
||
const double rel = std::abs(vol - exp) / exp;
|
||
if (!r.success || r.num_vertices != 4 || r.num_triangles != 4 ||
|
||
r.body.num_faces() == 0 || rel > 1e-6)
|
||
return bad(fmt("success=%d verts=%zu tris=%zu faces=%zu vol=%.6f rel=%.2e err='%s'",
|
||
(int)r.success, r.num_vertices, r.num_triangles,
|
||
r.body.num_faces(), vol, rel, r.error.c_str()));
|
||
return ok(fmt("PRC uncompressed tess: verts=%zu tris=%zu faces=%zu vol=%.6f rel=%.2e "
|
||
"(decompressed=%zu)",
|
||
r.num_vertices, r.num_triangles, r.body.num_faces(), vol, rel,
|
||
r.prc_tess_section_decompressed));
|
||
});
|
||
check("pdf3d.prc_compressed_diagnosed", [] {
|
||
// Phase4 task-88: compressed tessellation variant must be rejected with reason.
|
||
std::vector<vde::core::Point3D> verts = {
|
||
vde::core::Point3D(0, 0, 0), vde::core::Point3D(1, 0, 0),
|
||
vde::core::Point3D(0, 1, 0), vde::core::Point3D(0, 0, 1)};
|
||
std::vector<std::array<int, 3>> tris = {{0, 1, 2}, {1, 2, 3}};
|
||
std::vector<uint8_t> prc;
|
||
std::string err;
|
||
if (!vde::io::prc_detail::build_minimal_prc(verts, tris, false, prc, err, true))
|
||
return bad("build_minimal_prc(compressed) failed: " + err);
|
||
auto r = vde::io::import_pdf3d_prc(prc);
|
||
const bool mentions =
|
||
r.error.find("Compressed") != std::string::npos ||
|
||
r.error.find("compress") != std::string::npos ||
|
||
r.error.find("Huffman") != std::string::npos ||
|
||
r.error.find("å缩") != std::string::npos; // UTF-8 压缩
|
||
if (r.success || !mentions || r.diagnostics.empty())
|
||
return bad(fmt("success=%d diagnostics=%zu mentions=%d err='%s'",
|
||
(int)r.success, r.diagnostics.size(), (int)mentions,
|
||
r.error.c_str()));
|
||
return ok(fmt("compressed tess diagnosed honestly: diagnostics=%zu err='%s'",
|
||
r.diagnostics.size(), r.error.c_str()));
|
||
});
|
||
#else
|
||
unknown("pdf3d.prc_import_tess",
|
||
"import_pdf3d_prc 为 Phase4 新增 API,需 -DAUDIT_NEW_API 启用");
|
||
unknown("pdf3d.prc_compressed_diagnosed",
|
||
"import_pdf3d_prc 为 Phase4 新增 API,需 -DAUDIT_NEW_API 启用");
|
||
#endif
|
||
}
|
||
|
||
// --------------------------------------------------------- format detect
|
||
if (want("detect")) {
|
||
check("detect.format_api", [] {
|
||
auto bytes = [](const std::string& s) {
|
||
return std::vector<uint8_t>(s.begin(), s.end());
|
||
};
|
||
using vde::io::DetectedFormat;
|
||
using vde::io::FileFormat;
|
||
const DetectedFormat step = vde::io::detect_format(
|
||
bytes("ISO-10303-21;\nHEADER;\nENDSEC;\nDATA;\nENDSEC;\nEND-ISO-10303-21;\n"),
|
||
"model.step");
|
||
const bool step_ok = step.format == FileFormat::Step && step.is_known() &&
|
||
step.confidence >= 0.9 && !step.reason.empty();
|
||
const DetectedFormat dxf = vde::io::detect_format(
|
||
bytes("0\nSECTION\n2\nHEADER\n0\nENDSEC\n0\nEOF\n"));
|
||
const bool dxf_ok = dxf.format == FileFormat::Dxf && dxf.confidence >= 0.9;
|
||
const DetectedFormat stl = vde::io::detect_format(bytes(
|
||
"solid cube\nfacet normal 0 0 1\nouter loop\nvertex 0 0 0\nendloop\n"
|
||
"endfacet\nendsolid cube\n"));
|
||
const bool stl_ok = stl.format == FileFormat::Stl && stl.confidence >= 0.6;
|
||
const DetectedFormat unknown = vde::io::detect_format(
|
||
bytes("hello world, definitely not a CAD file"), "mystery.bin");
|
||
const bool unknown_ok = unknown.format == FileFormat::Unknown &&
|
||
unknown.confidence == 0.0 && !unknown.reason.empty();
|
||
// extension fallback (low confidence, no magic)
|
||
const DetectedFormat ext = vde::io::detect_format(
|
||
bytes("not a known magic header"), "part.step");
|
||
const bool ext_ok = ext.format == FileFormat::Step && ext.confidence > 0.0 &&
|
||
ext.confidence < 0.9 &&
|
||
ext.reason.find("扩展名") != std::string::npos;
|
||
// magic wins over conflicting extension hint
|
||
const DetectedFormat conflict = vde::io::detect_format(
|
||
bytes("ISO-10303-21;\nHEADER;\nENDSEC;\n"), "wrong.dwg");
|
||
const bool conflict_ok = conflict.format == FileFormat::Step &&
|
||
conflict.reason.find("魔数") != std::string::npos;
|
||
// file API + missing file honest
|
||
const auto path = tmp("audit_detect.step");
|
||
{
|
||
std::ofstream f(path.string(), std::ios::binary);
|
||
f << "ISO-10303-21;\nHEADER;\nENDSEC;\n";
|
||
}
|
||
const DetectedFormat file = vde::io::detect_format_file(path.string());
|
||
clean(path);
|
||
const bool file_ok = file.format == FileFormat::Step;
|
||
const DetectedFormat missing = vde::io::detect_format_file(
|
||
tmp("audit_detect_definitely_missing_xyz.step").string());
|
||
const bool missing_ok = missing.format == FileFormat::Unknown &&
|
||
!missing.reason.empty();
|
||
// empty input: no crash, Unknown + reason
|
||
const DetectedFormat empty = vde::io::detect_format({});
|
||
const bool empty_ok = empty.format == FileFormat::Unknown &&
|
||
empty.confidence == 0.0 && !empty.reason.empty();
|
||
// NUL/binary safety
|
||
const std::vector<uint8_t> nul_bytes = {'n', 'u', 'l', 0x00, 'b', 'y',
|
||
0x00, 't', 'e', 's'};
|
||
const DetectedFormat nul = vde::io::detect_format(nul_bytes, "blob.xyz");
|
||
const bool nul_ok = nul.format == FileFormat::Unknown && !nul.reason.empty();
|
||
// confidence always in [0,1]; magic >= 0.9, ext fallback < 0.5
|
||
const double confs[] = {step.confidence, dxf.confidence, stl.confidence,
|
||
unknown.confidence, ext.confidence, conflict.confidence,
|
||
file.confidence, missing.confidence, empty.confidence,
|
||
nul.confidence};
|
||
bool conf_ok = true;
|
||
for (double c : confs) conf_ok = conf_ok && c >= 0.0 && c <= 1.0;
|
||
const bool all = step_ok && dxf_ok && stl_ok && unknown_ok && ext_ok &&
|
||
conflict_ok && file_ok && missing_ok && empty_ok && nul_ok &&
|
||
conf_ok;
|
||
if (!all)
|
||
return bad(fmt("step=%d dxf=%d stl=%d unknown=%d ext=%d conflict=%d "
|
||
"file=%d missing=%d empty=%d nul=%d conf=%d "
|
||
"(step=%.2f ext=%.2f)",
|
||
(int)step_ok, (int)dxf_ok, (int)stl_ok, (int)unknown_ok,
|
||
(int)ext_ok, (int)conflict_ok, (int)file_ok, (int)missing_ok,
|
||
(int)empty_ok, (int)nul_ok, (int)conf_ok,
|
||
step.confidence, ext.confidence));
|
||
return ok(fmt("detect_format: STEP(%.2f)/DXF(%.2f)/STL(%.2f), unknown+reason, "
|
||
"ext-fallback(.step=%.2f), magic>ext, file API, missing/empty/NUL honest, "
|
||
"confidence in [0,1]",
|
||
step.confidence, dxf.confidence, stl.confidence, ext.confidence));
|
||
});
|
||
check("detect.step_vs_iges_cross_import", [] {
|
||
// 把 STEP 内容交给 IGES 导入器应诚实返回空,反之亦然
|
||
const std::string step = brep::export_step({box10()});
|
||
auto ig = brep::import_iges_from_string(step);
|
||
const std::string iges = brep::export_iges({box10()});
|
||
auto st = brep::import_step_from_string(iges);
|
||
return (ig.empty() && st.empty())
|
||
? ok("cross-format import rejected honestly both ways")
|
||
: bad(fmt("cross-import: step->iges=%zu iges->step=%zu", ig.size(),
|
||
st.size()));
|
||
});
|
||
}
|
||
|
||
// ------------------------------------------------------------------ summary
|
||
std::printf("\n=== SUMMARY: PASS=%d FAIL=%d UNKNOWN=%d total_checks=%d total=%.1fms ===\n",
|
||
g_pass, g_fail, g_unk, g_total, g_ms);
|
||
if (!g_fails.empty()) {
|
||
std::printf("FAILED CHECKS:\n");
|
||
for (auto& f : g_fails) std::printf(" - %s\n", f.c_str());
|
||
}
|
||
return g_fail == 0 ? 0 : 1;
|
||
}
|