Files
ViewDesignEngine/tests/mesh/test_vde1235_display_feedback.cpp
hm 6f44d48d29
Build & Test / build-and-test (push) Canceled after 0s
VDE Build & Test / build-and-test (push) Canceled after 0s
Build & Test / python-bindings (push) Canceled after 0s
feat: P2-5c 圆角盒 seam 归零 + P3-4/5/6/7 收口(1.0.68)
### P2-5c 圆角盒残余 seam 96→0
- 根因:平面单环耳切剔除共线中间点,与共享采样 3 段边界不一致;新增 restore_ring_boundary_points 把共享边界点逐点补回;
- 26 面圆角盒 open 96→0(Plane/Cylinder/Sphere 全 0),tris 6396,box 类保持 0;平面面与曲面相邻时 10 tris/面(纯平面 box 仍 2),
  测试断言按新语义更新;

### P3-4 外部服务 OS 级沙箱
- vde-service.json limits(max_memory_mb/max_cpu_seconds/max_processes/kill_on_close);Windows Job Object(挂起创建→Assign→Resume、
  KILL_ON_JOB_CLOSE、内存/CPU/进程数限制事件)+ POSIX setsid/rlimit;结果 limit_exceeded/limit_kind;
- test_plugin_external_service 18/18(内存/CPU/进程数超限、kill_on_close 回收、旧行为、非法清单);docs 更新;

### P3-5 插件 DLL 工件哈希 + 密钥轮换/吊销
- manifest artifacts[{path,sha256}]/key_id;SHA-256 自实现 + 路径白名单;Policy require_artifact_hashes/trusted_keys/revoked_key_ids;
  新错误码;evaluate 扩展 + manager hook 已接线;tool verify --hash/--key-id;test_plugin_security 42/42;docs plugin-security §4.5/§4.6;

### P3-6 C++ 跨 DLL ABI 边界定稿(opt-in 实验)
- VDE_BUILD_CPP_SHARED(默认 OFF)12 内核模块 SHARED + consumer smoke(CPP_SHARED_CONSUMER_PASS faces=6 volume=6000);
- 决策:保持 C++ 静态 + 纯 C ABI + 插件默认;跨 DLL 单例/STL/RTTI/导出规模风险,实验仅 opt-in;architecture §7.8/design §13;

### P3-7 MSVC/Linux 跨平台验证收口
- .github/workflows/ci.yml 新增 windows-msvc job(YAML 校验通过);vde_platform UTF-8 宽 API/error/自守卫修复;
- 可移植性审计 12 类;docs/guides/cross-platform-validation.md;本机无 MSVC/WSL/docker,实机由 CI 反馈;

### VDE-1249 / 工程
- 反馈单更新:圆角盒 open 960→96→0,1.0.68 预算 Normal≈6396,宿主复测指引改 1.0.68;
- 版本 1.0.68;全量构建 0 error(340 targets);全量 ctest 7472 注册、7377/7377 PASS(0 failed,25 skipped,560.68s)。
2026-10-28 20:49:27 +08:00

527 lines
24 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.
/**
* @file test_vde1235_display_feedback.cpp
* @brief VDE-1235 / VDE-1236 / VDE-1239 display 管线回归测试
*
* 覆盖:
* - VDE-1236:平面面三角化不再信任 TopoEdge::v_start 方向(解析圆角盒 6 平面
* × 2 三角、矩形面积、总面积 6052.11;共享边方向相反的合成夹具);
* - VDE-1235:allow_partial + failed_faces(部分面失败降级)、不可见面不再
* 截断网格、wireframe crease/tangent 分类 + 二面角 + 相邻面 id、
* DisplayMeshCache(内容/选项指纹复用)、build_display_mesh_lod 公开 LOD API;
* - VDE-1239:解析曲面(Cylinder/Sphere/Torus)显示密度提升(与 legacy
* to_mesh 同量级)与逐三角形 smooth_group(相切面合并、硬边分隔)。
*/
#include <gtest/gtest.h>
#include "vde/brep/brep.h"
#include "vde/brep/modeling.h"
#include "vde/mesh/display_mesh.h"
#include <algorithm>
#include <array>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <map>
#include <memory>
#include <set>
#include <string>
#include <vector>
using namespace vde;
using namespace vde::brep;
using namespace vde::mesh;
using namespace vde::core;
namespace {
std::map<int32_t, size_t> triangles_per_face(const DisplayMesh& mesh) {
std::map<int32_t, size_t> counts;
for (int32_t fid : mesh.triangle_face_id) counts[fid]++;
return counts;
}
size_t count_surface_kind(const DisplayMesh& mesh, FaceType type) {
size_t n = 0;
const int32_t want = static_cast<int32_t>(type);
for (int32_t kind : mesh.triangle_surface_kind)
if (kind == want) ++n;
return n;
}
double tri_area(const Point3D& a, const Point3D& b, const Point3D& c) {
return 0.5 * (b - a).cross(c - a).norm();
}
double face_mesh_area(const DisplayMesh& mesh, int32_t face_id) {
double area = 0.0;
for (size_t ti = 0; ti < mesh.num_triangles(); ++ti) {
if (mesh.triangle_face_id[ti] != face_id) continue;
area += tri_area(mesh.positions[mesh.indices[ti][0]],
mesh.positions[mesh.indices[ti][1]],
mesh.positions[mesh.indices[ti][2]]);
}
return area;
}
double total_mesh_area(const DisplayMesh& mesh) {
double area = 0.0;
for (size_t ti = 0; ti < mesh.num_triangles(); ++ti) {
area += tri_area(mesh.positions[mesh.indices[ti][0]],
mesh.positions[mesh.indices[ti][1]],
mesh.positions[mesh.indices[ti][2]]);
}
return area;
}
/// 每平滑组包含的 B-Rep 面集合
std::map<int32_t, std::set<int32_t>> faces_by_smooth_group(const DisplayMesh& mesh) {
std::map<int32_t, std::set<int32_t>> groups;
if (mesh.triangle_smooth_group.size() != mesh.num_triangles()) return groups;
for (size_t ti = 0; ti < mesh.num_triangles(); ++ti)
groups[mesh.triangle_smooth_group[ti]].insert(mesh.triangle_face_id[ti]);
return groups;
}
/// VDE-1236 最小复现体:make_box(40,40,20) → 12 边 r=2 解析圆角 → 26 面
BrepModel make_rounded_box_26f() {
auto box = make_box(40.0, 40.0, 20.0);
auto sharp = box.sharp_edges(30.0);
if (sharp.size() != 12) return BrepModel{};
return fillet_edges(box, sharp, std::vector<double>(12, 2.0));
}
/// 构造 4 顶点矩形单面片(loop 边方向不完全一致/顺序任意,供 VDE-1236 夹具)
BrepModel make_quad_sheet(const std::vector<int>& loop_order) {
BrepModel sheet;
const int v0 = sheet.add_vertex(Point3D(0, 0, 0));
const int v1 = sheet.add_vertex(Point3D(2, 0, 0));
const int v2 = sheet.add_vertex(Point3D(2, 1, 0));
const int v3 = sheet.add_vertex(Point3D(0, 1, 0));
const int e0 = sheet.add_edge(v0, v1); // 沿 +X
const int e1 = sheet.add_edge(v1, v2); // 沿 +Y
const int e2 = sheet.add_edge(v3, v2); // 沿 +X(与环遍历方向相反)
const int e3 = sheet.add_edge(v0, v3); // 沿 +Y(与环遍历方向相反)
const std::array<int, 4> all{e0, e1, e2, e3};
std::vector<int> loop_edges;
loop_edges.reserve(loop_order.size());
for (int idx : loop_order) loop_edges.push_back(all[static_cast<size_t>(idx)]);
const int sid = sheet.add_surface(curves::NurbsSurface::plane(
Point3D(0, 0, 0), Vector3D(1, 0, 0), Vector3D(0, 1, 0), 2.0, 1.0));
const int loop = sheet.add_loop(loop_edges, true);
const int face = sheet.add_face(sid, {loop});
const int shell = sheet.add_shell({face}, false);
sheet.add_body({shell}, "quad_sheet");
return sheet;
}
} // namespace
// ═══════════════════════════════════════════════════════════
// VDE-1236:平面快路径不再信任 TopoEdge::v_start 方向
// ═══════════════════════════════════════════════════════════
TEST(VDE1236DisplayMesh, RoundedBoxAnalytic26FacesPlanarFastPath) {
auto rounded = make_rounded_box_26f();
ASSERT_EQ(rounded.num_faces(), 26u);
int n_plane = 0, n_cyl = 0, n_sphere = 0;
for (size_t fi = 0; fi < rounded.num_faces(); ++fi) {
switch (rounded.face_type(static_cast<int>(fi))) {
case FaceType::Plane: ++n_plane; break;
case FaceType::Cylinder: ++n_cyl; break;
case FaceType::Sphere: ++n_sphere; break;
default: break;
}
}
ASSERT_EQ(n_plane, 6);
ASSERT_EQ(n_cyl, 12);
ASSERT_EQ(n_sphere, 8);
const auto mesh = build_display_mesh(rounded, DisplayTessOptions{});
ASSERT_FALSE(mesh.indices.empty());
EXPECT_TRUE(mesh.diagnostic.empty());
std::printf("[VDE-1236] total tris=%zu verts=%zu\n", mesh.num_triangles(),
mesh.num_vertices());
// VDE-1249 P2-5c:圆角盒平面面与曲面相邻,边界点来自 DisplaySharedEdges
// 共享采样(直线边 3 段 + 圆弧边界),耳切为保留共享边界点会补回共线点 →
// 每平面面 10 三角(12 点环最小三角化),6 面共 60;纯平面体(box)仍走
// 精确平面快路径 6×2=12 三角(见下方 box 断言,VDE-1236 的 1 三角缺陷
// 仍被 box 快路径覆盖)。
EXPECT_EQ(count_surface_kind(mesh, FaceType::Plane), 60u);
const auto per_face = triangles_per_face(mesh);
double plane_area = 0.0;
double curved_area = 0.0;
for (size_t fi = 0; fi < rounded.num_faces(); ++fi) {
const int fid = static_cast<int>(fi);
const FaceType type = rounded.face_type(fid);
const auto it = per_face.find(fid);
ASSERT_NE(it, per_face.end()) << "face " << fid;
if (type == FaceType::Plane) {
// VDE-1249 P2-5c:共享边界点补回后平面面 2 → 10 tris(纯平面体仍 2)
EXPECT_EQ(it->second, 10u) << "plane face " << fid;
const Vector3D n = rounded.face_normal(fid);
// x/y 面 = 矩形 36×16,z 面 = 矩形 36×36
const double expected = std::abs(n.z()) > 0.9 ? 1296.0 : 576.0;
const double area = face_mesh_area(mesh, fid);
EXPECT_NEAR(area, expected, expected * 1e-6) << "face " << fid;
plane_area += area;
} else {
curved_area += face_mesh_area(mesh, fid);
if (type == FaceType::Cylinder) {
// VDE-1239:解析柱面片显示密度(修复前 ~36 tris/片)
EXPECT_GE(it->second, 60u) << "cylinder face " << fid;
} else if (type == FaceType::Sphere) {
// VDE-1239:解析球面片显示密度(修复前 ~162 tris/片)
EXPECT_GE(it->second, 400u) << "sphere face " << fid;
}
}
}
EXPECT_NEAR(plane_area, 4896.0, 1e-6 * 4896.0); // 4×576 + 2×1296
// 纯平面体(box)仍走精确平面快路径:6 面 × 2 三角 = 12(VDE-1236 核心)
{
auto plain_box = make_box(2.0, 2.0, 2.0);
const auto box_mesh = build_display_mesh(plain_box, DisplayTessOptions{});
EXPECT_EQ(count_surface_kind(box_mesh, FaceType::Plane), 12u);
EXPECT_EQ(box_mesh.num_triangles(), 12u);
}
// VDE-1236 验收:整件面积 ≈ 6052.11(网格弦化误差远小于 2.0)
const double total = total_mesh_area(mesh);
EXPECT_NEAR(total, 6052.11, 2.0) << "total=" << total;
EXPECT_NEAR(curved_area, 6052.11 - 4896.0, 2.5);
// VDE-1239:解析曲面加密后整件三角数与 legacy to_mesh(~6444) 同量级
EXPECT_GE(mesh.num_triangles(), 4000u);
EXPECT_LE(mesh.num_triangles(), 12000u);
}
TEST(VDE1236DisplayMesh, SharedEdgeDirectionMismatchRingIsRebuilt) {
// VDE-1236 根因最小夹具:环中 e2/e3 的 v_start 顺序与遍历方向相反。
// 旧实现拼出 [v0,v1,v3] 只产 1 个覆盖一半的三角。
const auto sheet = make_quad_sheet({0, 1, 2, 3});
auto mesh = build_display_mesh(sheet, DisplayTessOptions{});
ASSERT_EQ(mesh.num_triangles(), 2u);
EXPECT_NEAR(face_mesh_area(mesh, 0), 2.0, 1e-9);
EXPECT_TRUE(mesh.diagnostic.empty());
// 环边序列本身乱序(非遍历序)也必须按端点邻接串联
const auto shuffled = make_quad_sheet({1, 3, 0, 2});
auto mesh2 = build_display_mesh(shuffled, DisplayTessOptions{});
ASSERT_EQ(mesh2.num_triangles(), 2u);
EXPECT_NEAR(face_mesh_area(mesh2, 0), 2.0, 1e-9);
}
// ═══════════════════════════════════════════════════════════
// VDE-1235 #3:allow_partial / failed_faces
// ═══════════════════════════════════════════════════════════
TEST(VDE1235PartialMesh, CorruptFaceStrictVsPartial) {
BrepModel corrupt = make_box(2.0, 2.0, 2.0);
// 追加一个引用不存在环 id 的面:三角化时抛异常(真实损坏拓扑夹具)
const int bad_face = corrupt.add_face(0, {99999});
ASSERT_EQ(bad_face, 6);
// 默认全或无:返回空网格 + diagnostic(不返回半截网格)
DisplayTessOptions strict;
const auto strict_mesh = build_display_mesh(corrupt, strict);
EXPECT_TRUE(strict_mesh.indices.empty());
EXPECT_FALSE(strict_mesh.diagnostic.empty());
EXPECT_NE(strict_mesh.diagnostic.find("face 6"), std::string::npos);
EXPECT_TRUE(strict_mesh.failed_faces.empty());
// allow_partial=true:保留其余 6 面(12 三角),失败面进入 failed_faces
DisplayTessOptions partial;
partial.allow_partial = true;
const auto mesh = build_display_mesh(corrupt, partial);
ASSERT_EQ(mesh.num_triangles(), 12u);
EXPECT_EQ(count_surface_kind(mesh, FaceType::Plane), 12u);
const auto per_face = triangles_per_face(mesh);
EXPECT_EQ(per_face.count(bad_face), 0u);
EXPECT_EQ(per_face.size(), 6u);
ASSERT_EQ(mesh.failed_faces.size(), 1u);
EXPECT_EQ(mesh.failed_faces[0], bad_face);
EXPECT_FALSE(mesh.diagnostic.empty());
EXPECT_NE(mesh.diagnostic.find("allow_partial"), std::string::npos);
}
TEST(VDE1235PartialMesh, InvisibleFaceSkipsWithoutTruncating) {
auto box = make_box(2.0, 2.0, 2.0);
box.set_face_visibility(0, false);
DisplayTessOptions opts;
const auto mesh = build_display_mesh(box, opts);
// 旧实现把不可见面当"三角化失败"提前返回:face 0 在最前 → 空网格 + diagnostic
ASSERT_FALSE(mesh.indices.empty());
EXPECT_TRUE(mesh.diagnostic.empty());
EXPECT_EQ(mesh.num_triangles(), 10u);
const auto per_face = triangles_per_face(mesh);
EXPECT_EQ(per_face.count(0), 0u);
EXPECT_EQ(per_face.size(), 5u);
EXPECT_TRUE(mesh.failed_faces.empty());
}
// ═══════════════════════════════════════════════════════════
// VDE-1235 #4:wireframe crease/tangent 分类 + 二面角 + 相邻面
// ═══════════════════════════════════════════════════════════
TEST(VDE1235Wireframe, BoxAllCreaseWithAdjacentFaces) {
auto box = make_box(2.0, 1.0, 3.0);
const auto wf = build_wireframe(box, 0.01, true);
ASSERT_EQ(wf.num_segments(), 12u);
EXPECT_TRUE(wf.classified);
ASSERT_EQ(wf.segment_info.size(), wf.segments.size());
EXPECT_TRUE(wf.all_crease());
EXPECT_EQ(wf.num_segments_of_class(WireframeEdgeClass::Crease), 12u);
for (const auto& info : wf.segment_info) {
EXPECT_EQ(info.cls, WireframeEdgeClass::Crease);
EXPECT_NEAR(info.dihedral_deg, 90.0, 1e-6);
EXPECT_GE(info.adjacent_faces[0], 0);
EXPECT_GE(info.adjacent_faces[1], 0);
EXPECT_NE(info.adjacent_faces[0], info.adjacent_faces[1]);
EXPECT_LT(info.adjacent_faces[0], 6);
EXPECT_LT(info.adjacent_faces[1], 6);
}
}
TEST(VDE1235Wireframe, CylinderSeamTangentCapsCrease) {
auto cyl = make_cylinder(1.0, 2.0, 0); // 解析圆柱:4 个 90° 侧 patch + 2 盖
const auto wf = build_wireframe(cyl, 1e-3, true);
ASSERT_FALSE(wf.segments.empty());
ASSERT_EQ(wf.segment_info.size(), wf.segments.size());
size_t tangent_straight = 0;
size_t crease_circle = 0;
for (size_t si = 0; si < wf.segments.size(); ++si) {
const auto& info = wf.segment_info[si];
const int32_t eid = wf.segment_edge_id[si];
const EdgeDisplayInfo ei = edge_display_info(cyl, eid);
if (ei.kind == DisplayEdgeKind::Line) {
// 侧面 90° 分片接缝:相切(旧 edge_class 用面心法向会误判 90°)
EXPECT_EQ(info.cls, WireframeEdgeClass::Tangent) << "edge " << eid;
EXPECT_LT(info.dihedral_deg, 1e-2) << "edge " << eid;
++tangent_straight;
} else if (ei.kind == DisplayEdgeKind::Circle) {
// 圆边 = 侧壁与盖面交线:锐边 90°
EXPECT_EQ(info.cls, WireframeEdgeClass::Crease) << "edge " << eid;
EXPECT_NEAR(info.dihedral_deg, 90.0, 1e-2) << "edge " << eid;
++crease_circle;
}
}
EXPECT_GE(tangent_straight, 1u);
EXPECT_GE(crease_circle, 1u);
EXPECT_EQ(wf.num_segments_of_class(WireframeEdgeClass::Tangent),
tangent_straight);
}
TEST(VDE1235Wireframe, HoleRimCircleEdgesAreCrease) {
BrepModel box = make_box(4.0, 4.0, 2.0);
HoleSpec spec;
spec.diameter = 1.0;
spec.depth = 0.0;
BrepModel holed = make_hole(box, Point3D(0, 0, 1), Vector3D(0, 0, -1), spec);
const auto wf = build_wireframe(holed, 1e-3, true);
size_t hole_rims = 0;
for (size_t si = 0; si < wf.segments.size(); ++si) {
const int32_t eid = wf.segment_edge_id[si];
const EdgeDisplayInfo ei = edge_display_info(holed, eid);
if (ei.kind != DisplayEdgeKind::Circle) continue;
if (std::abs(ei.radius - 0.5) > 1e-9) continue;
++hole_rims;
EXPECT_EQ(wf.segment_info[si].cls, WireframeEdgeClass::Crease);
EXPECT_NEAR(wf.segment_info[si].dihedral_deg, 90.0, 1e-2);
}
EXPECT_GE(hole_rims, 2u);
}
// ═══════════════════════════════════════════════════════════
// VDE-1235 #5:DisplayMeshCache(内容/选项指纹复用)
// ═══════════════════════════════════════════════════════════
TEST(VDE1235Cache, ReuseByContentAndOptions) {
auto box = make_box(2.0, 2.0, 2.0);
DisplayMeshCache cache(4);
const DisplayTessOptions opts;
EXPECT_EQ(cache.stats().entries, 0u);
auto m1 = cache.get(box, opts);
ASSERT_NE(m1, nullptr);
EXPECT_EQ(m1->num_triangles(), 12u);
auto s1 = cache.stats();
EXPECT_EQ(s1.misses, 1u);
EXPECT_EQ(s1.hits, 0u);
EXPECT_EQ(s1.entries, 1u);
// 同 brep 同 options 二次调用:命中同一缓存的网格(不重建)
auto m2 = cache.get(box, opts);
auto s2 = cache.stats();
EXPECT_EQ(s2.hits, 1u);
EXPECT_EQ(s2.misses, 1u);
EXPECT_EQ(m1.get(), m2.get());
EXPECT_EQ(m1->num_vertices(), m2->num_vertices());
// 相同内容、不同对象:内容指纹命中
BrepModel box_copy = box;
auto m3 = cache.get(box_copy, opts);
EXPECT_EQ(m3.get(), m1.get());
EXPECT_EQ(cache.stats().hits, 2u);
// 内容变更:指纹改变 → 未命中
BrepModel moved = box;
moved.set_vertex_point(0, Point3D(0.13, 0.27, 0.41));
auto m4 = cache.get(moved, opts);
EXPECT_NE(m4.get(), m1.get());
EXPECT_EQ(cache.stats().misses, 2u);
// 选项变更:未命中
DisplayTessOptions coarse = opts;
coarse.chord_tolerance = 0.01;
auto m5 = cache.get(box, coarse);
EXPECT_EQ(cache.stats().misses, 3u);
EXPECT_EQ(cache.stats().entries, 3u);
// 指纹稳定性/敏感性
EXPECT_EQ(brep_fingerprint(box), brep_fingerprint(box_copy));
EXPECT_NE(brep_fingerprint(box), brep_fingerprint(moved));
EXPECT_NE(display_options_fingerprint(opts),
display_options_fingerprint(coarse));
// LRU 容量淘汰 + clear
DisplayMeshCache small(1);
auto cyl = make_cylinder(1.0, 2.0, 0);
(void)small.get(box, opts);
(void)small.get(cyl, opts);
EXPECT_EQ(small.stats().entries, 1u);
EXPECT_EQ(small.stats().evictions, 1u);
small.clear();
EXPECT_EQ(small.stats().entries, 0u);
}
// ═══════════════════════════════════════════════════════════
// VDE-1235 #1 + VDE-1239:LOD API 与解析曲面密度
// ═══════════════════════════════════════════════════════════
TEST(VDE1235Lod, QualityOrderingAndAnalyticDensity) {
auto rounded = make_rounded_box_26f();
ASSERT_EQ(rounded.num_faces(), 26u);
const auto draft = build_display_mesh_lod(rounded, DisplayQuality::Draft);
const auto normal = build_display_mesh_lod(rounded, DisplayQuality::Normal);
const auto high = build_display_mesh_lod(rounded, DisplayQuality::High);
ASSERT_FALSE(draft.indices.empty());
ASSERT_FALSE(normal.indices.empty());
ASSERT_FALSE(high.indices.empty());
EXPECT_TRUE(draft.diagnostic.empty());
EXPECT_TRUE(normal.diagnostic.empty());
EXPECT_TRUE(high.diagnostic.empty());
std::printf("[VDE-1239] LOD tris draft=%zu normal=%zu high=%zu\n",
draft.num_triangles(), normal.num_triangles(),
high.num_triangles());
EXPECT_LT(draft.num_triangles(), normal.num_triangles());
EXPECT_LT(normal.num_triangles(), high.num_triangles());
// VDE-1239 验收:Normal/High 解析曲面密度不低于 legacy to_mesh 量级
EXPECT_GE(normal.num_triangles(), 4000u);
EXPECT_GE(high.num_triangles(), normal.num_triangles());
const auto per_face = triangles_per_face(normal);
for (size_t fi = 0; fi < rounded.num_faces(); ++fi) {
if (rounded.face_type(static_cast<int>(fi)) != FaceType::Sphere) continue;
EXPECT_GE(per_face.at(static_cast<int32_t>(fi)), 400u)
<< "sphere face " << fi;
}
// VDE-1249 P2-5c:平面面与曲面相邻时边界点被共享采样加密(直线边 3 段),
// 三角化由 2 增至 10 tris/面(6 面 → 60);该值与 LOD 档位无关(平面面不随
// 弦高/角度细分)。纯平面体 box 的 LOD 仍为每档 12(见下方断言)。
EXPECT_EQ(count_surface_kind(draft, FaceType::Plane), 60u);
EXPECT_EQ(count_surface_kind(normal, FaceType::Plane), 60u);
EXPECT_EQ(count_surface_kind(high, FaceType::Plane), 60u);
// 纯平面 box 的 LOD 三角数不变
auto box = make_box(2.0, 2.0, 2.0);
EXPECT_EQ(build_display_mesh_lod(box, DisplayQuality::Draft).num_triangles(), 12u);
EXPECT_EQ(build_display_mesh_lod(box, DisplayQuality::Normal).num_triangles(), 12u);
EXPECT_EQ(build_display_mesh_lod(box, DisplayQuality::High).num_triangles(), 12u);
}
// ═══════════════════════════════════════════════════════════
// VDE-1239:逐三角形 smooth_group(相切合并/硬边分隔)
// ═══════════════════════════════════════════════════════════
TEST(VDE1239SmoothGroups, BoxHasSixIndependentGroups) {
auto box = make_box(2.0, 2.0, 2.0);
const auto mesh = build_display_mesh(box, DisplayTessOptions{});
ASSERT_EQ(mesh.triangle_smooth_group.size(), mesh.num_triangles());
const auto groups = faces_by_smooth_group(mesh);
ASSERT_EQ(groups.size(), 6u);
for (const auto& [gid, faces] : groups) {
EXPECT_EQ(faces.size(), 1u) << "group " << gid;
// 同一面内同组
const int32_t face = *faces.begin();
for (size_t ti = 0; ti < mesh.num_triangles(); ++ti) {
if (mesh.triangle_face_id[ti] != face) continue;
EXPECT_EQ(mesh.triangle_smooth_group[ti], gid);
}
}
}
TEST(VDE1239SmoothGroups, CylinderSideMergedCapsSeparate) {
auto cyl = make_cylinder(1.0, 2.0, 0); // 4 个 90° 侧 patch + 2 盖
const auto mesh = build_display_mesh(cyl, DisplayTessOptions{});
const auto groups = faces_by_smooth_group(mesh);
ASSERT_EQ(mesh.triangle_smooth_group.size(), mesh.num_triangles());
// 侧面 4 分片相切 → 合并为 1 组;两个盖面各 1 组
ASSERT_EQ(groups.size(), 3u);
int multi_face_groups = 0;
for (const auto& [gid, faces] : groups) {
if (faces.size() > 1) {
++multi_face_groups;
for (int32_t face : faces) {
EXPECT_EQ(cyl.face_type(face), FaceType::Cylinder)
<< "face " << face;
}
}
}
EXPECT_EQ(multi_face_groups, 1);
}
TEST(VDE1239SmoothGroups, RoundedBoxG1SurfaceIsOneSmoothGroup) {
// 26 面解析圆角盒是全 G1 体:圆角柱面/球面片之间相切,且与两侧平面
// 相切(fillet 定义),因此整个外壳应合并为 1 个平滑组——宿主按组跨面
// 平均法线即可消除面片接缝的明暗断层(m4_fillet 型)。锐边分隔由
// box(6 组)/圆柱(侧+2 盖 = 3 组)用例覆盖。
auto rounded = make_rounded_box_26f();
const auto mesh = build_display_mesh(rounded, DisplayTessOptions{});
ASSERT_EQ(mesh.triangle_smooth_group.size(), mesh.num_triangles());
const auto groups = faces_by_smooth_group(mesh);
std::printf("[VDE-1239] rounded-box smooth groups=%zu\n", groups.size());
ASSERT_EQ(groups.size(), 1u);
EXPECT_EQ(groups.begin()->second.size(), 26u); // 全部 B-Rep 面同组
// 关闭平滑组计算 → 退化为 triangle_face_id(每面一组)
DisplayTessOptions no_groups;
no_groups.compute_smooth_groups = false;
const auto raw = build_display_mesh(rounded, no_groups);
ASSERT_EQ(raw.triangle_smooth_group.size(), raw.num_triangles());
for (size_t ti = 0; ti < raw.num_triangles(); ++ti)
EXPECT_EQ(raw.triangle_smooth_group[ti], raw.triangle_face_id[ti]);
}
// ═══════════════════════════════════════════════════════════
// 兼容性:既有显示契约不变
// ═══════════════════════════════════════════════════════════
TEST(VDE1235Compat, ExistingDisplayContractUnchanged) {
auto box = make_box(2.0, 2.0, 2.0);
DisplayMeshOptions alias; // 宿主命名别名
const auto mesh = build_display_mesh(box, alias);
EXPECT_EQ(mesh.num_triangles(), 12u);
EXPECT_TRUE(mesh.diagnostic.empty());
EXPECT_TRUE(mesh.failed_faces.empty());
EXPECT_EQ(mesh.triangle_smooth_group.size(), mesh.num_triangles());
const auto wf = build_wireframe(box, 0.01, true);
EXPECT_EQ(wf.num_segments(), 12u);
EXPECT_EQ(wf.positions.size(), 24u);
EXPECT_EQ(wf.segment_edge_id.size(), wf.segments.size());
EXPECT_EQ(wf.segment_info.size(), wf.segments.size());
// 旧签名(默认参数)仍可用
const auto wf_default = build_wireframe(box);
EXPECT_EQ(wf_default.num_segments(), 12u);
}