Files
ViewDesignEngine/tests/ui/test_viewport_api.cpp
T
hm 85f2df2ca7 refactor(batch2): extract pdm/license/platform/ui modules
Moved 4 module groups out of geometry kernel:

- vde_pdm: bom_table + quality_feedback + material_library (from brep/core)

- vde_license: license_manager (from core, vde_version.h updated)

- vde_platform: platform (from core, io_dwg_plugin.cpp updated)

- vde_ui: gizmo_api + selection_manager + viewport_api (from brep)

All modules compile. Pre-existing test failures unchanged (case-sensitive tier parsing, orientation cube)
2026-08-06 16:27:36 +08:00

72 lines
2.1 KiB
C++

#include <gtest/gtest.h>
#include "vde_ui/viewport_api.h"
#include "vde/brep/brep.h"
#include "vde/core/matrix4d.h"
using namespace vde::brep;
using namespace vde::ui;
using namespace vde::core;
/// 创建一个简单的立方体 BrepModel
static BrepModel make_test_model() {
BrepModel model;
int v0 = model.add_vertex(Point3D(0, 0, 0));
int v1 = model.add_vertex(Point3D(1, 0, 0));
int v2 = model.add_vertex(Point3D(1, 1, 0));
int v3 = model.add_vertex(Point3D(0, 1, 0));
model.add_edge(v0, v1);
model.add_edge(v1, v2);
model.add_edge(v2, v3);
model.add_edge(v3, v0);
int loop = model.add_loop({0, 1, 2, 3}, true);
auto surf = vde::curves::NurbsSurface::plane(
Point3D(0,0,0), Vector3D(1,0,0), Vector3D(0,1,0), 1.0, 1.0);
int sid = model.add_surface(surf);
int fid = model.add_face(sid, {loop});
int shell = model.add_shell({fid}, true);
model.add_body({shell}, "test");
return model;
}
TEST(ViewportApiTest, BoundingSphereNonEmpty) {
auto model = make_test_model();
auto bs = bounding_sphere(model);
EXPECT_GT(bs.radius, 0.0);
}
TEST(ViewportApiTest, OrientationCubeFaceRight) {
// 朝向 +X → "right"
auto face = orientation_cube_face(Vector3D(1, 0, 0));
EXPECT_EQ(face, "right");
}
TEST(ViewportApiTest, OrientationCubeFaceLeft) {
// 朝向 -X → "left"
auto face = orientation_cube_face(Vector3D(-1, 0, 0));
EXPECT_EQ(face, "left");
}
TEST(ViewportApiTest, OrientationCubeFaceTop) {
// 朝向 +Z → "top"
auto face = orientation_cube_face(Vector3D(0, 0, 1));
EXPECT_EQ(face, "top");
}
TEST(ViewportApiTest, SceneGridBasic) {
auto grid = scene_grid(10.0, 1.0);
// 应生成网格线
EXPECT_GT(grid.lines.size(), 0u);
// 范围应对称
EXPECT_GT(grid.extent_x, 0.0);
EXPECT_GT(grid.extent_y, 0.0);
}
TEST(ViewportApiTest, GroundPlane) {
auto model = make_test_model();
std::vector<BrepModel> bodies = {model};
auto plane = ground_plane(bodies);
// 地平面法向量应朝上
EXPECT_NEAR(plane.normal.z(), 1.0, 1e-9);
}