- nightly coverage job: core-plus-v2 is now the extended primary coverage
profile. The report-only archive step always runs; the hard baseline gate is
opt-in via vars.VDE_COV_PROFILE_V2 (legacy vars.VDE_ENABLE_CORE_PLUS_V2 still
honoured) and runs with --min-line-pct baseline --strict-baseline.
- tools/ci/validate_workflows.py: W54 rule 8 (every core-plus-v2 profile gate
must be --strict-baseline and opt-in gated; nightly.yml must keep the v2
report-only archive plus the v2 gate), new self-test counter-examples and an
updated nightly good case.
- tests: 4 new coverage targets / 49 cases for the v2 gap hotspots:
* test_cov_wave9_ssi: SSI degeneracy detection, fragment classification,
parallel/diagnostics entry points, tolerance/fuzzy overloads, env gates;
* test_cov_wave9_heal: stitch/gap-analysis, spur/dangling edge, unify topology
and auto-heal edge cases;
* test_cov_wave9_generative: generative surface checked/error branches;
* test_cov_wave9_mesh: repair/diagnostics/watertightness gap paths.
- No product source changes.
232 lines
8.9 KiB
C++
232 lines
8.9 KiB
C++
// KCP-1.0 Wave 9 / W54 (task-130):core-plus-v2 覆盖率缺口补测 —— 网格修复/诊断
|
||
// 目标:mesh_repair / mesh_diagnostics 的水密性度量、孔洞填充、重合顶点焊接、
|
||
// 绕向统一、非流形边检测与修复、边界环拟合等分支。不改变产品源码。
|
||
#include <gtest/gtest.h>
|
||
|
||
#include <array>
|
||
#include <vector>
|
||
|
||
#include "vde/mesh/halfedge_mesh.h"
|
||
#include "vde/mesh/mesh_diagnostics.h"
|
||
#include "vde/mesh/mesh_repair.h"
|
||
|
||
using namespace vde::mesh;
|
||
using namespace vde::core;
|
||
|
||
namespace {
|
||
|
||
// 单位立方体(外法线一致的 8 顶点 / 12 三角形)。
|
||
std::vector<Point3D> cube_verts() {
|
||
return {Point3D(0, 0, 0), Point3D(1, 0, 0), Point3D(1, 1, 0),
|
||
Point3D(0, 1, 0), Point3D(0, 0, 1), Point3D(1, 0, 1),
|
||
Point3D(1, 1, 1), Point3D(0, 1, 1)};
|
||
}
|
||
|
||
std::vector<std::array<int, 3>> cube_tris() {
|
||
return {{0, 2, 1}, {0, 3, 2}, {4, 5, 6}, {4, 6, 7}, {0, 1, 5},
|
||
{0, 5, 4}, {1, 2, 6}, {1, 6, 5}, {2, 3, 7}, {2, 7, 6},
|
||
{3, 0, 4}, {3, 4, 7}};
|
||
}
|
||
|
||
// 单位正方形(开放面片,2 三角形)。
|
||
std::vector<Point3D> quad_verts() {
|
||
return {Point3D(0, 0, 0), Point3D(1, 0, 0), Point3D(1, 1, 0),
|
||
Point3D(0, 1, 0)};
|
||
}
|
||
|
||
std::vector<std::array<int, 3>> quad_tris() {
|
||
return {{0, 1, 2}, {0, 2, 3}};
|
||
}
|
||
|
||
HalfedgeMesh make_mesh(const std::vector<Point3D>& verts,
|
||
const std::vector<std::array<int, 3>>& tris) {
|
||
HalfedgeMesh mesh;
|
||
mesh.build_from_triangles(verts, tris);
|
||
return mesh;
|
||
}
|
||
|
||
} // namespace
|
||
|
||
// ── 水密性度量 ────────────────────────────────────────────────────────────
|
||
|
||
TEST(CovWave9Mesh, AnalyzeCubeWatertightness) {
|
||
const auto w = analyze_mesh_watertightness(cube_verts(), cube_tris());
|
||
EXPECT_EQ(w.vertex_count, 8u);
|
||
EXPECT_EQ(w.welded_vertex_count, 8u);
|
||
EXPECT_EQ(w.triangle_count, 12u);
|
||
EXPECT_EQ(w.edge_count, 18u);
|
||
EXPECT_EQ(w.boundary_edges, 0u);
|
||
EXPECT_EQ(w.non_manifold_edges, 0u);
|
||
EXPECT_EQ(w.duplicate_triangles, 0u);
|
||
EXPECT_EQ(w.boundary_loops, 0u);
|
||
EXPECT_DOUBLE_EQ(w.shared_edge_ratio, 1.0);
|
||
EXPECT_TRUE(w.is_watertight);
|
||
EXPECT_NEAR(w.signed_volume, 1.0, 1e-9);
|
||
}
|
||
|
||
TEST(CovWave9Mesh, AnalyzeQuadOpenSheet) {
|
||
const auto w = analyze_mesh_watertightness(quad_verts(), quad_tris());
|
||
EXPECT_EQ(w.vertex_count, 4u);
|
||
EXPECT_EQ(w.triangle_count, 2u);
|
||
EXPECT_EQ(w.edge_count, 5u);
|
||
EXPECT_EQ(w.boundary_edges, 4u);
|
||
EXPECT_EQ(w.boundary_loops, 1u);
|
||
EXPECT_NEAR(w.boundary_length, 4.0, 1e-12);
|
||
EXPECT_DOUBLE_EQ(w.shared_edge_ratio, 0.2);
|
||
EXPECT_FALSE(w.is_watertight);
|
||
EXPECT_NEAR(w.signed_volume, 0.0, 1e-12);
|
||
}
|
||
|
||
// ── 边界统计与半边网格 ───────────────────────────────────────────────────
|
||
|
||
TEST(CovWave9Mesh, CubeBoundaryMetrics) {
|
||
const auto mesh = make_mesh(cube_verts(), cube_tris());
|
||
EXPECT_EQ(mesh.num_vertices(), 8u);
|
||
EXPECT_EQ(mesh.num_faces(), 12u);
|
||
|
||
const auto metrics = analyze_mesh_boundary(mesh);
|
||
EXPECT_EQ(metrics.vertices, 8u);
|
||
EXPECT_EQ(metrics.triangles, 12u);
|
||
EXPECT_EQ(metrics.edges, 18u);
|
||
EXPECT_EQ(metrics.boundary_edges, 0u);
|
||
EXPECT_EQ(metrics.nonmanifold_edges, 0u);
|
||
EXPECT_EQ(metrics.boundary_loops, 0u);
|
||
|
||
EXPECT_TRUE(analyze_mesh_watertightness(mesh).is_watertight);
|
||
}
|
||
|
||
// ── 修复报告 ──────────────────────────────────────────────────────────────
|
||
|
||
TEST(CovWave9Mesh, CubeHealingReport) {
|
||
const auto mesh = make_mesh(cube_verts(), cube_tris());
|
||
const auto report = mesh_healing_report(mesh);
|
||
EXPECT_EQ(report.total_faces, 12);
|
||
EXPECT_EQ(report.total_vertices, 8);
|
||
EXPECT_EQ(report.hole_count, 0);
|
||
EXPECT_EQ(report.non_manifold_edges, 0);
|
||
EXPECT_EQ(report.degenerate_faces, 0);
|
||
EXPECT_EQ(report.duplicate_vertices, 0);
|
||
EXPECT_EQ(report.flipped_faces, 0);
|
||
EXPECT_EQ(report.boundary_edges, 0);
|
||
EXPECT_TRUE(report.is_watertight);
|
||
EXPECT_TRUE(report.is_manifold);
|
||
EXPECT_TRUE(report.winding_consistent);
|
||
EXPECT_TRUE(report.outward_oriented);
|
||
EXPECT_GT(report.mesh_volume, 0.0);
|
||
EXPECT_FALSE(report.to_string().empty());
|
||
}
|
||
|
||
TEST(CovWave9Mesh, RepairCubeKeepsWatertight) {
|
||
const auto mesh = make_mesh(cube_verts(), cube_tris());
|
||
const auto repaired = repair_mesh(mesh);
|
||
EXPECT_EQ(repaired.num_faces(), 12u);
|
||
EXPECT_TRUE(analyze_mesh_watertightness(repaired).is_watertight);
|
||
}
|
||
|
||
// ── 孔洞填充 ──────────────────────────────────────────────────────────────
|
||
|
||
TEST(CovWave9Mesh, QuadHoleFillClosesBoundary) {
|
||
const auto mesh = make_mesh(quad_verts(), quad_tris());
|
||
const auto filled = automatic_hole_filling(mesh);
|
||
const auto w = analyze_mesh_watertightness(filled);
|
||
EXPECT_EQ(w.boundary_edges, 0u);
|
||
EXPECT_TRUE(w.is_watertight);
|
||
}
|
||
|
||
TEST(CovWave9Mesh, BoundaryLoopExtractionOnQuad) {
|
||
auto mesh = make_mesh(quad_verts(), quad_tris());
|
||
const auto loops = extract_boundary_loops(mesh);
|
||
ASSERT_EQ(loops.size(), 1u);
|
||
EXPECT_EQ(loops.front().vertices.size(), 4u);
|
||
EXPECT_NEAR(loops.front().length, 4.0, 1e-12);
|
||
|
||
const auto arcs = fit_boundary_arcs(mesh, loops.front(), 1e-3);
|
||
EXPECT_TRUE(arcs.empty());
|
||
|
||
EXPECT_EQ(fill_boundary_loops(mesh), 1u);
|
||
// 填充会沿环边补面(四边形孔洞实测新增 4 个三角形),只要求面数增加、
|
||
// 且填充后边界闭合。
|
||
EXPECT_GT(mesh.num_faces(), 2u);
|
||
EXPECT_EQ(analyze_mesh_watertightness(mesh).boundary_edges, 0u);
|
||
}
|
||
|
||
TEST(CovWave9Mesh, RepairMeshFillOptionRespected) {
|
||
const auto open = make_mesh(quad_verts(), quad_tris());
|
||
RepairOptions no_fill;
|
||
no_fill.fill_holes = false;
|
||
const auto unfilled = repair_mesh(open, no_fill);
|
||
EXPECT_EQ(analyze_mesh_watertightness(unfilled).boundary_edges, 4u);
|
||
|
||
const auto filled = repair_mesh(open);
|
||
EXPECT_EQ(analyze_mesh_watertightness(filled).boundary_edges, 0u);
|
||
}
|
||
|
||
// ── 重合顶点焊接 + 绕向统一 ───────────────────────────────────────────────
|
||
|
||
TEST(CovWave9Mesh, WeldDuplicateCubeVertices) {
|
||
const auto base = cube_verts();
|
||
const auto tris = cube_tris();
|
||
|
||
// 后 6 个三角形使用重复顶点(位置完全一致,索引 8..15)。
|
||
std::vector<Point3D> verts = base;
|
||
verts.insert(verts.end(), base.begin(), base.end());
|
||
std::vector<std::array<int, 3>> dup_tris = tris;
|
||
for (size_t i = 6; i < dup_tris.size(); ++i) {
|
||
for (int k = 0; k < 3; ++k) dup_tris[i][k] += 8;
|
||
}
|
||
|
||
const auto w = analyze_mesh_watertightness(verts, dup_tris, 1e-9);
|
||
EXPECT_EQ(w.vertex_count, 16u);
|
||
EXPECT_EQ(w.welded_vertex_count, 8u);
|
||
EXPECT_EQ(w.triangle_count, 12u);
|
||
EXPECT_TRUE(w.is_watertight);
|
||
|
||
const auto mesh = make_mesh(verts, dup_tris);
|
||
const auto unified = weld_and_unify_orientation(mesh, 1e-9);
|
||
EXPECT_EQ(unified.num_vertices(), 8u);
|
||
EXPECT_TRUE(analyze_mesh_watertightness(unified).is_watertight);
|
||
}
|
||
|
||
TEST(CovWave9Mesh, UnifyOrientationFlipsDetectsFlippedTriangle) {
|
||
auto verts = cube_verts();
|
||
auto tris = cube_tris();
|
||
std::swap(tris[0][1], tris[0][2]);
|
||
|
||
const auto flips = unify_orientation_flips(verts, tris, 1e-9);
|
||
ASSERT_EQ(flips.size(), tris.size());
|
||
int flipped = 0;
|
||
for (char f : flips) flipped += (f != 0) ? 1 : 0;
|
||
EXPECT_GE(flipped, 1);
|
||
|
||
EXPECT_TRUE(unify_orientation_flips(verts, {}, 1e-9).empty());
|
||
}
|
||
|
||
// ── 自交 / 非流形 ─────────────────────────────────────────────────────────
|
||
|
||
TEST(CovWave9Mesh, RepairSelfIntersectionsCubeNoPairs) {
|
||
const auto mesh = make_mesh(cube_verts(), cube_tris());
|
||
int resolved = -1;
|
||
const auto out = repair_self_intersections(mesh, &resolved);
|
||
EXPECT_EQ(resolved, 0);
|
||
EXPECT_EQ(out.num_faces(), 12u);
|
||
}
|
||
|
||
TEST(CovWave9Mesh, NonManifoldEdgesDetectAndRepair) {
|
||
const std::vector<Point3D> verts = {
|
||
Point3D(0, 0, 0), Point3D(1, 0, 0), Point3D(0, 1, 0),
|
||
Point3D(0, -1, 0), Point3D(0, 0, 1)};
|
||
const std::vector<std::array<int, 3>> tris = {
|
||
{0, 1, 2}, {0, 1, 3}, {0, 1, 4}};
|
||
|
||
const auto w = analyze_mesh_watertightness(verts, tris, 1e-9);
|
||
EXPECT_EQ(w.non_manifold_edges, 1u);
|
||
EXPECT_FALSE(w.is_watertight);
|
||
|
||
const auto mesh = make_mesh(verts, tris);
|
||
const auto repaired = non_manifold_repair(mesh);
|
||
EXPECT_EQ(analyze_mesh_boundary(repaired).nonmanifold_edges, 0u);
|
||
|
||
const auto repaired2 = repair_non_manifold_edges(mesh);
|
||
EXPECT_EQ(analyze_mesh_boundary(repaired2).nonmanifold_edges, 0u);
|
||
}
|