继续对 "Status: Fixed" 反馈文档做真实现终审,本轮落实 5 处伪实现/失效实现。
曲线曲面(VDE-125):
- sew_surfaces:源码注释自述"不检测重合顶点/边",仅把各面按索引偏移拼进同一模型,
相邻曲面公共边界各留一份顶点与边 ⇒ 壳必然漏水、validate 按破壳处理。改为容差
空间哈希焊接顶点(3×3×3 邻域、map<tuple> 避免大坐标位打包溢出)+ add_edge_unique
共享边界边 + 按"每条边恰 2 邻接面"判定壳体闭合
- boundary_surface / fill_surface:N 边(n≠4)分支控制网格建成 (nu+1)×(nv+1),
而 knots_u 隐含 u 向控制点数 = nu ⇒ 三角形/五边形输入 100% 抛
"u-direction size mismatch"。修正网格维度与闭合环参数化
交互拾取(VDE-405,vde_ui::SelectionManager):
- interactive_select 原完全忽略窗口角点、无条件返回全部面(框选永远全选)
- pick_select 原为 (void)全部入参; return {}
- 现实现:新增 ViewProjection/set_view(world→clip + 视口);pick_select 屏幕点
反投影成世界射线 → rayIntersectAll 取最近命中面,并按 pick_radius 像素做屏幕
空间回退;interactive_select 投影面 AABB/边/顶点,Window 要求完全包围、
Crossing 相交即选。未设视图时明确返回空
结构型材(VDE-124):
- make_weld_bead 原把 body_b/edge_b 用 (void) 掉,焊道只按单边定位会埋进板体。
改为取两边中点连线的中点作接缝位置;越界边返回空体而非 UB
BOM(VDE-408):
- bom_generation 质量累计用 bounds().volume()(包围盒体积,圆柱偏高 27%)⇒
改用 body_volume()(解析真实体积)
回归测试:新增 tests/ui/test_selection_manager.cpp(8 例);test_surface_tools 新增
缝合焊接断言(6 顶点/7 边/公共边 2 邻接);test_structural_profiles 新增焊道接缝定位断言。
验证:test_surface_tools 16/16、test_structural_profiles 26/26、test_selection_manager 8/8、
test_measure 33/33、test_draft_analysis 17/17、test_brep_validate 18/18、test_hlr_api 11/11、
test_brep_modeling 73/73、test_brep 43/43。
文档:VDE-125/124/405/408 补真实实现审计并校正状态;audit-implementation.md 增第二轮章节。
150 lines
5.8 KiB
C++
150 lines
5.8 KiB
C++
#include <gtest/gtest.h>
|
||
#include "vde_ui/selection_manager.h"
|
||
#include "vde/brep/modeling.h"
|
||
#include <cmath>
|
||
|
||
using namespace vde::ui;
|
||
using namespace vde::core;
|
||
using vde::brep::make_box;
|
||
|
||
// ═══════════════════════════════════════════════════════════
|
||
// VDE-405: SelectionManager 真实屏幕空间拾取
|
||
//
|
||
// 回归"interactive_select 忽略窗口角点、无条件返回全部面"与
|
||
// "pick_select 直接 return {}" 两个伪实现。
|
||
//
|
||
// 测试用视图(正交,相机沿 +Z 看向原点):
|
||
// ndc.x = world.x / 2, ndc.y = world.y / 2, ndc.z = (world.z - 2) / 5
|
||
// 视口 800×600 ⇒ 屏幕原点左上、y 向下:
|
||
// 世界 x∈[-1,1] → 屏幕 x∈[200,600]
|
||
// 世界 y∈[-1,1] → 屏幕 y∈[450,150](上小下大)
|
||
// world→NDC 的 near(z=-1)=世界 z=-3,far(z=+1)=世界 z=+7
|
||
// ═══════════════════════════════════════════════════════════
|
||
|
||
namespace {
|
||
|
||
ViewProjection test_view() {
|
||
ViewProjection vp;
|
||
vp.world_to_clip = Matrix4D::Identity();
|
||
vp.world_to_clip.at(0, 0) = 0.5;
|
||
vp.world_to_clip.at(1, 1) = 0.5;
|
||
vp.world_to_clip.at(2, 2) = 0.2;
|
||
vp.world_to_clip.at(2, 3) = -0.4;
|
||
vp.viewport_width = 800.0;
|
||
vp.viewport_height = 600.0;
|
||
vp.valid = true;
|
||
return vp;
|
||
}
|
||
|
||
SelectionFilter face_only_filter() {
|
||
SelectionFilter f;
|
||
f.allowed_types = {SelectionFilterType::Face};
|
||
return f;
|
||
}
|
||
|
||
} // namespace
|
||
|
||
TEST(SelectionManagerTest, PickSelect_NoViewReturnsEmpty) {
|
||
auto box = make_box(2, 2, 2);
|
||
SelectionManager sm; // 未 set_view
|
||
auto r = sm.pick_select(box, Point2D(400, 300), 5.0);
|
||
EXPECT_TRUE(r.empty());
|
||
}
|
||
|
||
TEST(SelectionManagerTest, InteractiveSelect_NoViewReturnsEmpty) {
|
||
auto box = make_box(2, 2, 2);
|
||
SelectionManager sm;
|
||
auto r = sm.interactive_select(box, Point2D(0, 0), Point2D(800, 600),
|
||
SelectionMode::Window, face_only_filter());
|
||
EXPECT_TRUE(r.empty());
|
||
}
|
||
|
||
TEST(SelectionManagerTest, PickSelect_RayHitsNearestFace) {
|
||
auto box = make_box(2, 2, 2);
|
||
SelectionManager sm;
|
||
sm.set_view(test_view());
|
||
|
||
// 视口中心 → 射线 (0,0,-3)+t(0,0,1):先命中 z=-1 底面(face 0),
|
||
// 而非更远的 z=+1 顶面(face 1,距离 4)。
|
||
auto r = sm.pick_select(box, Point2D(400, 300), 5.0, face_only_filter());
|
||
ASSERT_EQ(r.items.size(), 1u);
|
||
EXPECT_EQ(r.items[0].entity_id, 0);
|
||
EXPECT_EQ(r.items[0].type, SelectionFilterType::Face);
|
||
EXPECT_NEAR(r.items[0].world_position.z(), -1.0, 1e-4);
|
||
}
|
||
|
||
TEST(SelectionManagerTest, PickSelect_MissReturnsEmpty) {
|
||
auto box = make_box(2, 2, 2);
|
||
SelectionManager sm;
|
||
sm.set_view(test_view());
|
||
|
||
// 屏幕 y=100 → 世界 y≈1.33,在盒体外 ⇒ 射线不命中;pick_radius=0
|
||
// 关闭屏幕空间回退 ⇒ 必须为空(旧实现恒为空是因为根本没实现)。
|
||
auto r = sm.pick_select(box, Point2D(400, 100), 0.0, face_only_filter());
|
||
EXPECT_TRUE(r.empty());
|
||
}
|
||
|
||
TEST(SelectionManagerTest, PickSelect_ScreenSpaceFallbackHonorsPickRadius) {
|
||
auto box = make_box(2, 2, 2);
|
||
SelectionManager sm;
|
||
sm.set_view(test_view());
|
||
|
||
// 屏幕 y=148 → 世界 y≈1.013,刚出盒体(射线不命中);但 face 3(y=+1 面)
|
||
// 的包围盒中心投影在屏幕 (400,150),距该点 2 像素 ≤ pick_radius(5) ⇒ 回退选中。
|
||
auto r = sm.pick_select(box, Point2D(400, 148), 5.0, face_only_filter());
|
||
ASSERT_EQ(r.items.size(), 1u);
|
||
EXPECT_EQ(r.items[0].entity_id, 3);
|
||
|
||
// pick_radius 收紧到 1 像素 ⇒ 距离 2 > 1,不再命中
|
||
auto r2 = sm.pick_select(box, Point2D(400, 148), 1.0, face_only_filter());
|
||
EXPECT_TRUE(r2.empty());
|
||
}
|
||
|
||
TEST(SelectionManagerTest, InteractiveSelect_WindowRequiresFullEnclosure) {
|
||
auto box = make_box(2, 2, 2);
|
||
SelectionManager sm;
|
||
sm.set_view(test_view());
|
||
|
||
// 覆盖整个视口 ⇒ 6 个面全部被完全包围
|
||
auto all = sm.interactive_select(box, Point2D(0, 0), Point2D(800, 600),
|
||
SelectionMode::Window, face_only_filter());
|
||
EXPECT_EQ(all.items.size(), 6u);
|
||
|
||
// 小窗口只圈住视口中心附近;盒体每个面都延伸到 x=±1(屏幕 200/600),
|
||
// 无一面被完全包围 ⇒ Window 模式必须为空
|
||
auto none = sm.interactive_select(box, Point2D(390, 290), Point2D(410, 310),
|
||
SelectionMode::Window, face_only_filter());
|
||
EXPECT_TRUE(none.empty());
|
||
}
|
||
|
||
TEST(SelectionManagerTest, InteractiveSelect_CrossingSelectsTouchedFaces) {
|
||
auto box = make_box(2, 2, 2);
|
||
SelectionManager sm;
|
||
sm.set_view(test_view());
|
||
|
||
// 视口中心小窗口:世界 x,y ∈ [-0.05,0.05],只压住 z=±1 两面的包围盒中心
|
||
auto r = sm.interactive_select(box, Point2D(390, 290), Point2D(410, 310),
|
||
SelectionMode::Crossing, face_only_filter());
|
||
ASSERT_EQ(r.items.size(), 2u);
|
||
for (const auto& it : r.items) {
|
||
EXPECT_TRUE(it.entity_id == 0 || it.entity_id == 1) << "face " << it.entity_id;
|
||
}
|
||
}
|
||
|
||
TEST(SelectionManagerTest, SelectionFilter_KeepsOnlyAllowedTypes) {
|
||
auto box = make_box(2, 2, 2);
|
||
SelectionManager sm;
|
||
sm.set_view(test_view());
|
||
|
||
auto all = sm.interactive_select(box, Point2D(0, 0), Point2D(800, 600),
|
||
SelectionMode::Window, {});
|
||
ASSERT_GT(all.items.size(), 6u); // 面 + 边 + 顶点
|
||
|
||
SelectionFilter faces;
|
||
faces.allowed_types = {SelectionFilterType::Face};
|
||
auto only_faces = sm.selection_filter(all, faces);
|
||
EXPECT_EQ(only_faces.items.size(), 6u);
|
||
for (const auto& it : only_faces.items)
|
||
EXPECT_EQ(it.type, SelectionFilterType::Face);
|
||
}
|