Files

1608 lines
77 KiB
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Phase-1 audit probe for VDE B-Rep kernel capability surface.
// Scratch file (build/probe, not committed). One check = one [PASS]/[FAIL]/[UNKNOWN] line.
// Every check is isolated in try/catch and preceded by a "[RUN]" stderr marker so a
// hard crash still identifies the culprit check.
#include <cstdio>
#include <cstdarg>
#include <cmath>
#include <string>
#include <vector>
#include <chrono>
#include <functional>
#include "vde/fs_compat.h"
#include <utility>
#include "vde/core/point.h"
#include "vde/core/exact_predicates.h"
#include "vde/core/aabb.h"
#include "vde/core/transform.h"
#include "vde/curves/nurbs_curve.h"
#include "vde/curves/nurbs_surface.h"
#include "vde/curves/surface_tools.h"
#include "vde/mesh/halfedge_mesh.h"
#include "vde/brep/brep.h"
#include "vde/brep/modeling.h"
#include "vde/brep/brep_boolean.h"
#include "vde/brep/boolean_ext.h"
#include "vde/brep/boolean_fallback.h"
#include "vde/brep/boolean_split.h"
#include "vde/brep/brep_heal.h"
#include "vde/brep/feature_edit.h"
#include "vde/brep/feature_recognition.h"
#include "vde/brep/advanced_healing.h"
#include "vde/brep/brep_validate.h"
#include "vde/brep/measure.h"
#include "vde/brep/tolerance.h"
#include "vde/brep/direct_modeling.h"
#include "vde/brep/advanced_blend.h"
#include "vde/brep/draft_analysis.h"
#include "vde/brep/analytic_ssi.h"
#include "vde/brep/ssi_boolean.h"
#include "vde/brep/tolerant_modeling.h"
#include "vde/brep/trimmed_surface.h"
#include "vde/brep/nurbs_to_brep.h"
#include "vde/brep/section_view.h"
#include "vde/brep/assembly.h"
#include "vde/brep/feature_tree.h"
#include "vde/brep/parallel_boolean.h"
#include "vde/curves/class_a_surfacing.h"
#include "vde/foundation/vde_format.h"
#include "vde/brep/feature_edit.h"
using vde::brep::BrepModel;
using vde::core::Point3D;
using vde::core::Vector3D;
using namespace vde::brep;
namespace {
int g_pass = 0, g_fail = 0, g_unk = 0;
int g_total_checks = 0;
double g_total_ms = 0.0;
std::vector<std::string> g_fail_names;
std::string g_group_filter = "all";
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_filter == "all" || g_group_filter == g || g_group_filter == "ABCDEFGH";
}
using Ret = std::pair<bool, std::string>;
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 = {false, fmt("EXCEPTION std::exception: %s", e.what())};
} catch (...) {
r = {false, "EXCEPTION unknown"};
}
double ms = std::chrono::duration<double, std::milli>(
std::chrono::steady_clock::now() - t0).count();
g_total_ms += ms;
++g_total_checks;
if (r.first) {
++g_pass;
std::printf("[PASS] %s: %s (%.1fms)\n", name, r.second.c_str(), ms);
} else {
++g_fail;
g_fail_names.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_unk;
std::printf("[UNKNOWN] %s: %s\n", name, why.c_str());
std::fflush(stdout);
}
double relerr(double got, double exp) {
return std::abs(got - exp) / std::max(1e-12, std::abs(exp));
}
// ─────────────────────────────────────────────────────────────────────────────
// A. Constructions
// ─────────────────────────────────────────────────────────────────────────────
void groupA() {
if (!want("A")) return;
const BrepModel box = make_box(10, 10, 10);
check("construct.box.metrics", [&]() -> Ret {
auto m = analytic_measure(box);
auto v = validate(box);
bool ok = std::abs(m.volume - 1000.0) < 0.2 &&
std::abs(m.surface_area - 600.0) < 1.0 &&
box.num_faces() == 6 && box.num_edges() == 12 &&
box.num_vertices() == 8 && v.valid && v.watertightness > 0.999;
return {ok, fmt("vol=%.4f area=%.4f F/E/V=%zu/%zu/%zu valid=%d wt=%.4f euler=%d",
m.volume, m.surface_area, box.num_faces(), box.num_edges(),
box.num_vertices(), (int)v.valid, v.watertightness,
v.euler_characteristic)};
});
const int N = 64;
const BrepModel cyl = make_cylinder(10.0, 20.0, N);
const double poly_ref = 0.5 * N * 100.0 * std::sin(2.0 * M_PI / N) * 20.0;
check("construct.cylinder.volume", [&]() -> Ret {
auto m = analytic_measure(cyl);
auto v = validate(cyl);
bool ok = relerr(m.volume, poly_ref) < 0.01 && v.valid;
return {ok, fmt("vol=%.4f polyprism=%.4f rel=%.2e true_pi=%.2f faceting_err=%.2f%% F=%zu E=%zu valid=%d wt=%.4f",
m.volume, poly_ref, relerr(m.volume, poly_ref),
M_PI * 100.0 * 20.0,
100.0 * relerr(m.volume, M_PI * 100.0 * 20.0),
cyl.num_faces(), cyl.num_edges(), (int)v.valid,
v.watertightness)};
});
check("construct.cylinder.analytic_surface", [&]() -> Ret {
// VDE-1226:默认 make_cylinder(...,segments>0) 保持面片化(向后兼容);
// 解析圆柱由 segments==0 / make_cylinder_exact 提供(宿主显式 opt-in)。
auto cex = make_cylinder(8, 40, 0);
int ncyl = 0, nplane = 0, nother = 0;
for (size_t i = 0; i < cex.num_faces(); ++i) {
auto t = cex.face_type((int)i);
if (t == FaceType::Cylinder) ++ncyl;
else if (t == FaceType::Plane) ++nplane;
else ++nother;
}
int def_plane = 0;
for (size_t i = 0; i < cyl.num_faces(); ++i)
if (cyl.face_type((int)i) == FaceType::Plane) ++def_plane;
bool ok = ncyl >= 4 && cex.num_faces() <= 9;
return {ok, fmt("exact: faces=%zu cylinder=%d plane=%d other=%d (segments==0 analytic); default faceted: faces=%zu plane=%d (backward compat)",
cex.num_faces(), ncyl, nplane, nother, cyl.num_faces(), def_plane)};
});
check("construct.primitives_analytic_surfaces", [&]() -> Ret {
// VDE-1226:解析图元 = make_*_exact / segments==0(默认面片化保持兼容)
auto c = make_cylinder_exact(10, 20);
auto t = make_torus_exact(10, 2);
auto s = make_sphere(5, 16, 8);
auto k = make_cone_exact(5, 0.01, 10); // 近尖锥;r_top=0 走 256 段 faceted 回退
int cyl_t = 0, tor_t = 0, sph_t = 0, cone_t = 0, plane_t = 0, spline_t = 0;
for (auto* b : {&c, &t, &s, &k})
for (size_t i = 0; i < b->num_faces(); ++i)
switch (b->face_type((int)i)) {
case FaceType::Cylinder: ++cyl_t; break;
case FaceType::Torus: ++tor_t; break;
case FaceType::Sphere: ++sph_t; break;
case FaceType::Cone: ++cone_t; break;
case FaceType::Plane: ++plane_t; break;
default: ++spline_t; break;
}
bool ok = cyl_t >= 4 && tor_t >= 16 && sph_t > 0 && cone_t >= 4;
return {ok, fmt("exact primitives: Cylinder=%d Torus=%d Sphere=%d Cone=%d Plane=%d Spline/Other=%d",
cyl_t, tor_t, sph_t, cone_t, plane_t, spline_t)};
});
const BrepModel sph = make_sphere(5.0, 32, 16);
check("construct.sphere.metrics", [&]() -> Ret {
auto m = analytic_measure(sph);
auto v = validate(sph);
const double ev = 4.0 / 3.0 * M_PI * 125.0;
const double ea = 4.0 * M_PI * 25.0;
bool ok = relerr(m.volume, ev) < 0.005 && relerr(m.surface_area, ea) < 0.005 && v.valid;
return {ok, fmt("vol=%.4f exp=%.4f rel=%.2e area=%.4f exp=%.4f rel=%.2e F=%zu valid=%d wt=%.4f",
m.volume, ev, relerr(m.volume, ev), m.surface_area, ea,
relerr(m.surface_area, ea), sph.num_faces(), (int)v.valid,
v.watertightness)};
});
const BrepModel cone = make_cone(5.0, 0.0, 10.0, 64);
check("construct.cone.volume", [&]() -> Ret {
auto m = analytic_measure(cone);
auto v = validate(cone);
const double ev = M_PI * 25.0 * 10.0 / 3.0;
bool ok = relerr(m.volume, ev) < 0.02 && v.valid;
return {ok, fmt("vol=%.4f exp=%.4f rel=%.2e F=%zu valid=%d wt=%.4f",
m.volume, ev, relerr(m.volume, ev), cone.num_faces(),
(int)v.valid, v.watertightness)};
});
const BrepModel torus = make_torus(10.0, 2.0, 48, 24);
check("construct.torus.volume", [&]() -> Ret {
auto m = analytic_measure(torus);
auto v = validate(torus);
const double ev = 2.0 * M_PI * M_PI * 10.0 * 4.0;
bool ok = relerr(m.volume, ev) < 0.02 && v.valid;
return {ok, fmt("vol=%.4f exp=%.4f rel=%.2e F=%zu valid=%d wt=%.4f",
m.volume, ev, relerr(m.volume, ev), torus.num_faces(),
(int)v.valid, v.watertightness)};
});
check("construct.extrude.circle_exact_cylinder", [&]() -> Ret {
auto circle = vde::curves::NurbsCurve::circle(Point3D(0, 0, 0), 5.0);
auto body = extrude(circle, Vector3D(0, 0, 10));
auto m = analytic_measure(body);
const double ev = M_PI * 25.0 * 10.0;
int ncyl = 0;
for (size_t i = 0; i < body.num_faces(); ++i) {
if (body.face_type((int)i) == FaceType::Cylinder) ++ncyl;
if (!ncyl) {
auto s = ssi::surface_from_nurbs(body.face_surface((int)i));
if (s && s->kind == ssi::Kind::Cylinder) ++ncyl;
}
}
auto v = validate(body);
bool ok = relerr(m.volume, ev) < 0.005;
return {ok, fmt("vol=%.4f exp=%.4f rel=%.2e (exact rational ruled surface: no faceting) F=%zu analytic_classified_faces=%d valid=%d",
m.volume, ev, relerr(m.volume, ev), body.num_faces(), ncyl,
(int)v.valid)};
});
check("construct.revolve.square_torus", [&]() -> Ret {
std::vector<Point3D> pts = {Point3D(5, 0, 0), Point3D(8, 0, 0),
Point3D(8, 0, 10), Point3D(5, 0, 10)};
auto prof = vde::curves::NurbsCurve::closed_from_points(pts);
auto body = revolve(prof, Point3D(0, 0, 0), Vector3D(0, 0, 1), 2.0 * M_PI);
auto m = analytic_measure(body);
const double ev = 2.0 * M_PI * 6.5 * 30.0; // Pappus
bool ok = relerr(m.volume, ev) < 0.05;
return {ok, fmt("vol=%.4f Pappus=%.4f rel=%.2e F=%zu valid=%d",
m.volume, ev, relerr(m.volume, ev), body.num_faces(),
(int)validate(body).valid)};
});
check("construct.loft.circles", [&]() -> Ret {
std::vector<vde::curves::NurbsCurve> prof;
prof.push_back(vde::curves::NurbsCurve::circle(Point3D(0, 0, 0), 5.0));
prof.push_back(vde::curves::NurbsCurve::circle(Point3D(0, 0, 10), 3.0));
auto body = loft(prof);
auto m = analytic_measure(body);
const double ev = M_PI * 10.0 / 3.0 * (25.0 + 15.0 + 9.0);
bool ok = relerr(m.volume, ev) < 0.02;
return {ok, fmt("vol=%.4f exp=%.4f rel=%.2e F=%zu", m.volume, ev,
relerr(m.volume, ev), body.num_faces())};
});
check("construct.sweep.circle_line", [&]() -> Ret {
auto prof = vde::curves::NurbsCurve::circle(Point3D(0, 0, 0), 1.0);
auto path = vde::curves::NurbsCurve::line(Point3D(0, 0, 0), Point3D(0, 0, 10));
auto body = sweep(prof, path);
auto m = analytic_measure(body);
const double ev = M_PI * 1.0 * 10.0;
bool ok = relerr(m.volume, ev) < 0.02;
return {ok, fmt("vol=%.4f exp=%.4f rel=%.2e F=%zu", m.volume, ev,
relerr(m.volume, ev), body.num_faces())};
});
check("construct.make_hole.through", [&]() -> Ret {
BrepModel plate = make_box(40, 40, 20);
HoleSpec spec;
spec.standard = HoleStandard::ISO;
spec.diameter = 10.0;
spec.depth = 0.0; // through
auto body = make_hole(plate, Point3D(0, 0, 10), Vector3D(0, 0, -1), spec);
auto m = analytic_measure(body);
const double ev = 40.0 * 40.0 * 20.0 - M_PI * 25.0 * 20.0;
auto v = validate(body);
bool ok = relerr(m.volume, ev) < 0.02 && v.valid;
return {ok, fmt("vol=%.4f exp=%.4f rel=%.2e F=%zu E=%zu valid=%d wt=%.4f",
m.volume, ev, relerr(m.volume, ev), body.num_faces(),
body.num_edges(), (int)v.valid, v.watertightness)};
});
check("predicates.exact_signs", []() -> Ret {
// Phase4 task-93: internal Shewchuk adaptive predicates must be available and
// sign-exact vs integer reference on random integer inputs.
if (!vde::core::exact_predicates_available())
return {false, "internal exact predicates unavailable"};
const char* backend = vde::core::exact_predicates_backend();
const vde::core::PrecisionMode pm = vde::core::precision_mode();
if (!backend || backend[0] == '\0')
return {false, "empty exact predicate backend"};
auto sgn = [](long long v) { return v > 0 ? 1 : (v < 0 ? -1 : 0); };
long long seed = 123456789;
auto nexti = [&]() {
seed = seed * 1103515245LL + 12345LL;
return (long long)((seed >> 16) & 0x7FF) - 1024; // [-1024,1023]
};
int mismatches = 0;
for (int i = 0; i < 200; ++i) {
const long long ax = nexti(), ay = nexti(), bx = nexti(), by = nexti(),
cx = nexti(), cy = nexti(), dx = nexti(), dy = nexti();
const __int128 o2 = (__int128)(bx - ax) * (cy - ay) -
(__int128)(by - ay) * (cx - ax);
const int ref2 = o2 > 0 ? 1 : (o2 < 0 ? -1 : 0);
if (vde::core::exact_orient2d_sign((double)ax, (double)ay, (double)bx,
(double)by, (double)cx, (double)cy) != ref2)
++mismatches;
const long long az = nexti(), bz = nexti(), cz = nexti(), dz = nexti();
const __int128 ux = bx - ax, uy = by - ay, uz = bz - az;
const __int128 vx = cx - ax, vy = cy - ay, vz = cz - az;
const __int128 wx = dx - ax, wy = dy - ay, wz = dz - az;
const __int128 det3 = ux * (vy * wz - vz * wy) -
uy * (vx * wz - vz * wx) +
uz * (vx * wy - vy * wx);
const int ref3 = det3 > 0 ? 1 : (det3 < 0 ? -1 : 0);
if (vde::core::exact_orient3d_sign((double)ax, (double)ay, (double)az,
(double)bx, (double)by, (double)bz,
(double)cx, (double)cy, (double)cz,
(double)dx, (double)dy, (double)dz) != ref3)
++mismatches;
}
// fixed degenerate/circle/sphere cases
const int col = vde::core::exact_orient2d_sign(0, 0, 1, 1, 2, 2);
const int cop = vde::core::exact_orient3d_sign(0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 0);
const int circ = vde::core::exact_incircle_sign(0, 0, 1, 0, 1, 1, 0.5, 0.5);
const int sph = vde::core::exact_insphere_sign(0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1,
0.1, 0.1, 0.1);
if (col != 0 || cop != 0 || circ <= 0 || sph <= 0) ++mismatches;
return {mismatches == 0,
fmt("backend=%s mode=%d random(200x2) mismatches=%d degenerate(=%d,%d,"
"incircle=%d,insphere=%d)", backend, (int)pm, mismatches, col, cop,
circ, sph)};
});
}
// ─────────────────────────────────────────────────────────────────────────────
// B. Booleans
// ─────────────────────────────────────────────────────────────────────────────
void groupB() {
if (!want("B")) return;
const BrepModel A = make_box(10, 10, 10); // [-5,5]^3
const BrepModel B = make_box(10, 10, 10, Point3D(5, 0, 0)); // [0,10]x...
const BrepModel Bsep = make_box(10, 10, 10, Point3D(20, 0, 0));
check("boolean.union.overlap", [&]() -> Ret {
auto r = brep_union(A, B);
auto m = analytic_measure(r);
bool ok = relerr(m.volume, 1500.0) < 0.02 && r.num_faces() > 6;
return {ok, fmt("vol=%.3f exp=1500 rel=%.2e F=%zu E=%zu valid=%d",
m.volume, relerr(m.volume, 1500.0), r.num_faces(),
r.num_edges(), (int)validate(r).valid)};
});
check("boolean.intersection.overlap", [&]() -> Ret {
auto r = brep_intersection(A, B);
auto m = analytic_measure(r);
bool ok = relerr(m.volume, 500.0) < 0.02;
return {ok, fmt("vol=%.3f exp=500 rel=%.2e F=%zu", m.volume,
relerr(m.volume, 500.0), r.num_faces())};
});
check("boolean.difference.overlap", [&]() -> Ret {
auto r = brep_difference(A, B);
auto m = analytic_measure(r);
bool ok = relerr(m.volume, 500.0) < 0.02;
return {ok, fmt("vol=%.3f exp=500 rel=%.2e F=%zu", m.volume,
relerr(m.volume, 500.0), r.num_faces())};
});
check("boolean.union.separated", [&]() -> Ret {
auto r = brep_union(A, Bsep);
auto m = analytic_measure(r);
bool ok = relerr(m.volume, 2000.0) < 0.02;
return {ok, fmt("vol=%.3f exp=2000 rel=%.2e F=%zu bodies=%zu",
m.volume, relerr(m.volume, 2000.0), r.num_faces(),
r.num_bodies())};
});
check("boolean.intersection.separated_empty", [&]() -> Ret {
auto r = brep_intersection(A, Bsep);
auto m = analytic_measure(r);
bool ok = r.num_faces() == 0 || std::abs(m.volume) < 1e-6;
return {ok, fmt("vol=%.3e F=%zu (empty expected)", m.volume, r.num_faces())};
});
const BrepModel plate = make_box(40, 40, 20);
const BrepModel drill = make_cylinder(10.0, 40.0, 48);
const double exp_cut = 40.0 * 40.0 * 20.0 - M_PI * 100.0 * 20.0;
check("boolean.difference.box_cylinder", [&]() -> Ret {
auto r = brep_difference(plate, drill);
auto m = analytic_measure(r);
auto v = validate(r);
bool ok = relerr(m.volume, exp_cut) < 0.02;
return {ok, fmt("vol=%.3f exp=%.3f rel=%.2e F=%zu E=%zu valid=%d wt=%.4f",
m.volume, exp_cut, relerr(m.volume, exp_cut), r.num_faces(),
r.num_edges(), (int)v.valid, v.watertightness)};
});
check("boolean.repeat.cut_stable", [&]() -> Ret {
auto r1 = brep_difference(plate, drill);
auto r2 = brep_difference(r1, drill);
auto m1 = analytic_measure(r1);
auto m2 = analytic_measure(r2);
bool ok = relerr(m2.volume, m1.volume) < 0.02 && r2.num_faces() > 0;
return {ok, fmt("vol1=%.3f vol2=%.3f delta=%.2e F1=%zu F2=%zu",
m1.volume, m2.volume, relerr(m2.volume, m1.volume),
r1.num_faces(), r2.num_faces())};
});
check("boolean.split.box_thin_plate", [&]() -> Ret {
auto tool = make_box(0.2, 12, 12, Point3D(5, 0, 0));
auto sr = brep_split(A, tool);
double sum = 0.0;
int valid_parts = 0;
for (const auto& p : sr.parts) {
sum += analytic_measure(p).volume;
if (validate(p).valid) ++valid_parts;
}
bool ok = sr.parts.size() >= 2 && relerr(sum, 1000.0) < 0.03;
return {ok, fmt("parts=%zu vol_sum=%.3f exp=1000 rel=%.2e valid_parts=%d notes=%zu",
sr.parts.size(), sum, relerr(sum, 1000.0), valid_parts,
sr.notes.size())};
});
check("boolean.preview_undo", [&]() -> Ret {
auto prev = boolean_preview(A, B, BoolOpKind::Union);
BooleanUndoState st;
auto with = boolean_with_undo(A, B, BoolOpKind::Union, st);
auto restored = boolean_undo(st);
auto mv = analytic_measure(prev);
auto mw = analytic_measure(with);
auto mr0 = analytic_measure(restored.first);
bool ok = st.valid && relerr(mv.volume, 1500.0) < 0.02 &&
relerr(mw.volume, 1500.0) < 0.02 &&
relerr(mr0.volume, 1000.0) < 0.02;
return {ok, fmt("preview_vol=%.3f undo_vol=%.3f fused_vol=%.3f valid=%d",
mv.volume, mr0.volume, mw.volume, (int)st.valid)};
});
check("boolean.clip_by_plane", [&]() -> Ret {
auto r = clip_by_plane(A, Point3D(0, 0, 0), Vector3D(0, 0, 1), true);
auto m = analytic_measure(r);
bool ok = relerr(m.volume, 500.0) < 0.02;
return {ok, fmt("vol=%.3f exp=500 rel=%.2e F=%zu", m.volume,
relerr(m.volume, 500.0), r.num_faces())};
});
}
// ─────────────────────────────────────────────────────────────────────────────
// C. Blend / offset / shell / direct modeling
// ─────────────────────────────────────────────────────────────────────────────
void groupC() {
if (!want("C")) return;
const BrepModel box = make_box(10, 10, 10);
check("blend.fillet_single_edge", [&]() -> Ret {
auto r = fillet(box, 0, 1.0);
auto m = analytic_measure(r);
const double ev = 1000.0 - (1.0 - M_PI / 4.0) * 1.0 * 10.0;
bool ok = relerr(m.volume, ev) < 0.02 && r.num_faces() > 6;
return {ok, fmt("vol=%.3f exp=%.3f rel=%.2e F=%zu E=%zu valid=%d wt=%.4f",
m.volume, ev, relerr(m.volume, ev), r.num_faces(),
r.num_edges(), (int)validate(r).valid, validate(r).watertightness)};
});
check("blend.chamfer_single_edge", [&]() -> Ret {
auto r = chamfer(box, 0, 1.0);
auto m = analytic_measure(r);
const double ev = 1000.0 - 0.5 * 1.0 * 1.0 * 10.0;
bool ok = relerr(m.volume, ev) < 0.02 && r.num_faces() > 6;
return {ok, fmt("vol=%.3f exp=%.3f rel=%.2e F=%zu valid=%d wt=%.4f",
m.volume, ev, relerr(m.volume, ev), r.num_faces(),
(int)validate(r).valid, validate(r).watertightness)};
});
check("blend.fillet_edges_multi", [&]() -> Ret {
auto r = fillet_edges(box, {0, 1, 2, 3}, 1.0);
auto m = analytic_measure(r);
bool ok = m.volume > 0.0 && m.volume < 1000.0 && r.num_faces() > 6;
return {ok, fmt("vol=%.3f F=%zu valid=%d wt=%.4f", m.volume, r.num_faces(),
(int)validate(r).valid, validate(r).watertightness)};
});
check("blend.advanced_brep_fillet", [&]() -> Ret {
auto r = brep_fillet(box, 0, 1.0);
auto m = analytic_measure(r);
const double ev = 1000.0 - (1.0 - M_PI / 4.0) * 10.0;
bool ok = relerr(m.volume, ev) < 0.03;
return {ok, fmt("vol=%.3f exp=%.3f rel=%.2e F=%zu", m.volume, ev,
relerr(m.volume, ev), r.num_faces())};
});
check("blend.corner_blend_3_edges", [&]() -> Ret {
auto r = corner_blend(box, {0, 1, 2}, 1.0);
auto m = analytic_measure(r);
bool ok = r.num_faces() > 6 && m.volume > 900.0 && m.volume < 1000.0;
return {ok, fmt("vol=%.3f F=%zu valid=%d wt=%.4f", m.volume, r.num_faces(),
(int)validate(r).valid, validate(r).watertightness)};
});
check("shell.open_face_inward", [&]() -> Ret {
auto r = shell(box, 0, 1.0);
auto m = analytic_measure(r);
bool ok = m.volume > 350.0 && m.volume < 550.0;
return {ok, fmt("vol=%.3f exp~424 F=%zu", m.volume, r.num_faces())};
});
check("shell.closed_face", [&]() -> Ret {
auto r = shell(box, -1, 1.0);
auto m = analytic_measure(r);
bool ok = m.volume > 400.0 && m.volume < 600.0;
return {ok, fmt("vol=%.3f exp~488 F=%zu", m.volume, r.num_faces())};
});
check("offset.offset_body_outward", [&]() -> Ret {
auto r = offset_body(box, 1.0);
auto m = analytic_measure(r.body);
bool ok = r.valid && relerr(m.volume, 1728.0) < 0.02;
return {ok, fmt("valid=%d vol=%.3f exp=1728 rel=%.2e F=%zu approx_faces=%d max_verr=%.2e",
(int)r.valid, m.volume, relerr(m.volume, 1728.0),
r.body.num_faces(), r.num_approximate_faces,
r.max_vertex_error)};
});
check("offset.offset_body_inward", [&]() -> Ret {
auto r = offset_body(box, -1.0);
auto m = analytic_measure(r.body);
bool ok = r.valid && relerr(m.volume, 512.0) < 0.02;
return {ok, fmt("valid=%d vol=%.3f exp=512 rel=%.2e", (int)r.valid, m.volume,
relerr(m.volume, 512.0))};
});
check("offset.offset_body_selfintersect_detect", [&]() -> Ret {
auto r = offset_body(box, -6.0);
bool ok = !r.valid || r.self_intersecting;
return {ok, fmt("valid=%d self_intersecting=%d F=%zu (collapse expected)",
(int)r.valid, (int)r.self_intersecting, r.body.num_faces())};
});
check("draft.analyze_draft", [&]() -> Ret {
auto an = analyze_draft(box, Vector3D(0, 0, 1));
double ang = draft_angle(box, 0, Vector3D(0, 0, 1));
bool ok = an.faces.size() >= 6 && std::abs(std::abs(ang) - M_PI / 2) < 1e-3;
return {ok, fmt("faces=%zu pos=%d neg=%d zero=%d under=%d angle_bottom=%.6f rad (expect +-pi/2)",
an.faces.size(), an.positive_count, an.negative_count,
an.zero_draft_count, an.undercut_count, ang)};
});
check("draft.draft_face", [&]() -> Ret {
auto dr = draft_face(box, 5, 5.0, Vector3D(0, 0, 1));
auto m = analytic_measure(dr.body);
bool ok = dr.success && std::abs(m.volume - 1000.0) > 5.0 &&
std::abs(m.volume - 1000.0) < 100.0;
return {ok, fmt("success=%d F=%zu vol=%.3f (5deg on 10x10 side => expect ~956, delta=%.1f; 0 delta = no-op)",
(int)dr.success, dr.body.num_faces(), m.volume,
m.volume - 1000.0)};
});
check("shell.shell_offset_api", [&]() -> Ret {
auto sr = shell_offset(box, 1.0);
auto m = analytic_measure(sr.shell_body);
bool ok = sr.shell_body.num_faces() >= 6 && m.volume > 0.0;
return {ok, fmt("surfaces=%zu gaps=%zu shell_body_F=%zu vol=%.3f",
sr.offset_surfaces.size(), sr.edge_gaps.size(),
sr.shell_body.num_faces(), m.volume)};
});
check("direct.tweak_face", [&]() -> Ret {
auto r = tweak_face(box, 0, 1.0);
auto m = analytic_measure(r.body);
bool ok = r.success && relerr(m.volume, 1100.0) < 0.02;
return {ok, fmt("success=%d vol=%.3f exp=1100 rel=%.2e errs=%zu warns=%zu",
(int)r.success, m.volume, relerr(m.volume, 1100.0),
r.errors.size(), r.warnings.size())};
});
check("direct.push_pull", [&]() -> Ret {
auto r = push_pull(box, 0, 1.0);
auto m = analytic_measure(r.body);
bool ok = r.success && relerr(m.volume, 1100.0) < 0.02;
return {ok, fmt("success=%d vol=%.3f exp=1100 rel=%.2e", (int)r.success,
m.volume, relerr(m.volume, 1100.0))};
});
check("direct.offset_face", [&]() -> Ret {
auto r = offset_face(box, 0, 1.0);
auto m = analytic_measure(r.body);
bool ok = r.success && relerr(m.volume, 1100.0) < 0.02;
return {ok, fmt("success=%d vol=%.3f exp=1100 rel=%.2e", (int)r.success,
m.volume, relerr(m.volume, 1100.0))};
});
check("direct.scale_body", [&]() -> Ret {
auto r = scale_body(box, Vector3D(2, 1, 1));
auto m = analytic_measure(r.body);
bool ok = r.success && relerr(m.volume, 2000.0) < 0.02;
return {ok, fmt("success=%d vol=%.3f exp=2000 rel=%.2e", (int)r.success,
m.volume, relerr(m.volume, 2000.0))};
});
check("direct.mirror_body", [&]() -> Ret {
auto r = mirror_body(box, Point3D(0, 0, 0), Vector3D(1, 0, 0));
auto m = analytic_measure(r.body);
bool ok = r.success && relerr(m.volume, 1000.0) < 0.02;
return {ok, fmt("success=%d vol=%.3f exp=1000 rel=%.2e", (int)r.success,
m.volume, relerr(m.volume, 1000.0))};
});
check("direct.copy_face", [&]() -> Ret {
auto r = copy_face(box, 0);
bool ok = r.success && r.body.num_faces() == 1;
return {ok, fmt("success=%d F=%zu V=%zu", (int)r.success,
r.body.num_faces(), r.body.num_vertices())};
});
check("direct.delete_face_with_heal", [&]() -> Ret {
auto r = delete_face_with_heal(box, 0);
bool ok = r.body.num_faces() > 0 && r.success;
return {ok, fmt("success=%d F=%zu E=%zu errs=%zu warns=%zu",
(int)r.success, r.body.num_faces(), r.body.num_edges(),
r.errors.size(), r.warnings.size())};
});
}
// ─────────────────────────────────────────────────────────────────────────────
// D. Healing / validation / tolerance
// ─────────────────────────────────────────────────────────────────────────────
void groupD() {
if (!want("D")) return;
const BrepModel box = make_box(10, 10, 10);
const BrepModel sph = make_sphere(5.0, 24, 12);
check("validate.box_clean", [&]() -> Ret {
auto v = validate(box);
bool ok = v.valid && v.watertightness > 0.999 && v.non_manifold_edges == 0 &&
v.euler_characteristic == 2 && v.untrimmed_faces == 0;
return {ok, fmt("valid=%d wt=%.4f nm=%zu euler=%d untrimmed=%zu F=%zu E=%zu errs=%zu warns=%zu",
(int)v.valid, v.watertightness, v.non_manifold_edges,
v.euler_characteristic, v.untrimmed_faces, v.total_faces,
v.total_edges, v.errors.size(), v.warnings.size())};
});
check("validate.sphere_clean", [&]() -> Ret {
auto v = validate(sph);
bool ok = v.valid && v.watertightness > 0.99;
return {ok, fmt("valid=%d wt=%.4f F=%zu E=%zu errs=%zu warns=%zu",
(int)v.valid, v.watertightness, v.total_faces, v.total_edges,
v.errors.size(), v.warnings.size())};
});
check("validate.open_shell_detected", [&]() -> Ret {
// 真实开放壳:删除 box 一个面(shell() 修复后返回的是合法闭合杯状实体,不能用作开放壳)
auto open = delete_face(box, 0);
auto v = validate(open);
bool ok = !v.valid && v.watertightness < 1.0 && !v.errors.empty();
return {ok, fmt("valid=%d wt=%.4f dangling=%zu errs=%zu (open shell must not pass as solid)",
(int)v.valid, v.watertightness, v.dangling_edges, v.errors.size())};
});
check("heal.topology_box", [&]() -> Ret {
BrepModel copy = box;
bool okh = heal_topology(copy);
auto v = validate(copy);
bool ok = okh && v.valid && copy.num_faces() == box.num_faces();
return {ok, fmt("heal_ret=%d valid=%d F=%zu->%zu euler=%d", (int)okh,
(int)v.valid, box.num_faces(), copy.num_faces(),
v.euler_characteristic)};
});
check("heal.gaps_idempotent", [&]() -> Ret {
BrepModel copy = box;
int n = heal_gaps(copy);
int n2 = heal_gaps(copy);
bool ok = n == 0 && n2 == 0 && copy.num_vertices() == 8;
return {ok, fmt("merged=%d then=%d V=%zu", n, n2, copy.num_vertices())};
});
check("heal.slivers_none", [&]() -> Ret {
BrepModel copy = box;
int n = heal_slivers(copy);
bool ok = n == 0 && copy.num_faces() == 6;
return {ok, fmt("removed=%d F=%zu", n, copy.num_faces())};
});
check("heal.auto_pipeline", [&]() -> Ret {
BrepModel copy = box;
auto rep = auto_heal_pipeline(copy);
bool ok = rep.overall_score >= 80 && rep.successful_steps() >= 5;
return {ok, fmt("score=%d good_steps=%d fixed=%d warns=%zu", rep.overall_score,
rep.successful_steps(), rep.total_fixed(), rep.warnings.size())};
});
check("heal.diagnostics", [&]() -> Ret {
BrepModel copy = box;
auto rep = heal_diagnostics(copy);
auto v = validate(copy);
bool ok = rep.overall_score >= 0 && v.valid;
return {ok, fmt("score=%d warns=%zu valid_after=%d", rep.overall_score,
rep.warnings.size(), (int)v.valid)};
});
check("heal.gap_fill_open_sheet", [&]() -> Ret {
auto surf = vde::curves::NurbsSurface::plane(Point3D(0, 0, 0), Vector3D(1, 0, 0),
Vector3D(0, 1, 0), 10, 10);
auto sheet = vde::curves::surface_to_brep(surf);
auto rep = gap_fill(sheet, 1e-6);
bool ok = rep.holes_found >= 1 && rep.holes_filled >= 1;
return {ok, fmt("holes_found=%d holes_filled=%d new_faces=%zu warn=%zu",
rep.holes_found, rep.holes_filled, rep.filled_face_ids.size(),
rep.warnings.size())};
});
check("boolean.tolerant_union", [&]() -> Ret {
auto other = make_box(10, 10, 10, Point3D(5, 0, 0));
auto d = tolerant_boolean(box, other, 0);
auto m = analytic_measure(d.result);
bool ok = relerr(m.volume, 1500.0) < 0.03;
return {ok, fmt("success=%d vol=%.3f exp=1500 rel=%.2e failures=%zu err='%s'",
(int)d.success, m.volume, relerr(m.volume, 1500.0),
d.failed_faces.size(), d.error_message.c_str())};
});
check("tolerance.scale_and_config", [&]() -> Ret {
double mt = model_tolerance(box);
auto cfg = auto_tolerance(box);
auto g = ToleranceConfig::global();
bool ok = mt > 0.0 && mt < 1e-2 && cfg.vertex_merge > 0.0 &&
cfg.boolean > 0.0 && g.sliver_area > 0.0;
return {ok, fmt("model_tol=%.3e auto.vertex_merge=%.3e auto.boolean=%.3e global.validation=%.3e",
mt, cfg.vertex_merge, cfg.boolean, g.validation)};
});
}
// ─────────────────────────────────────────────────────────────────────────────
// E. Queries / mass properties / section
// ─────────────────────────────────────────────────────────────────────────────
void groupE() {
if (!want("E")) return;
const BrepModel box = make_box(10, 10, 10);
const BrepModel farbox = make_box(10, 10, 10, Point3D(20, 0, 0));
check("query.bounds", [&]() -> Ret {
auto bb = box.bounds();
bool ok = std::abs(bb.min().x() + 5) < 1e-9 && std::abs(bb.max().z() - 5) < 1e-9;
return {ok, fmt("min=(%.3f,%.3f,%.3f) max=(%.3f,%.3f,%.3f)",
bb.min().x(), bb.min().y(), bb.min().z(), bb.max().x(),
bb.max().y(), bb.max().z())};
});
check("query.face_edge_consistency", [&]() -> Ret {
double area = 0.0, len = 0.0;
int bad_face_edges = 0, bad_edge_faces = 0;
for (size_t i = 0; i < box.num_faces(); ++i) {
area += box.face_area((int)i);
if (box.face_edges((int)i).size() != 4) ++bad_face_edges;
}
for (size_t i = 0; i < box.num_edges(); ++i) {
len += box.edge_length((int)i);
if (box.edge_faces((int)i).size() != 2) ++bad_edge_faces;
}
bool ok = relerr(area, 600.0) < 0.005 && relerr(len, 120.0) < 1e-6 &&
bad_face_edges == 0 && bad_edge_faces == 0;
return {ok, fmt("sum_face_area=%.4f sum_edge_len=%.4f bad_face_edges=%d bad_edge_faces=%d",
area, len, bad_face_edges, bad_edge_faces)};
});
check("query.ray_cast", [&]() -> Ret {
auto hits = box.rayIntersectAll(0, 0, 20, 0, 0, -1);
bool ok = hits.size() == 2;
return {ok, fmt("hits=%zu d0=%.3f d1=%.3f (expect 2: z=5,z=-5)",
hits.size(), hits.empty() ? -1.0f : hits[0].distance,
hits.size() < 2 ? -1.0f : hits[1].distance)};
});
check("query.point_classification", [&]() -> Ret {
int up = 0;
auto in = classify_point_adaptive(box, Point3D(0, 0, 0), up);
int up2 = 0;
auto out = classify_point_adaptive(box, Point3D(20, 0, 0), up2);
bool ok = in == IN && out == OUT;
return {ok, fmt("center=%d (IN=-1) outside=%d (OUT=1) upgrades=%d/%d",
(int)in, (int)out, up, up2)};
});
check("query.mass_properties", [&]() -> Ret {
auto mp = mass_properties(box);
const double eye = 1000.0 / 12.0 * 200.0; // m/12*(h^2+d^2)
bool ok = relerr(mp.volume, 1000.0) < 0.02 &&
mp.centroid.norm() < 0.05 &&
std::abs(mp.inertia(0, 0) - eye) / eye < 0.03;
return {ok, fmt("vol=%.3f centroid=(%.4f,%.4f,%.4f) Ixx=%.2f exp=%.2f rel=%.2e",
mp.volume, mp.centroid.x(), mp.centroid.y(), mp.centroid.z(),
mp.inertia(0, 0), eye,
std::abs(mp.inertia(0, 0) - eye) / eye)};
});
check("query.analytic_measure", [&]() -> Ret {
auto m = analytic_measure(box);
bool ok = std::abs(m.volume - 1000.0) < 0.2 &&
std::abs(m.surface_area - 600.0) < 1.0 && m.capped_faces == 0;
return {ok, fmt("vol=%.4f area=%.4f evals=%lld capped=%d", m.volume,
m.surface_area, m.evals, m.capped_faces)};
});
check("query.centroid_offset_body", [&]() -> Ret {
BrepModel moved = make_box(10, 10, 10, Point3D(10, 0, 0));
auto c = centroid(moved);
bool ok = std::abs(c.x() - 10.0) < 0.1 && std::abs(c.y()) < 0.1;
return {ok, fmt("centroid=(%.4f,%.4f,%.4f) expect (10,0,0)", c.x(), c.y(), c.z())};
});
check("query.section_plane_and_properties", [&]() -> Ret {
auto curves = section_plane(box, Point3D(0, 0, 0), Vector3D(0, 0, 1));
double area = -1.0;
if (!curves.empty()) area = section_properties(curves[0]).area;
bool ok = !curves.empty() && relerr(area, 100.0) < 0.02;
return {ok, fmt("curves=%zu area=%.4f exp=100 rel=%.2e", curves.size(), area,
curves.empty() ? -1.0 : relerr(area, 100.0))};
});
check("query.section_clip_body", [&]() -> Ret {
auto clipped = clip_body(box, Point3D(0, 0, 0), Vector3D(0, 0, 1), true);
auto m = analytic_measure(clipped);
bool ok = relerr(m.volume, 500.0) < 0.03;
return {ok, fmt("vol=%.3f exp=500 rel=%.2e F=%zu", m.volume,
relerr(m.volume, 500.0), clipped.num_faces())};
});
check("query.distance_clearance", [&]() -> Ret {
double cl = clearance(box, farbox);
double d = distance(box, farbox);
bool ok = std::abs(cl - 10.0) < 0.2 && std::abs(d - 10.0) < 0.2;
return {ok, fmt("clearance=%.3f distance=%.3f exp=10", cl, d)};
});
check("query.wall_thickness", [&]() -> Ret {
auto wt = analyze_wall_thickness(box, 3, false);
bool ok = std::abs(wt.min_thickness - 10.0) < 1.0 &&
std::abs(wt.max_thickness - 10.0) < 1.0;
return {ok, fmt("min=%.3f max=%.3f avg=%.3f exp=10", wt.min_thickness,
wt.max_thickness, wt.avg_thickness)};
});
check("query.fit_circle_3_points", [&]() -> Ret {
auto r = fit_circle_3_points(Point3D(5, 0, 0), Point3D(0, 5, 0),
Point3D(-5, 0, 0));
bool ok = r.valid && std::abs(r.radius - 5.0) < 1e-6;
return {ok, fmt("valid=%d r=%.6f center=(%.3f,%.3f,%.3f)", (int)r.valid,
r.radius, r.center.x(), r.center.y(), r.center.z())};
});
}
// ─────────────────────────────────────────────────────────────────────────────
// F. NURBS <-> B-Rep conversion / tessellation
// ─────────────────────────────────────────────────────────────────────────────
void groupF() {
if (!want("F")) return;
check("convert.surface_to_brep_plane", [&]() -> Ret {
auto surf = vde::curves::NurbsSurface::plane(Point3D(0, 0, 0), Vector3D(1, 0, 0),
Vector3D(0, 1, 0), 10, 10);
auto body = vde::curves::surface_to_brep(surf);
auto m = analytic_measure(body);
bool ok = body.num_faces() == 1 && body.num_edges() == 4 &&
body.num_vertices() == 4 && relerr(m.surface_area, 100.0) < 0.01;
return {ok, fmt("F/E/V=%zu/%zu/%zu area=%.4f exp=100", body.num_faces(),
body.num_edges(), body.num_vertices(), m.surface_area)};
});
check("convert.nurbs_surface_to_body", [&]() -> Ret {
auto surf = vde::curves::NurbsSurface::plane(Point3D(0, 0, 0), Vector3D(1, 0, 0),
Vector3D(0, 1, 0), 10, 10);
auto body = nurbs_surface_to_body(surf);
auto m = analytic_measure(body);
bool ok = body.num_faces() == 1 && relerr(m.surface_area, 100.0) < 0.01;
return {ok, fmt("F=%zu area=%.4f exp=100", body.num_faces(), m.surface_area)};
});
check("convert.nurbs_surfaces_to_body", [&]() -> Ret {
auto s1 = vde::curves::NurbsSurface::plane(Point3D(0, 0, 0), Vector3D(1, 0, 0),
Vector3D(0, 1, 0), 5, 10);
auto s2 = vde::curves::NurbsSurface::plane(Point3D(5, 0, 0), Vector3D(1, 0, 0),
Vector3D(0, 1, 0), 5, 10);
auto body = nurbs_surfaces_to_body({s1, s2});
auto m = analytic_measure(body);
bool ok = body.num_faces() == 2 && relerr(m.surface_area, 100.0) < 0.02;
return {ok, fmt("F=%zu area=%.4f exp=100", body.num_faces(), m.surface_area)};
});
check("convert.thicken_surface", [&]() -> Ret {
auto surf = vde::curves::NurbsSurface::plane(Point3D(0, 0, 0), Vector3D(1, 0, 0),
Vector3D(0, 1, 0), 10, 10);
auto solid = vde::curves::thicken_surface(surf, 2.0);
auto m = analytic_measure(solid);
bool ok = relerr(m.volume, 200.0) < 0.03;
return {ok, fmt("vol=%.3f exp=200 rel=%.2e F=%zu", m.volume,
relerr(m.volume, 200.0), solid.num_faces())};
});
check("tessellate.box_quality", [&]() -> Ret {
auto box = make_box(10, 10, 10);
auto mesh = box.to_mesh(0.05);
auto q = box.quality_report(mesh);
bool ok = q.num_triangles == 12 && q.degenerate_tris == 0 &&
std::abs(q.min_area - 50.0) < 1e-6;
return {ok, fmt("tris=%d min_area=%.1f max_area=%.1f degen=%d", q.num_triangles,
q.min_area, q.max_area, q.degenerate_tris)};
});
check("tessellate.mesh_watertight_metric", [&]() -> Ret {
auto box = make_box(10, 10, 10);
auto mesh = box.to_mesh(0.05);
auto q = box.quality_report(mesh);
// to_mesh 按面独立输出顶点(渲染用),因此先用位置量化统计"焊接后"顶点数;
// 水密性以 quality_report(按位置焊接后判定)为准。
std::vector<std::array<long long, 3>> uniq;
uniq.reserve(mesh.num_vertices());
for (size_t i = 0; i < mesh.num_vertices(); ++i) {
const auto& p = mesh.vertex(i);
std::array<long long, 3> key{llround(p.x() * 1e6), llround(p.y() * 1e6), llround(p.z() * 1e6)};
if (std::find(uniq.begin(), uniq.end(), key) == uniq.end()) uniq.push_back(key);
}
const size_t welded_verts = uniq.size();
bool ok = q.is_watertight && welded_verts == 8 && q.num_triangles == 12 &&
q.chord_error_max < 1e-9;
return {ok, fmt("raw_verts=%zu welded=%zu tris=%d is_watertight=%d chord_max=%.3e chord_rms=%.3e",
mesh.num_vertices(), welded_verts, q.num_triangles,
(int)q.is_watertight, q.chord_error_max, q.chord_error_rms)};
});
check("tessellate.adaptive_sphere", [&]() -> Ret {
auto sph = make_sphere(5.0, 24, 12);
auto mesh = sph.to_mesh_adaptive(0.01);
auto q = sph.quality_report(mesh);
// VDE-1226/P1 修后:按 3D 弦高自适应(不再按参数密度 100 细分)、极点退化行合并。
bool ok = q.num_triangles > 1000 && q.num_triangles < 200000 &&
q.degenerate_tris == 0 && q.is_watertight;
return {ok, fmt("tris=%d verts=%zu degen=%d is_watertight=%d", q.num_triangles,
mesh.num_vertices(), q.degenerate_tris, (int)q.is_watertight)};
});
check("convert.mesh_to_brep_roundtrip", [&]() -> Ret {
auto box = make_box(10, 10, 10);
auto mesh = box.to_mesh(0.1);
auto body = mesh_to_brep_model(mesh);
auto m = analytic_measure(body);
bool ok = relerr(m.volume, 1000.0) < 0.05 && body.num_faces() > 0;
return {ok, fmt("vol=%.3f exp=1000 rel=%.2e F=%zu E=%zu", m.volume,
relerr(m.volume, 1000.0), body.num_faces(), body.num_edges())};
});
check("query.face_types_box", [&]() -> Ret {
auto box = make_box(10, 10, 10);
int planes = 0;
for (size_t i = 0; i < box.num_faces(); ++i)
if (box.face_type((int)i) == FaceType::Plane) ++planes;
bool ok = planes == 6;
return {ok, fmt("plane_faces=%d/6", planes)};
});
}
// ─────────────────────────────────────────────────────────────────────────────
// G. SSI + SSI booleans
// ─────────────────────────────────────────────────────────────────────────────
void groupG() {
if (!want("G")) return;
check("ssi.analytic_plane_sphere", [&]() -> Ret {
ssi::Surface pl;
pl.kind = ssi::Kind::Plane;
pl.o = Point3D(0, 0, 0);
pl.z = Vector3D(0, 0, 1);
ssi::Surface sp;
sp.kind = ssi::Kind::Sphere;
sp.o = Point3D(0, 0, 0);
sp.z = Vector3D(0, 0, 1);
sp.r1 = 5.0;
auto tr = ssi::trace_intersection(pl, sp, Point3D(-6, -6, -1), Point3D(6, 6, 1));
double maxdev = 0.0;
size_t npts = 0;
for (const auto& poly : tr.polylines)
for (const auto& p : poly) {
maxdev = std::max(maxdev, std::abs(p.norm() - 5.0));
++npts;
}
bool ok = !tr.polylines.empty() && npts > 4 && maxdev < 1e-3;
return {ok, fmt("curves=%zu pts=%zu max_radius_dev=%.3e degenerate=%d",
tr.polylines.size(), npts, maxdev, (int)tr.degenerate)};
});
check("ssi.analytic_plane_cylinder", [&]() -> Ret {
ssi::Surface pl;
pl.kind = ssi::Kind::Plane;
pl.o = Point3D(0, 0, 0);
pl.z = Vector3D(0, 0, 1);
ssi::Surface cy;
cy.kind = ssi::Kind::Cylinder;
cy.o = Point3D(0, 0, 0);
cy.z = Vector3D(0, 0, 1);
cy.r1 = 10.0;
auto tr = ssi::trace_intersection(pl, cy, Point3D(-12, -12, -1), Point3D(12, 12, 1));
double maxdev = 0.0;
size_t npts = 0;
for (const auto& poly : tr.polylines)
for (const auto& p : poly) {
maxdev = std::max(maxdev, std::abs(std::hypot(p.x(), p.y()) - 10.0));
++npts;
}
bool ok = !tr.polylines.empty() && npts > 4 && maxdev < 1e-3;
return {ok, fmt("curves=%zu pts=%zu max_radius_dev=%.3e", tr.polylines.size(),
npts, maxdev)};
});
const BrepModel A = make_box(10, 10, 10);
const BrepModel B = make_box(10, 10, 10, Point3D(5, 0, 0));
check("ssi.boolean_union_boxes", [&]() -> Ret {
auto r = ssi_boolean_union(A, B);
auto m = analytic_measure(r.result);
bool ok = r.error_message.empty() && relerr(m.volume, 1500.0) < 0.02;
return {ok, fmt("vol=%.3f exp=1500 rel=%.2e F=%zu err='%s' ssi_curves=%d kept=%d time=%.1fms",
m.volume, relerr(m.volume, 1500.0), r.result.num_faces(),
r.error_message.c_str(), r.num_ssi_curves, r.num_kept,
r.total_time_ms())};
});
check("ssi.boolean_intersection_boxes", [&]() -> Ret {
auto r = ssi_boolean_intersection(A, B);
auto m = analytic_measure(r.result);
bool ok = relerr(m.volume, 500.0) < 0.02;
return {ok, fmt("vol=%.3f exp=500 rel=%.2e F=%zu err='%s'",
m.volume, relerr(m.volume, 500.0), r.result.num_faces(),
r.error_message.c_str())};
});
check("ssi.boolean_difference_box_cylinder", [&]() -> Ret {
auto plate = make_box(40, 40, 20);
auto drill = make_cylinder(10.0, 40.0, 48);
auto r = ssi_boolean_difference(plate, drill);
auto m = analytic_measure(r.result);
const double ev = 40.0 * 40.0 * 20.0 - M_PI * 100.0 * 20.0;
bool ok = relerr(m.volume, ev) < 0.02;
return {ok, fmt("vol=%.3f exp=%.3f rel=%.2e F=%zu err='%s'",
m.volume, ev, relerr(m.volume, ev), r.result.num_faces(),
r.error_message.c_str())};
});
check("boolean.fallback_ladder", [&]() -> Ret {
auto r = brep_boolean_robust(A, B, FallbackBoolOp::Union);
double vol = -1.0;
if (r.brep_body) vol = analytic_measure(*r.brep_body).volume;
bool ok = r.success() && r.final_level >= 1 && r.final_level <= 4 &&
(!r.brep_body || relerr(vol, 1500.0) < 0.03);
return {ok, fmt("final_level=%d brep_quality=%d levels_tried=%zu vol_brep=%.3f mesh_verts=%zu err='%s'",
r.final_level, (int)r.brep_quality, r.levels_tried.size(), vol,
r.result_body.num_vertices(),
r.diagnostic.error_message.c_str())};
});
}
// ─────────────────────────────────────────────────────────────────────────────
// H. Feature / recognition / trimmed surface
// ─────────────────────────────────────────────────────────────────────────────
void groupH() {
if (!want("H")) return;
check("feature.tree_primitive_box", [&]() -> Ret {
FeatureNode n;
n.type = FeatureType::PrimitiveBox;
n.params.values = {10.0, 10.0, 10.0};
auto body = n.evaluate();
auto m = analytic_measure(body);
bool ok = relerr(m.volume, 1000.0) < 0.02;
return {ok, fmt("vol=%.3f F=%zu", m.volume, body.num_faces())};
});
check("feature.tree_parameter_expression", [&]() -> Ret {
ParameterTable pt;
pt.set("width", 10.0);
pt.set("height", 20.0);
double simple = pt.evaluate_expression("width * 2");
double compound = pt.evaluate_expression("width * 2 + height");
bool ok = std::abs(simple - 20.0) < 1e-9 && std::abs(compound - 40.0) < 1e-9;
return {ok, fmt("'width * 2'=%.3f (exp 20) 'width * 2 + height'=%.3f (exp 40) size=%zu [evaluator only resolves bare names/literals]",
simple, compound, pt.size())};
});
check("trimmed_surface.mass_integral", [&]() -> Ret {
auto surf = vde::curves::NurbsSurface::plane(Point3D(0, 0, 0), Vector3D(1, 0, 0),
Vector3D(0, 1, 0), 10, 10);
auto ts = TrimmedSurface::from_rect(surf, 0.0, 1.0, 0.0, 1.0);
auto mi = ts.mass_integral(0.01);
bool ok = relerr(mi.area, 100.0) < 0.01;
return {ok, fmt("area=%.4f exp=100 evals=%lld capped=%d", mi.area, mi.evals,
(int)mi.capped)};
});
// VDE-1223 修复后:recognize_features 可安全探测(普通圆柱 0 假特征 + make_hole 通孔 1 孔)
check("feature.recognize_features", [&]() -> Ret {
auto cyl = make_cylinder(8, 40, 32);
auto fc = recognize_features(cyl);
const int fake = static_cast<int>(fc.features.size());
HoleSpec spec;
spec.diameter = 6.0;
spec.depth = 0.0;
auto plate = make_box(60, 60, 20);
auto holed = make_hole(plate, Point3D(0, 0, 10), Vector3D(0, 0, -1), spec);
auto fh = recognize_features(holed);
bool ok = fake == 0 && fh.hole_count == 1 &&
(!fh.features.empty() && fh.features.front().type == RecognizedFeatureType::Hole);
return {ok, fmt("cylinder: fake=%d (expect 0); make_hole: features=%zu holes=%d (expect hole 1)",
fake, fh.features.size(), fh.hole_count)};
});
check("feature.edit_feature", [&]() -> Ret {
HoleSpec spec;
spec.diameter = 6.0;
spec.depth = 0.0;
auto plate = make_box(60, 60, 20);
auto holed = make_hole(plate, Point3D(0, 0, 10), Vector3D(0, 0, -1), spec);
auto feats = recognize_features(holed);
if (feats.features.empty()) return {false, "recognize_features returned no hole on make_hole model"};
const double v0 = holed.body_volume();
FeatureEditParams p;
p.radius = 4.0; // 原 r=3 → r=4,体积应减小
auto r = edit_feature(holed, feats.features.front(), p);
bool ok = r.success && r.body.num_faces() > 0 && r.body.is_valid() &&
r.body.body_volume() < v0;
return {ok, fmt("success=%d F=%zu vol %.1f -> %.1f valid=%d errs=%zu",
(int)r.success, r.body.num_faces(), v0, r.body.body_volume(),
(int)r.body.is_valid(), r.errors.size())};
});
check("construct.make_hole.standard_tapped", [&]() -> Ret {
auto plate = make_box(60, 60, 20);
HoleSpec spec;
spec.diameter = 6.0;
spec.depth = 0.0;
spec.tapped = true;
spec.thread_pitch = 1.0;
auto body = make_hole(plate, Point3D(0, 0, 10), Vector3D(0, 0, -1), spec);
const auto v = validate(body);
const double v0 = plate.body_volume();
bool ok = body.num_faces() > 0 && v.valid && v.watertightness >= 0.999 &&
body.body_volume() < v0;
return {ok, fmt("tapped: F=%zu valid=%d wt=%.4f vol=%.1f < plate=%.1f",
body.num_faces(), (int)v.valid, v.watertightness,
body.body_volume(), v0)};
});
check("blend.corner_blend_4plus_edge", [&]() -> Ret {
auto box = make_box(10, 10, 10);
std::vector<BlendNetworkEdge> es;
es.reserve(box.num_edges());
for (size_t e = 0; e < box.num_edges(); ++e)
es.push_back({static_cast<int>(e), 2.0, 2.0});
auto r = blend_network_solve(box, es);
const auto v = validate(r.body);
bool ok = r.success && v.valid && v.watertightness >= 0.999;
return {ok, fmt("12-edge network: success=%d F=%zu valid=%d wt=%.4f conflicts=%zu",
(int)r.success, r.body.num_faces(), (int)v.valid,
v.watertightness, r.conflicts.size())};
});
check("brep_heal.fill_holes", [&]() -> Ret {
// 独立 gap_fill 能力见 heal.gap_fill_open_sheet;此处验证 heal 流水线在封闭体上不破坏水密。
auto box = make_box(10, 10, 10);
auto healed = box;
bool ok = heal_topology(healed);
const auto v = validate(healed);
bool pass = ok && v.valid && v.watertightness >= 0.999;
return {pass, fmt("heal_topology(box): ok=%d valid=%d wt=%.4f (standalone gap_fill probed by heal.gap_fill_open_sheet)",
(int)ok, (int)v.valid, v.watertightness)};
});
}
// ─────────────────────────────────────────────────────────────────────────────
// ───────────────────────────────────────────────────────────────────────────
// J. Wave3-C7b 新 API 实测(不受 ABCD... 分组影响;默认 all 跑,或用 J 单独跑)
// ───────────────────────────────────────────────────────────────────────────
namespace {
vde::fs::path audit_tmp(const char* name) {
auto dir = vde::fs::temp_directory_path() / "vde_audit_brep";
vde::fs::create_directories(dir);
return dir / name;
}
void audit_rm(const vde::fs::path& p) {
std::error_code ec;
vde::fs::remove(p, ec);
}
int top_face_id(const BrepModel& b) {
int best = -1;
double bestz = -1e300;
for (size_t i = 0; i < b.num_faces(); ++i) {
const double z = b.face_center((int)i).z();
if (z > bestz) {
bestz = z;
best = (int)i;
}
}
return best;
}
BrepModel make_dirty_dup_face_box() {
BrepModel box = make_box(10, 10, 10);
const auto& f = box.face(1);
const int lid = box.add_loop(box.loop_by_id(f.loops[0]).edges, true);
box.add_face(box.face(1).surface_id, {lid});
return box;
}
} // namespace
void groupJ() {
if (!want("J")) return;
// B-2:push_pull_draft 解析圆锥台体积(圆柱顶盖 r=10 收锥,α=10°,h=5)
check("b2.push_pull_draft_cone", [&]() -> Ret {
const BrepModel cyl = make_cylinder(10.0, 20.0, 0);
const int top = top_face_id(cyl);
const double h = 5.0;
const double alpha = 10.0 * M_PI / 180.0;
const double r0 = 10.0;
const double r1 = r0 - h * std::tan(alpha);
const double base = M_PI * r0 * r0 * 20.0;
const double ev = base + M_PI * h / 3.0 * (r0 * r0 + r0 * r1 + r1 * r1);
auto r = push_pull_draft(cyl, top, h, 10.0);
const double v = analytic_measure(r.body).volume;
const bool ok = r.success && relerr(v, ev) < 1e-3 && validate(r.body).valid;
return {ok, fmt("top=%d success=%d vol=%.4f exp=%.4f rel=%.2e faces=%zu valid=%d",
top, (int)r.success, v, ev, relerr(v, ev), r.body.num_faces(),
(int)validate(r.body).valid)};
});
// B-2:offset_face 解析面等距(平面盒 → 体积精确 +100)
check("b2.offset_face_analytic", [&]() -> Ret {
auto r = offset_face(make_box(10, 10, 10), 0, 1.0);
const double v = analytic_measure(r.body).volume;
const bool ok = r.success && relerr(v, 1100.0) < 1e-6 && validate(r.body).valid;
return {ok, fmt("success=%d vol=%.6f exp=1100 rel=%.2e valid=%d",
(int)r.success, v, relerr(v, 1100.0),
(int)validate(r.body).valid)};
});
// B-1:heal_with_rules 脏模型(重复面)→ 合法 + 体积复原 + 规则计数
check("b1.heal_with_rules_duplicate_face", [&]() -> Ret {
auto dirty = make_dirty_dup_face_box();
HealRuleDiagnostics d;
(void)heal_with_rules(dirty, HealRuleOptions{}, &d);
const double v = analytic_measure(dirty).volume;
const auto vr = validate(dirty);
const bool ok = vr.valid && relerr(v, 1000.0) < 1e-3 &&
d.duplicate_faces_removed >= 1;
return {ok, fmt("valid=%d wt=%.4f vol=%.4f rel=%.2e dup_removed=%d "
"nonmanifold_removed=%d",
(int)vr.valid, vr.watertightness, v, relerr(v, 1000.0),
d.duplicate_faces_removed, d.nonmanifold_faces_removed)};
});
// A-10:.vde 二进制往返(V1 几何段)
check("a10.vde_roundtrip", [&]() -> Ret {
const auto p = audit_tmp("audit_box.vde");
const BrepModel box = make_box(10, 10, 10);
bool saved = vde::foundation::save_vde(box, p.string());
bool threw = false;
BrepModel loaded;
try {
loaded = vde::foundation::load_vde(p.string());
} catch (...) {
threw = true;
}
std::error_code ec;
const auto sz = vde::fs::file_size(p, ec);
audit_rm(p);
const double v = analytic_measure(loaded).volume;
const bool ok = saved && !threw && loaded.num_faces() == box.num_faces() &&
relerr(v, 1000.0) < 1e-9 && validate(loaded).valid;
return {ok, fmt("saved=%d threw=%d file=%lluB faces=%zu vol=%.6f rel=%.2e valid=%d",
(int)saved, (int)threw, (unsigned long long)sz,
loaded.num_faces(), v, relerr(v, 1000.0),
(int)validate(loaded).valid)};
});
// A-10:V1 规范冻结(serialize → validate_vde_data:magic/version/段边界/错误码)
check("a10.vde_validate_v1", [&]() -> Ret {
const auto bytes = vde::foundation::serialize_vde(make_box(10, 10, 10));
const auto chk = vde::foundation::validate_vde_data(bytes);
const bool ok = chk.valid && chk.magic_ok && chk.version_ok &&
chk.error_code == vde::foundation::VdeErrorCode::Ok;
return {ok, fmt("valid=%d magic_ok=%d version=%u version_ok=%d err=%u sections=%zu "
"bytes=%zu",
(int)chk.valid, (int)chk.magic_ok, chk.version,
(int)chk.version_ok, (unsigned)chk.error_code, chk.sections.size(),
bytes.size())};
});
// A-10:V6 JSON 伴生文件
check("a10.vde_json_companion", [&]() -> Ret {
const auto p = audit_tmp("audit_box.vde.json");
audit_rm(p);
const bool saved = vde::foundation::save_vde_json(make_box(10, 10, 10), p.string());
std::error_code ec;
const auto sz = vde::fs::file_size(p, ec);
audit_rm(p);
return {saved && sz > 100, fmt("saved=%d json_size=%lluB", (int)saved,
(unsigned long long)sz)};
});
// B-3:1000 件装配级 fuse_all 短场景(2³ 立方 ×1000,间距 3 → 实体分离但一次批量)
check("b3.fuse_all_1000_parts", [&]() -> Ret {
std::vector<BrepModel> parts;
parts.reserve(1000);
for (int i = 0; i < 1000; ++i)
parts.push_back(make_box(2, 2, 2, Point3D(static_cast<double>(i) * 3.0, 0, 0)));
const auto t0 = std::chrono::steady_clock::now();
const BrepModel fused = fuse_all(parts);
const double ms = std::chrono::duration<double, std::milli>(
std::chrono::steady_clock::now() - t0)
.count();
const double v = analytic_measure(fused).volume;
const bool ok = fused.num_faces() > 0 && relerr(v, 8000.0) < 1e-3;
return {ok, fmt("parts=1000 faces=%zu vol=%.3f exp=8000 rel=%.2e ms=%.0f valid=%d",
fused.num_faces(), v, relerr(v, 8000.0), ms,
(int)validate(fused).valid)};
});
// B-4:A 级曲面多 patch 拼接连续性(两平面 patch 共享边 → G0/G1 连续)
check("b4.patch_continuity_g1", [&]() -> Ret {
auto s0 = vde::curves::NurbsSurface::plane(Point3D(0, 0, 0), Vector3D(1, 0, 0),
Vector3D(0, 1, 0), 10.0, 10.0);
auto s1 = vde::curves::NurbsSurface::plane(Point3D(10, 0, 0), Vector3D(1, 0, 0),
Vector3D(0, 1, 0), 10.0, 10.0);
const auto rep = vde::curves::multi_surface_diagnosis({s0, s1}, {{0, 1}});
if (rep.boundaries.empty())
return {false, "no boundary continuity pair detected"};
const auto& b = rep.boundaries[0];
const bool ok = b.has_common_edge && b.g0_ok && b.g1_ok;
return {ok, fmt("patches=%d boundaries=%zu common=%d g0_err=%.2e g1_err=%.2e "
"g0_ok=%d g1_ok=%d",
rep.num_patches, rep.boundaries.size(),
(int)b.has_common_edge, b.g0_error, b.g1_error, (int)b.g0_ok,
(int)b.g1_ok)};
});
// A-5b:凸台特征编辑解析体积(box20³? 4000 + 凸台 πr²h;识別 radius/depth 后 depth+2)
check("a5b.boss_feature_edit_analytic", [&]() -> Ret {
const BrepModel box = make_box(20, 20, 10); // 4000
const BrepModel boss = make_cylinder(3.0, 6.0, 0, Point3D(0, 0, 7.0)); // z=4..10
const BrepModel body = brep_union(box, boss);
const auto feats = recognize_features(body);
if (feats.boss_count < 1)
return {false, fmt("boss feature not recognized (features=%zu boss=%d)",
feats.features.size(), feats.boss_count)};
const RecognizedFeature& bf = feats.features.front();
const double new_depth = bf.depth + 2.0;
const auto er = edit_feature(body, bf, FeatureEditParams{0.0, new_depth, 0.0});
const double ev = 4000.0 + M_PI * bf.radius * bf.radius * new_depth;
const double v = analytic_measure(er.body).volume;
const bool ok = er.success && validate(er.body).valid &&
relerr(v, ev) < 1e-6;
return {ok, fmt("boss r=%.6f depth=%.3f->%.3f success=%d vol=%.6f exp=%.6f "
"rel=%.2e valid=%d",
bf.radius, bf.depth, new_depth, (int)er.success, v, ev,
relerr(v, ev), (int)validate(er.body).valid)};
});
// A-12:loft/sweep F 与体积 rel(严格 5e-3;面数由建模契约决定)
check("a12.loft_sweep_faces_volume", [&]() -> Ret {
std::vector<vde::curves::NurbsCurve> prof;
prof.push_back(vde::curves::NurbsCurve::circle(Point3D(0, 0, 0), 5.0));
prof.push_back(vde::curves::NurbsCurve::circle(Point3D(0, 0, 10), 3.0));
const BrepModel lf = loft(prof);
const double evl = M_PI * 10.0 / 3.0 * (25.0 + 15.0 + 9.0);
auto swp_prof = vde::curves::NurbsCurve::circle(Point3D(0, 0, 0), 1.0);
auto path = vde::curves::NurbsCurve::line(Point3D(0, 0, 0), Point3D(0, 0, 10));
const BrepModel sw = sweep(swp_prof, path);
const double evs = M_PI * 10.0;
const double vl = analytic_measure(lf).volume;
const double vs = analytic_measure(sw).volume;
const bool ok = lf.num_faces() > 0 && sw.num_faces() > 0 &&
relerr(vl, evl) < 5e-3 && relerr(vs, evs) < 5e-3;
return {ok, fmt("loft F=%zu rel=%.2e | sweep F=%zu rel=%.2e", lf.num_faces(),
relerr(vl, evl), sw.num_faces(), relerr(vs, evs))};
});
// B-6:特征编辑冲突/非法输入 5/5 诚实拒绝(不崩、不静默产出脏体)
check("b6.feature_edit_conflict_reject_5of5", [&]() -> Ret {
const BrepModel box = make_box(10, 10, 10);
int rejected = 0, total = 0;
auto reject = [&](const RecognizedFeature& f, const FeatureEditParams& p) {
++total;
DirectModelingResult r;
try {
r = edit_feature(box, f, p);
} catch (...) {
++rejected;
return;
}
if (!r.success) ++rejected;
};
reject(RecognizedFeature{}, FeatureEditParams{});
RecognizedFeature f2;
f2.type = RecognizedFeatureType::Hole;
f2.radius = -1.0;
f2.depth = -1.0;
reject(f2, FeatureEditParams{});
RecognizedFeature f3;
f3.type = RecognizedFeatureType::Boss;
f3.face_ids = {99};
f3.depth = -5.0;
reject(f3, FeatureEditParams{});
RecognizedFeature f4;
f4.type = RecognizedFeatureType::Fillet;
f4.radius = -2.0;
reject(f4, FeatureEditParams{});
RecognizedFeature f5;
f5.type = RecognizedFeatureType::Chamfer;
f5.face_ids = {-1, 12345};
reject(f5, FeatureEditParams{});
return {rejected == 5 && total == 5,
fmt("invalid/conflicting edits rejected %d/%d", rejected, total)};
});
}
// I. Diagnostics (cross-check analytic_measure vs mesh volume; never asserts)
// ─────────────────────────────────────────────────────────────────────────────
namespace diag {
double mesh_volume(const vde::mesh::HalfedgeMesh& mesh) {
double sum = 0.0;
for (size_t fi = 0; fi < mesh.num_faces(); ++fi) {
auto fv = mesh.face_vertices((int)fi);
if (fv.size() < 3) continue;
for (size_t k = 1; k + 1 < fv.size(); ++k) {
const Point3D& a = mesh.vertex(fv[0]);
const Point3D& b = mesh.vertex(fv[k]);
const Point3D& c = mesh.vertex(fv[k + 1]);
sum += a.dot(b.cross(c));
}
}
return std::abs(sum) / 6.0;
}
Ret dump(const char* tag, const BrepModel& b) {
auto am = analytic_measure(b);
auto mesh = b.to_mesh(0.05);
double mv = mesh_volume(mesh);
auto v = validate(b);
int emptyLoops = 0, totalFaces = 0;
for (const auto& f : b.all_faces()) {
++totalFaces;
if (f.loops.empty()) ++emptyLoops;
}
return {true, fmt("[%s] analytic_vol=%.3f analytic_area=%.3f mesh_vol=%.3f F=%zu E=%zu V=%zu empty_loop_faces=%d valid=%d wt=%.4f euler=%d errs=%zu warns=%zu",
tag, am.volume, am.surface_area, mv, b.num_faces(), b.num_edges(),
b.num_vertices(), emptyLoops, (int)v.valid, v.watertightness,
v.euler_characteristic, v.errors.size(), v.warnings.size())};
}
} // namespace diag
void groupI() {
if (!want("I")) return;
const BrepModel A = make_box(10, 10, 10);
const BrepModel B = make_box(10, 10, 10, Point3D(5, 0, 0));
check("diag.legacy_union", [&]() -> Ret { return diag::dump("union", brep_union(A, B)); });
check("diag.legacy_intersection", [&]() -> Ret { return diag::dump("inter", brep_intersection(A, B)); });
check("diag.legacy_difference", [&]() -> Ret { return diag::dump("diff", brep_difference(A, B)); });
check("diag.ssi_difference_plate_drill", [&]() -> Ret {
return diag::dump("ssi-diff", ssi_boolean_difference(make_box(40, 40, 20),
make_cylinder(10.0, 40.0, 48)).result);
});
check("diag.fillet", [&]() -> Ret { return diag::dump("fillet", fillet(A, 0, 1.0)); });
check("diag.chamfer", [&]() -> Ret { return diag::dump("chamfer", chamfer(A, 0, 1.0)); });
check("diag.shell_open", [&]() -> Ret { return diag::dump("shell-open", shell(A, 0, 1.0)); });
check("diag.shell_closed", [&]() -> Ret { return diag::dump("shell-closed", shell(A, -1, 1.0)); });
check("diag.tweak_face", [&]() -> Ret { return diag::dump("tweak", tweak_face(A, 0, 1.0).body); });
check("diag.offset_face", [&]() -> Ret { return diag::dump("offset-face", offset_face(A, 0, 1.0).body); });
check("diag.clip_body", [&]() -> Ret {
return diag::dump("clip", clip_body(A, Point3D(0, 0, 0), Vector3D(0, 0, 1), true));
});
check("diag.thicken", [&]() -> Ret {
auto surf = vde::curves::NurbsSurface::plane(Point3D(0, 0, 0), Vector3D(1, 0, 0),
Vector3D(0, 1, 0), 10, 10);
return diag::dump("thicken", vde::curves::thicken_surface(surf, 2.0));
});
check("diag.loft", [&]() -> Ret {
std::vector<vde::curves::NurbsCurve> prof;
prof.push_back(vde::curves::NurbsCurve::circle(Point3D(0, 0, 0), 5.0));
prof.push_back(vde::curves::NurbsCurve::circle(Point3D(0, 0, 10), 3.0));
return diag::dump("loft", loft(prof));
});
check("diag.sweep", [&]() -> Ret {
auto prof = vde::curves::NurbsCurve::circle(Point3D(0, 0, 0), 1.0);
auto path = vde::curves::NurbsCurve::line(Point3D(0, 0, 0), Point3D(0, 0, 10));
return diag::dump("sweep", sweep(prof, path));
});
check("diag.tessellation_quality_fields", [&]() -> Ret {
auto mesh = A.to_mesh(0.05);
auto q = A.quality_report(mesh);
int boundary = 0;
const size_t nhe = mesh.num_edges() * 2;
for (size_t i = 0; i < nhe; ++i)
if (mesh.is_boundary_edge((int)i)) ++boundary;
return {true, fmt("tris=%d verts=%zu edges=%zu boundary_halfedges=%d watertight=%d degen=%d chord_max=%.3e chord_rms=%.3e aspect_max=%.3f",
q.num_triangles, mesh.num_vertices(), mesh.num_edges(),
boundary, (int)q.is_watertight, q.degenerate_tris,
q.chord_error_max, q.chord_error_rms, q.aspect_ratio_max)};
});
check("diag.wall_thickness_samples", [&]() -> Ret {
auto wt = analyze_wall_thickness(A, 3, true);
std::string s;
for (size_t i = 0; i < wt.samples.size() && i < 6; ++i) {
const auto& sm = wt.samples[i];
s += fmt(" [f%d (%.1f,%.1f,%.1f) n=(%.2f,%.2f,%.2f) t=%.2f]",
sm.face_id, sm.position.x(), sm.position.y(), sm.position.z(),
sm.normal.x(), sm.normal.y(), sm.normal.z(), sm.thickness);
}
return {true, fmt("min=%.2f max=%.2f avg=%.2f samples=%zu%s", wt.min_thickness,
wt.max_thickness, wt.avg_thickness, wt.samples.size(), s.c_str())};
});
check("diag.offset_body_semantics", [&]() -> Ret {
auto r1 = offset_body(A, 1.0);
auto r2 = offset_body(A, -1.0);
return {true, fmt("out: valid=%d F=%zu vol=%.1f | in: valid=%d F=%zu vol=%.1f (analytic)",
(int)r1.valid, r1.body.num_faces(),
analytic_measure(r1.body).volume, (int)r2.valid,
r2.body.num_faces(), analytic_measure(r2.body).volume)};
});
check("diag.make_primitives_face_types", [&]() -> Ret {
std::string s;
for (auto* b : {&A}) (void)b;
auto cyl = make_cylinder(10, 20, 64);
auto tor = make_torus(10, 2, 32, 16);
auto sph = make_sphere(5, 16, 8);
auto cone = make_cone(5, 0, 10, 32);
for (auto pair : std::vector<std::pair<const char*, BrepModel>>{
{"cyl", cyl}, {"torus", tor}, {"sphere", sph}, {"cone", cone}}) {
int ncyl = 0, ntor = 0, nsph = 0, ncone = 0, nplane = 0, noth = 0;
for (size_t i = 0; i < pair.second.num_faces(); ++i) {
switch (pair.second.face_type((int)i)) {
case FaceType::Cylinder: ++ncyl; break;
case FaceType::Torus: ++ntor; break;
case FaceType::Sphere: ++nsph; break;
case FaceType::Cone: ++ncone; break;
case FaceType::Plane: ++nplane; break;
default: ++noth; break;
}
}
s += fmt(" %s: F=%zu cyl=%d tor=%d sph=%d cone=%d plane=%d other=%d;",
pair.first, pair.second.num_faces(), ncyl, ntor, nsph, ncone,
nplane, noth);
}
return {true, s};
});
}
} // namespace
int main(int argc, char** argv) {
if (argc > 1) g_group_filter = argv[1];
std::printf("=== VDE B-Rep kernel capability audit probe (group=%s) ===\n",
g_group_filter.c_str());
std::printf("build: %s %s\n", __DATE__, __TIME__);
groupA();
groupB();
groupC();
groupD();
groupE();
groupF();
groupG();
groupH();
groupI();
groupJ();
std::printf("\n=== SUMMARY: PASS=%d FAIL=%d UNKNOWN=%d total_checks=%d total=%.1fms ===\n",
g_pass, g_fail, g_unk, g_total_checks, g_total_ms);
if (!g_fail_names.empty()) {
std::printf("FAILED CHECKS:\n");
for (const auto& n : g_fail_names) std::printf(" - %s\n", n.c_str());
}
return 0;
}