Wave 8 W48 (task-123). Profile: tools/coverage/target_profiles.json gains core-plus-v2 = core-plus 59 targets + 37 plugin/capi/spatial/sdf/compute targets (96 total; >=85 required). Excludes test_curved_boolean_baseline (gcov wall-clock sensitive, same as core-plus) and test_plugin_ecosystem (asserts all official plugin kinds, needs full plugin build). line_pct_gate = 52.0 derived from the measured 54.01% (floor - 2pp). Tests: 5 new files / 20 cases covering plugin lifecycle + capability registry semantics, C API export boundaries, BVH edge cases, SDF field nodes and compute SIMD lane boundaries. All 20 pass; module-subset ctest (Plugin|Capi|Spatial|Sdf| Compute|Brep|Curves|Foundation) = 721/721 passed. Measurement (build-cov8, RelWithDebInfo + VDE_ENABLE_COVERAGE, MinGW gcc 16.1.0): before core-plus 50.91% (63374/124474), after core-plus-v2 54.01% (70324/130198), func 62.88% (3568/5674), branch 33.55%; 2418/2418 cases pass. --update-baseline wrote tools/coverage/baseline.json core-plus-v2 entry and --min-line-pct baseline --strict-baseline PASSed (status PASS, line gate 54.01%). Plugin fixture fix: test_plugin_extensions build deps now include vde_service_runner / vde_service_stl_convert / vde_service_gcs_solve (3 external-service cases failed when only the target was built; 9/9 pass after the fix). CI: nightly coverage-nightly adds a core-plus-v2 report-only archive step and an opt-in hard gate gated by vars.VDE_ENABLE_CORE_PLUS_V2=1; pr-quality dry-run plan adds --profile core-plus-v2. Evidence: docs/planning/wave8/cov-notes.md and build/kcp8_evidence/cov/ (before/after/after-gate reports, ctest logs). Validation: validate_workflows.py --strict PASS 2/2, vde_release.py --check PASS (14 checks, 0 fail/0 warn), no product (src/) changes.
168 lines
7.2 KiB
C++
168 lines
7.2 KiB
C++
#include <gtest/gtest.h>
|
|
#include "vde/sdf/sdf_tree.h"
|
|
#include "vde/sdf/sdf_primitives.h"
|
|
#include "vde/sdf/sdf_operations.h"
|
|
#include <cmath>
|
|
#include <vector>
|
|
|
|
using namespace vde::sdf;
|
|
using namespace vde::core;
|
|
|
|
// ═══════════════════════════════════════════════════════════
|
|
// Wave 8 补测: SDF 表达式树的字段操作
|
|
//
|
|
// 覆盖 src/sdf/sdf_tree.cpp 中此前未执行的求值路径:
|
|
// - 图元节点: ellipsoid / cone / capsule / triangular_prism /
|
|
// hex_prism / link / wedge
|
|
// - 变形节点: rotate / mirror_y / mirror_z / twist / bend /
|
|
// elongate / cheap_bend / displace
|
|
// - 平滑差集 smooth_difference
|
|
// - estimate_radius 的分支与 estimate_bounds / estimate_bbox
|
|
// 断言方式: 树求值结果必须与直接调用对应图元/操作函数一致。
|
|
// ═══════════════════════════════════════════════════════════
|
|
|
|
namespace {
|
|
|
|
const std::vector<Point3D>& probes() {
|
|
static const std::vector<Point3D> pts = {
|
|
Point3D(0.0, 0.0, 0.0),
|
|
Point3D(0.3, 0.2, 0.1),
|
|
Point3D(1.5, -0.5, 0.25),
|
|
Point3D(2.0, 0.0, 0.0),
|
|
Point3D(-1.0, 0.5, -0.25),
|
|
};
|
|
return pts;
|
|
}
|
|
|
|
} // namespace
|
|
|
|
// ── 图元: 椭球 / 圆锥台 / 胶囊 ───────────────────────────
|
|
|
|
TEST(CovSdfField, EllipsoidConeCapsuleTreeMatchesPrimitive) {
|
|
const Point3D radii(2.0, 1.0, 0.5);
|
|
auto ell = SdfNode::ellipsoid(radii);
|
|
ASSERT_EQ(ell->op, SdfOp::Ellipsoid);
|
|
|
|
auto cn = SdfNode::cone(0.5, 2.0);
|
|
auto cap = SdfNode::capsule(Point3D(0, -1, 0), Point3D(0, 1, 0), 0.4);
|
|
|
|
for (const auto& p : probes()) {
|
|
EXPECT_DOUBLE_EQ(evaluate(ell, p), ellipsoid(p, radii));
|
|
EXPECT_DOUBLE_EQ(evaluate(cn, p), cone(p, 0.5, 2.0));
|
|
EXPECT_DOUBLE_EQ(evaluate(cap, p),
|
|
capsule(p, Point3D(0, -1, 0), Point3D(0, 1, 0), 0.4));
|
|
EXPECT_TRUE(std::isfinite(evaluate(ell, p)));
|
|
}
|
|
}
|
|
|
|
// ── 图元: 三角棱柱 / 正多边形棱柱 / 链接 / 楔形 ─────────
|
|
|
|
TEST(CovSdfField, PrismLinkWedgeTreeMatchesPrimitive) {
|
|
const double h = 2.0;
|
|
auto tri = SdfNode::triangular_prism(h);
|
|
const double rh = h * 0.57735;
|
|
const Point3D ta(-rh, 0, -rh * 0.5);
|
|
const Point3D tb(rh, 0, -rh * 0.5);
|
|
const Point3D tc(0, 0, rh);
|
|
|
|
auto hex6 = SdfNode::hex_prism(1.5, 2.0);
|
|
auto hex8 = SdfNode::hex_prism(1.2, 1.5, 8);
|
|
auto lk = SdfNode::link(1.0, 2.0, 0.1);
|
|
auto wg = SdfNode::wedge(Point3D(1.0, 2.0, 0.5));
|
|
|
|
for (const auto& p : probes()) {
|
|
EXPECT_DOUBLE_EQ(evaluate(tri, p), triangular_prism(p, ta, tb, tc, h));
|
|
EXPECT_DOUBLE_EQ(evaluate(hex6, p), regular_polygon_prism(p, 1.5, 2.0, 6));
|
|
EXPECT_DOUBLE_EQ(evaluate(hex8, p), regular_polygon_prism(p, 1.2, 1.5, 8));
|
|
EXPECT_DOUBLE_EQ(evaluate(lk, p), link(p, 2.0, 1.0, 0.1));
|
|
EXPECT_DOUBLE_EQ(evaluate(wg, p), wedge(p, 2.0, 4.0, 1.0));
|
|
}
|
|
}
|
|
|
|
// ── 变形: 旋转 / Y-Z 镜像 ────────────────────────────────
|
|
|
|
TEST(CovSdfField, RotateAndMirrorTreeMatchesOperation) {
|
|
const Point3D half(1.0, 1.0, 1.0);
|
|
const double angle = 0.6;
|
|
auto rot = SdfNode::rotate(SdfNode::box(half), angle);
|
|
auto my = SdfNode::mirror_y(SdfNode::sphere(0.75));
|
|
auto mz = SdfNode::mirror_z(SdfNode::sphere(0.75));
|
|
|
|
for (const auto& p : probes()) {
|
|
EXPECT_DOUBLE_EQ(evaluate(rot, p), box(op_rotate(p, angle), half));
|
|
EXPECT_DOUBLE_EQ(evaluate(my, p), sphere(op_mirror_y(p), 0.75));
|
|
EXPECT_DOUBLE_EQ(evaluate(mz, p), sphere(op_mirror_z(p), 0.75));
|
|
}
|
|
}
|
|
|
|
// ── 修饰/变形/位移 + 平滑差集 + 包围盒估算 ───────────────
|
|
|
|
TEST(CovSdfField, DeformSmoothDifferenceAndBounds) {
|
|
const Point3D half(0.5, 0.5, 0.5);
|
|
auto sdiff = SdfNode::smooth_difference(SdfNode::sphere(1.0),
|
|
SdfNode::box(half), 0.25);
|
|
auto twist = SdfNode::twist(SdfNode::box(half), 0.5);
|
|
auto bend = SdfNode::bend(SdfNode::box(half), 0.3);
|
|
auto elong = SdfNode::elongate(SdfNode::sphere(0.5), Point3D(0.5, 0.5, 0.5));
|
|
auto cbend = SdfNode::cheap_bend(SdfNode::box(half), 0.4);
|
|
auto disp = SdfNode::displace(SdfNode::sphere(1.0), 0.1, 2.0);
|
|
|
|
for (const auto& p : probes()) {
|
|
EXPECT_DOUBLE_EQ(evaluate(sdiff, p),
|
|
op_smooth_difference(sphere(p, 1.0), box(p, half), 0.25));
|
|
EXPECT_DOUBLE_EQ(evaluate(twist, p), box(op_twist(p, 0.5), half));
|
|
EXPECT_DOUBLE_EQ(evaluate(bend, p), box(op_bend(p, 0.3), half));
|
|
EXPECT_DOUBLE_EQ(evaluate(elong, p),
|
|
sphere(op_elongate(p, Point3D(0.5, 0.5, 0.5)), 0.5));
|
|
EXPECT_DOUBLE_EQ(evaluate(cbend, p), box(op_cheap_bend(p, 0.4), half));
|
|
EXPECT_DOUBLE_EQ(evaluate(disp, p),
|
|
op_displace(sphere(p, 1.0), p, 0.1, 2.0));
|
|
}
|
|
|
|
// ── 包围盒估算分支 ──
|
|
const auto ell_bounds = estimate_bounds(SdfNode::ellipsoid(Point3D(2.0, 1.0, 0.5)), 0.5);
|
|
EXPECT_DOUBLE_EQ(ell_bounds.x(), 2.5);
|
|
EXPECT_DOUBLE_EQ(ell_bounds.y(), 2.5);
|
|
EXPECT_DOUBLE_EQ(ell_bounds.z(), 2.5);
|
|
|
|
const auto box_bounds = estimate_bounds(SdfNode::box(Point3D(1.0, 2.0, 3.0)), 0.0);
|
|
EXPECT_NEAR(box_bounds.x(), std::sqrt(14.0), 1e-12);
|
|
|
|
const auto torus_bounds = estimate_bounds(SdfNode::torus(1.0, 0.3), 0.0);
|
|
EXPECT_NEAR(torus_bounds.x(), 1.3, 1e-12);
|
|
|
|
const auto cap_bounds = estimate_bounds(
|
|
SdfNode::capsule(Point3D(0, -1, 0), Point3D(0, 1, 0), 0.4), 0.0);
|
|
EXPECT_NEAR(cap_bounds.x(), 1.4, 1e-12);
|
|
|
|
const auto cyl_bounds = estimate_bounds(SdfNode::cylinder(1.0, 2.0), 0.0);
|
|
EXPECT_NEAR(cyl_bounds.x(), std::sqrt(2.0), 1e-12);
|
|
|
|
const auto link_bounds = estimate_bounds(SdfNode::link(1.0, 2.0, 0.1), 0.0);
|
|
EXPECT_NEAR(link_bounds.x(), 2.1, 1e-12);
|
|
|
|
const auto wedge_bounds = estimate_bounds(SdfNode::wedge(Point3D(1.0, 2.0, 0.5)), 0.0);
|
|
EXPECT_NEAR(wedge_bounds.x(), std::sqrt(1.0 + 4.0 + 0.25), 1e-12);
|
|
|
|
// 组合节点: union 取最大, difference 取被减主体, translate 增加偏移模长
|
|
auto uni = SdfNode::op_union(SdfNode::sphere(1.0), SdfNode::box(Point3D(2, 2, 2)));
|
|
EXPECT_NEAR(estimate_bounds(uni, 0.0).x(), std::sqrt(12.0), 1e-12);
|
|
|
|
auto diff = SdfNode::op_difference(SdfNode::sphere(3.0), SdfNode::box(half));
|
|
EXPECT_NEAR(estimate_bounds(diff, 0.0).x(), 3.0, 1e-12);
|
|
|
|
auto trans = SdfNode::translate(SdfNode::sphere(1.0), Point3D(2.0, 0.0, 0.0));
|
|
EXPECT_NEAR(estimate_bounds(trans, 0.0).x(), 3.0, 1e-12);
|
|
|
|
// estimate_bbox: 对称 AABB
|
|
auto bbox = estimate_bbox(SdfNode::sphere(1.0), 0.25);
|
|
EXPECT_DOUBLE_EQ(bbox.min.x(), -1.25);
|
|
EXPECT_DOUBLE_EQ(bbox.max.x(), 1.25);
|
|
EXPECT_DOUBLE_EQ(bbox.min.y(), bbox.min.z());
|
|
EXPECT_DOUBLE_EQ(bbox.max.y(), bbox.max.z());
|
|
EXPECT_DOUBLE_EQ(bbox.min.x(), -bbox.max.x());
|
|
|
|
// 空指针节点返回远距离哨兵值
|
|
EXPECT_DOUBLE_EQ(evaluate(SdfNodePtr(), Point3D(0, 0, 0)), 1e30);
|
|
}
|