真实缺口:transform rotate_x/y/z·rotate·mirror·mirror_about_plane(+6);Polygon2D perimeter/is_convex/simplify(+9);exact_point_in_polyhedron(+3);simd_vector dot3/intersect4/intersect4_count/aabb_intersect_batch*(新增 test_simd_vector 4 例)。逐点/逐字段对手写公式或独立标量复算。 假阳性:add_task/cache_line_count/prefetch_array/set_aos/invalidate_soa(vde_infra)、base32_encode(vde_license)、make_temp_file/delete_file/run_command(vde_platform)非 core;decompress_brep/edgebreaker_decompress/serialize/project 已有专测。
120 lines
4.2 KiB
C++
120 lines
4.2 KiB
C++
#include <gtest/gtest.h>
|
|
#include "vde/core/exact_predicates.h"
|
|
#include <vector>
|
|
#include <cmath>
|
|
|
|
using namespace vde::core;
|
|
|
|
TEST(ExactPredicatesTest, Orient2D_CounterClockwise) {
|
|
double r = exact_orient2d(0, 0, 1, 0, 0, 1);
|
|
EXPECT_GT(r, 0.0); // CCW
|
|
}
|
|
|
|
TEST(ExactPredicatesTest, Orient2D_Clockwise) {
|
|
double r = exact_orient2d(0, 0, 0, 1, 1, 0);
|
|
EXPECT_LT(r, 0.0);
|
|
}
|
|
|
|
TEST(ExactPredicatesTest, Orient2D_Collinear) {
|
|
double r = exact_orient2d(0, 0, 1, 1, 2, 2);
|
|
EXPECT_NEAR(r, 0.0, 1e-9);
|
|
}
|
|
|
|
TEST(ExactPredicatesTest, Orient3D_Above) {
|
|
// Tetrahedron: base on z=0, apex at z=1 → positive volume
|
|
double r = exact_orient3d(0,0,0, 1,0,0, 0,1,0, 0,0,1);
|
|
EXPECT_GT(r, 0.0);
|
|
}
|
|
|
|
TEST(ExactPredicatesTest, Orient3D_Coplanar) {
|
|
double r = exact_orient3d(0,0,0, 1,0,0, 0,1,0, 0.5,0.5,0);
|
|
EXPECT_NEAR(r, 0.0, 1e-9);
|
|
}
|
|
|
|
TEST(ExactPredicatesTest, InSphere_Inside) {
|
|
// Regular tetrahedron, point at centroid → inside circumsphere
|
|
double r = exact_in_sphere(0,0,0, 2,0,0, 0,2,0, 0,0,2, 0.2,0.2,0.2);
|
|
EXPECT_GT(r, 0.0);
|
|
}
|
|
|
|
TEST(ExactPredicatesTest, InSphere_OnSurface) {
|
|
double r = exact_in_sphere(0,0,0, 3,0,0, 0,3,0, 0,0,3, 0,0,3);
|
|
EXPECT_NEAR(r, 0.0, 1e-8);
|
|
}
|
|
|
|
TEST(ExactPredicatesTest, PointInPolygon_Inside) {
|
|
std::vector<Point3D> poly = {{0,0,0},{2,0,0},{2,2,0},{0,2,0}};
|
|
EXPECT_TRUE(exact_point_in_polygon({1,1,0}, poly));
|
|
}
|
|
|
|
TEST(ExactPredicatesTest, PointInPolygon_Outside) {
|
|
std::vector<Point3D> poly = {{0,0,0},{2,0,0},{2,2,0},{0,2,0}};
|
|
EXPECT_FALSE(exact_point_in_polygon({3,3,0}, poly));
|
|
}
|
|
|
|
TEST(ExactPredicatesTest, PointInPolygon_OnEdge) {
|
|
std::vector<Point3D> poly = {{0,0,0},{2,0,0},{2,2,0},{0,2,0}};
|
|
EXPECT_TRUE(exact_point_in_polygon({1,0,0}, poly));
|
|
}
|
|
|
|
TEST(ExactPredicatesTest, PrecisionMode) {
|
|
set_precision_mode(PrecisionMode::Fast);
|
|
EXPECT_EQ(precision_mode(), PrecisionMode::Fast);
|
|
|
|
set_precision_mode(PrecisionMode::Adaptive);
|
|
EXPECT_EQ(precision_mode(), PrecisionMode::Adaptive);
|
|
|
|
set_precision_mode(PrecisionMode::Adaptive); // restore default
|
|
}
|
|
|
|
TEST(ExactPredicatesTest, IsUncertain) {
|
|
EXPECT_TRUE(is_uncertain(1e-12));
|
|
EXPECT_FALSE(is_uncertain(1.0));
|
|
}
|
|
|
|
// ═══════════════════════════════════════════════════════════
|
|
// VDE-893: exact_point_in_polyhedron 未测试公开函数补测
|
|
// ═══════════════════════════════════════════════════════════
|
|
|
|
namespace {
|
|
|
|
// 单位立方体 [0,1]^3
|
|
std::vector<Point3D> unit_cube_vertices() {
|
|
return {{0, 0, 0}, {1, 0, 0}, {1, 1, 0}, {0, 1, 0},
|
|
{0, 0, 1}, {1, 0, 1}, {1, 1, 1}, {0, 1, 1}};
|
|
}
|
|
std::vector<std::vector<int>> unit_cube_faces() {
|
|
return {{0, 1, 2, 3}, {4, 5, 6, 7}, {0, 1, 5, 4},
|
|
{3, 2, 6, 7}, {1, 2, 6, 5}, {0, 3, 7, 4}};
|
|
}
|
|
|
|
} // namespace
|
|
|
|
TEST(ExactPredicatesTest, PointInPolyhedron_InsideCube) {
|
|
// 射线沿 +X;测试点取 y≠z 以避开 x 面扇形对角线(y=z)
|
|
auto v = unit_cube_vertices();
|
|
auto f = unit_cube_faces();
|
|
EXPECT_TRUE(exact_point_in_polyhedron({0.5, 0.3, 0.7}, v, f)); // 仅穿出 x=1 一次
|
|
EXPECT_TRUE(exact_point_in_polyhedron({0.2, 0.8, 0.4}, v, f));
|
|
}
|
|
|
|
TEST(ExactPredicatesTest, PointInPolyhedron_OutsideCube) {
|
|
auto v = unit_cube_vertices();
|
|
auto f = unit_cube_faces();
|
|
// −X 外侧:射线穿入 x=0、穿出 x=1 → 2 次 → 偶 → 外
|
|
EXPECT_FALSE(exact_point_in_polyhedron({-0.5, 0.3, 0.7}, v, f));
|
|
// +X 外侧:射线背离立方体 → 0 次
|
|
EXPECT_FALSE(exact_point_in_polyhedron({2.0, 0.3, 0.7}, v, f));
|
|
// +Y / +Z 外侧:射线整体在体外 → 0 次
|
|
EXPECT_FALSE(exact_point_in_polyhedron({0.5, 1.5, 0.3}, v, f));
|
|
EXPECT_FALSE(exact_point_in_polyhedron({0.5, 0.3, 1.5}, v, f));
|
|
}
|
|
|
|
TEST(ExactPredicatesTest, PointInPolyhedron_EmptyInputs) {
|
|
std::vector<Point3D> no_v;
|
|
std::vector<std::vector<int>> no_f;
|
|
EXPECT_FALSE(exact_point_in_polyhedron({0, 0, 0}, no_v, no_f));
|
|
EXPECT_FALSE(exact_point_in_polyhedron({0, 0, 0}, unit_cube_vertices(), no_f));
|
|
EXPECT_FALSE(exact_point_in_polyhedron({0, 0, 0}, no_v, unit_cube_faces()));
|
|
}
|