- Add 12 new test files: render/viewport_layout, render/section_view, boolean/polygon_offset, core/icp, core/voronoi, core/material_library, spatial/incremental_bvh, spatial/kd_tree, curves/bezier_surface, capi/capi_extended, and expand mesh/halfedge + mesh/delaunay - Fix 30+ compilation errors: missing includes, undefined symbols, circular dependencies, namespace issues, API mismatches - Implement missing functions: point_to_plane_icp, colored_icp, scale_aware_registration, polygon_offset_arc, multi_contour_offset, offset_quality_check, validate_style, available_standards, add_vertex_unique, angle_distribution - Fix infinite recursion in MaterialDatabase constructor - Fix polygon_offset normal direction (inward -> outward) - Fix viewport_bounds out-of-bounds handling - Add linker group flags for static library circular dependencies - 87% test pass rate (4479 tests, 592 pre-existing failures)
124 lines
4.2 KiB
C++
124 lines
4.2 KiB
C++
#include <gtest/gtest.h>
|
||
#include "vde/mesh/delaunay_2d.h"
|
||
|
||
using namespace vde::mesh;
|
||
|
||
TEST(DelaunayTest, FourPointsSquare) {
|
||
std::vector<Point2D> pts = {{0,0}, {1,0}, {1,1}, {0,1}};
|
||
auto result = delaunay_2d(pts);
|
||
EXPECT_GE(result.triangles.size(), 2u);
|
||
EXPECT_EQ(result.vertices.size(), 4u);
|
||
}
|
||
|
||
TEST(DelaunayTest, ThreePoints) {
|
||
std::vector<Point2D> pts = {{0,0}, {1,0}, {0,1}};
|
||
auto result = delaunay_2d(pts);
|
||
EXPECT_EQ(result.triangles.size(), 1u);
|
||
}
|
||
|
||
TEST(DelaunayTest, FivePointsStar) {
|
||
// 中心点 + 四个方向的点,形成十字/星形
|
||
std::vector<Point2D> pts = {{0,0}, {1,0}, {0,1}, {-1,0}, {0,-1}};
|
||
auto result = delaunay_2d(pts);
|
||
EXPECT_GT(result.triangles.size(), 3u);
|
||
}
|
||
|
||
TEST(DelaunayTest, ColinearPoints) {
|
||
// 所有点共线(退化情况),不应崩溃
|
||
std::vector<Point2D> pts = {{0,0}, {1,0}, {2,0}, {3,0}, {4,0}};
|
||
auto result = delaunay_2d(pts);
|
||
// 共线点无法形成有效三角形,但不应崩溃
|
||
(void)result;
|
||
}
|
||
|
||
TEST(DelaunayTest, ManyPointsRandom) {
|
||
// 生成 50 个伪随机点(确定性种子)
|
||
std::vector<Point2D> pts;
|
||
unsigned int seed = 12345;
|
||
for (int i = 0; i < 50; ++i) {
|
||
seed = seed * 1103515245 + 12345;
|
||
double x = static_cast<double>((seed >> 16) & 0x7FFF) / 32767.0 * 100.0;
|
||
seed = seed * 1103515245 + 12345;
|
||
double y = static_cast<double>((seed >> 16) & 0x7FFF) / 32767.0 * 100.0;
|
||
pts.push_back({x, y});
|
||
}
|
||
auto result = delaunay_2d(pts);
|
||
EXPECT_GT(result.triangles.size(), 0u);
|
||
EXPECT_GE(result.vertices.size(), pts.size());
|
||
}
|
||
|
||
TEST(DelaunayTest, TriangleVerticesMatchInput) {
|
||
// 所有输入点都应出现在结果顶点中
|
||
std::vector<Point2D> pts = {{0,0}, {3,0}, {3,4}, {0,4}, {1.5, 2}};
|
||
auto result = delaunay_2d(pts);
|
||
for (const auto& p : pts) {
|
||
bool found = false;
|
||
for (const auto& v : result.vertices) {
|
||
if (v[0] == p[0] && v[1] == p[1]) {
|
||
found = true;
|
||
break;
|
||
}
|
||
}
|
||
EXPECT_TRUE(found) << "Input point (" << p[0] << "," << p[1] << ") not found in result vertices";
|
||
}
|
||
}
|
||
|
||
TEST(DelaunayTest, TriangleIndicesValid) {
|
||
// 所有三角形索引应在 [0, vertices.size()) 范围内
|
||
std::vector<Point2D> pts = {{0,0}, {5,0}, {5,5}, {0,5}, {2,2}};
|
||
auto result = delaunay_2d(pts);
|
||
ASSERT_GT(result.vertices.size(), 0u);
|
||
for (const auto& tri : result.triangles) {
|
||
for (int idx : tri) {
|
||
EXPECT_GE(idx, 0);
|
||
EXPECT_LT(static_cast<size_t>(idx), result.vertices.size());
|
||
}
|
||
}
|
||
}
|
||
|
||
TEST(DelaunayTest, TriangleOrientationCCW) {
|
||
// 验证所有三角形为逆时针方向(有向面积为正)
|
||
std::vector<Point2D> pts = {{0,0}, {4,0}, {4,3}, {0,3}, {2,1}};
|
||
auto result = delaunay_2d(pts);
|
||
ASSERT_GT(result.vertices.size(), 0u);
|
||
for (const auto& tri : result.triangles) {
|
||
const auto& a = result.vertices[tri[0]];
|
||
const auto& b = result.vertices[tri[1]];
|
||
const auto& c = result.vertices[tri[2]];
|
||
// 有向面积的二倍:(b-a) × (c-a)
|
||
double cross = (b[0] - a[0]) * (c[1] - a[1]) - (c[0] - a[0]) * (b[1] - a[1]);
|
||
EXPECT_GT(cross, 0.0) << "Triangle not CCW: idx=(" << tri[0] << "," << tri[1] << "," << tri[2] << ")";
|
||
}
|
||
}
|
||
|
||
TEST(DelaunayTest, TwoPoints) {
|
||
// 仅两个点(退化),不应崩溃
|
||
std::vector<Point2D> pts = {{0,0}, {1,1}};
|
||
auto result = delaunay_2d(pts);
|
||
(void)result;
|
||
}
|
||
|
||
TEST(DelaunayTest, IdenticalPoints) {
|
||
// 多个点在同一位置,不应崩溃
|
||
std::vector<Point2D> pts = {{5,5}, {5,5}, {5,5}, {5,5}};
|
||
auto result = delaunay_2d(pts);
|
||
(void)result;
|
||
}
|
||
|
||
TEST(DelaunayTest, LargeCoordinates) {
|
||
// 大坐标值 (1e6),验证三角化有效
|
||
std::vector<Point2D> pts = {
|
||
{1e6, 1e6}, {1e6 + 100, 1e6}, {1e6 + 100, 1e6 + 100},
|
||
{1e6, 1e6 + 100}, {1e6 + 50, 1e6 + 50}
|
||
};
|
||
auto result = delaunay_2d(pts);
|
||
EXPECT_GT(result.triangles.size(), 0u);
|
||
// 验证索引有效
|
||
for (const auto& tri : result.triangles) {
|
||
for (int idx : tri) {
|
||
EXPECT_GE(idx, 0);
|
||
EXPECT_LT(static_cast<size_t>(idx), result.vertices.size());
|
||
}
|
||
}
|
||
}
|