Files
ViewDesignEngine/tests/regression/regression_snapshots.cpp
T
hm 1a78e8e191 fix: comprehensive test fixes and implementation bugs
Build system: fix VDE_BUILD_TYPE, MinGW big-obj, cross-platform temp dir
Core fixes: Matrix4D inverse, ExactPredicates sign, GJK overflow, VdeFormat weights, VRML/Collada IO
Test fixes: ObjectPool, Transaction paths, /tmp replacement, Matrix4D expectations
Result: 292/295 fast tests pass (99%)
2026-08-04 06:44:53 +08:00

805 lines
24 KiB
C++

/// @file test_regression_snapshots.cpp
/// @brief 回归快照测试 — 已知正确结果 vs 当前输出,防止回退
///
/// 覆盖:
/// 基本体素属性快照 (20)
/// 布尔运算结果快照 (20)
/// 格式导出/导入一致性 (20)
/// 拓扑修复前后对比 (10)
/// 边缘情况快照 (10)
/// 数值精度快照 (10)
/// 退化场景快照 (10)
/// — 总计 ~100 项
#include <gtest/gtest.h>
#include "vde/brep/brep.h"
#include "vde/brep/modeling.h"
#include "vde/brep/brep_boolean.h"
#include "vde/brep/brep_validate.h"
#include "vde/brep/brep_heal.h"
#include "vde/brep/step_export.h"
#include "vde/brep/step_import.h"
#include "vde/brep/iges_export.h"
#include "vde/brep/iges_import.h"
#include "vde/curves/nurbs_surface.h"
#include "vde/curves/surface_analysis.h"
#include "vde/core/point.h"
#include <cmath>
#include <cstdio>
#include <vector>
#include <string>
using namespace vde::brep;
using namespace vde::core;
using namespace vde::curves;
#define SNAP_TEST(name) TEST(RegressionSnapshots, name)
// ═══════════════════════════════════════════════════════════
// Helper: snapshot a BrepModel's basic properties
// ═══════════════════════════════════════════════════════════
struct Snapshot {
size_t vertices, edges, faces, bodies, surfaces;
bool valid;
};
Snapshot snap(const BrepModel& m) {
return {m.num_vertices(), m.num_edges(), m.num_faces(),
m.num_bodies(), m.num_surfaces(), m.is_valid()};
}
void expect_snapshot(const BrepModel& m, size_t min_v, size_t min_e,
size_t min_f, size_t nb, const char* tag) {
SCOPED_TRACE(tag);
auto s = snap(m);
EXPECT_GE(s.vertices, min_v) << "vertices too few";
EXPECT_GE(s.edges, min_e) << "edges too few";
EXPECT_GE(s.faces, min_f) << "faces too few";
EXPECT_EQ(s.bodies, nb) << "body count mismatch";
EXPECT_TRUE(s.valid) << "model should be valid";
}
// ═══════════════════════════════════════════════════════════
// 1. 基本体素属性快照 (20)
// ═══════════════════════════════════════════════════════════
SNAP_TEST(Primitive_Box_1x1x1) {
auto b = make_box(1,1,1);
expect_snapshot(b, 8, 12, 6, 1, "Box_1x1x1");
}
SNAP_TEST(Primitive_Box_2x3x4) {
auto b = make_box(2,3,4);
expect_snapshot(b, 8, 12, 6, 1, "Box_2x3x4");
}
SNAP_TEST(Primitive_Box_10x10x10) {
auto b = make_box(10,10,10);
expect_snapshot(b, 8, 12, 6, 1, "Box_10x10x10");
}
SNAP_TEST(Primitive_Box_Tiny) {
auto b = make_box(0.001, 0.001, 0.001);
expect_snapshot(b, 8, 12, 6, 1, "Box_Tiny");
}
SNAP_TEST(Primitive_Cylinder_R1H2) {
auto c = make_cylinder(1, 2, 8);
expect_snapshot(c, 4, 4, 1, 1, "Cyl_R1H2"); // approximate
auto s = snap(c);
EXPECT_GT(s.faces, 0u);
}
SNAP_TEST(Primitive_Cylinder_R2H5_16seg) {
auto c = make_cylinder(2, 5, 16);
auto s = snap(c);
EXPECT_GT(s.vertices, 0u);
EXPECT_GT(s.faces, 0u);
EXPECT_TRUE(s.valid);
}
SNAP_TEST(Primitive_Cylinder_HighSeg) {
auto c = make_cylinder(1, 3, 32);
auto s = snap(c);
EXPECT_GE(s.faces, 32u);
}
SNAP_TEST(Primitive_Sphere_R1) {
auto s = make_sphere(1, 16, 8);
auto sp = snap(s);
EXPECT_GT(sp.faces, 0u);
EXPECT_EQ(sp.bodies, 1u);
}
SNAP_TEST(Primitive_Sphere_R3) {
auto s = make_sphere(3, 24, 12);
auto sp = snap(s);
EXPECT_GT(sp.surfaces, 0u);
EXPECT_TRUE(sp.valid);
}
SNAP_TEST(Primitive_Sphere_HighRes) {
auto s = make_sphere(2, 32, 16);
auto sp = snap(s);
EXPECT_GE(sp.faces, 32u * 16u);
}
SNAP_TEST(Primitive_Cone_R2R1H4) {
auto c = make_cone(2, 1, 4, 16);
auto s = snap(c);
EXPECT_GT(s.faces, 0u);
EXPECT_TRUE(s.valid);
}
SNAP_TEST(Primitive_Cone_R3R0H6) {
auto c = make_cone(3, 0, 6, 24);
auto s = snap(c);
EXPECT_GT(s.faces, 0u);
}
SNAP_TEST(Primitive_Torus_R5R1) {
auto t = make_torus(5, 1, 16, 8);
auto s = snap(t);
EXPECT_GT(s.faces, 0u);
EXPECT_TRUE(s.valid);
}
SNAP_TEST(Primitive_Torus_R3R05_HighRes) {
auto t = make_torus(3, 0.5, 32, 16);
auto s = snap(t);
EXPECT_GE(s.faces, 32u * 16u);
}
SNAP_TEST(Primitive_IsValid_Box) { EXPECT_TRUE(make_box(2,2,2).is_valid()); }
SNAP_TEST(Primitive_IsValid_Cyl) { EXPECT_TRUE(make_cylinder(1,3,16).is_valid()); }
SNAP_TEST(Primitive_IsValid_Sphere){ EXPECT_TRUE(make_sphere(1,12,6).is_valid()); }
SNAP_TEST(Primitive_IsValid_Cone) { EXPECT_TRUE(make_cone(2,1,4,12).is_valid()); }
SNAP_TEST(Primitive_IsValid_Torus) { EXPECT_TRUE(make_torus(4,1,16,8).is_valid()); }
SNAP_TEST(Primitive_NumBodies_Box) { EXPECT_EQ(make_box(1,2,3).num_bodies(), 1u); }
// 20 tests ✓
// ═══════════════════════════════════════════════════════════
// 2. 布尔运算结果快照 (20)
// ═══════════════════════════════════════════════════════════
SNAP_TEST(Boolean_Union_BoxBox_ResultHasFaces) {
auto r = brep_union(make_box(2,2,2), make_box(2,2,2, Point3D(1,0,0)));
EXPECT_GT(r.num_faces(), 0u);
EXPECT_TRUE(r.is_valid());
}
SNAP_TEST(Boolean_Intersection_BoxBox_HasFaces) {
auto r = brep_intersection(make_box(2,2,2), make_box(2,2,2, Point3D(1,0,0)));
EXPECT_TRUE(r.is_valid());
}
SNAP_TEST(Boolean_Difference_BoxBox_Valid) {
auto r = brep_difference(make_box(2,2,2), make_box(2,2,2, Point3D(1,0,0)));
EXPECT_TRUE(r.is_valid());
}
SNAP_TEST(Boolean_Union_CylSphere_Valid) {
auto r = brep_union(make_cylinder(2,4,16), make_sphere(2,12,6));
EXPECT_TRUE(r.is_valid());
EXPECT_GT(r.num_faces(), 0u);
}
SNAP_TEST(Boolean_Intersection_CylSphere_HasFacesOrEmpty) {
auto r = brep_intersection(make_cylinder(1,3,12), make_sphere(2,8,4));
EXPECT_TRUE(r.is_valid());
}
SNAP_TEST(Boolean_Difference_BoxCyl_ConsistentTopology) {
auto r = brep_difference(make_box(3,3,3), make_cylinder(1,10,16));
EXPECT_TRUE(r.is_valid());
// After subtracting a cylinder that goes through, the result should still have faces
EXPECT_GT(r.num_faces(), 0u);
}
SNAP_TEST(Boolean_SelfUnion_IdenticalBodies) {
auto a = make_box(2,2,2);
auto r = brep_union(a, a);
EXPECT_TRUE(r.is_valid());
EXPECT_GT(r.num_faces(), 0u);
}
SNAP_TEST(Boolean_SelfIntersection_IdenticalBodies) {
auto a = make_sphere(3, 16, 8);
auto r = brep_intersection(a, a);
EXPECT_TRUE(r.is_valid());
}
SNAP_TEST(Boolean_SelfDifference_ProducesEmptyOrValid) {
auto a = make_box(2,2,2);
auto r = brep_difference(a, a);
// Self-difference may produce empty body — should not crash
EXPECT_NO_THROW({ (void)r.is_valid(); });
}
SNAP_TEST(Boolean_Union_ThreeBodies) {
auto a = make_box(2,2,2);
auto b = make_cylinder(1,4,12, Point3D(1.5, 0, 0));
auto c = make_sphere(1, 8, 4, Point3D(-1, 0, 0));
auto ab = brep_union(a, b);
auto abc = brep_union(ab, c);
EXPECT_TRUE(abc.is_valid());
EXPECT_GT(abc.num_faces(), 0u);
}
SNAP_TEST(Boolean_Union_SphereChain) {
BrepModel r = make_sphere(0.5, 8, 4);
for (int i = 0; i < 5; ++i) {
r = brep_union(r, make_sphere(0.5, 8, 4, Point3D(i*0.8, 0, 0)));
}
EXPECT_TRUE(r.is_valid());
EXPECT_GT(r.num_faces(), 10u);
}
SNAP_TEST(Boolean_Diff_MultipleCuts) {
BrepModel r = make_box(5,5,5);
for (int i = 0; i < 3; ++i) {
r = brep_difference(r, make_cylinder(0.8, 10, 12,
Point3D(-2 + i*2, 0, 0)));
}
EXPECT_TRUE(r.is_valid());
EXPECT_GT(r.num_faces(), 0u);
}
SNAP_TEST(Boolean_IntersectionProgressive) {
BrepModel r = make_sphere(5, 16, 8);
for (int i = 0; i < 3; ++i) {
r = brep_intersection(r, make_sphere(5 - i*0.5, 12, 6));
}
EXPECT_TRUE(r.is_valid());
}
SNAP_TEST(Boolean_PointTouch_Union) {
auto a = make_sphere(1, 12, 6, Point3D(0,0,0));
auto b = make_sphere(1, 12, 6, Point3D(0,0,2));
auto r = brep_union(a, b);
EXPECT_TRUE(r.is_valid());
}
SNAP_TEST(Boolean_BarelyOverlapping) {
auto a = make_box(2,2,2);
auto b = make_box(2,2,2, Point3D(1.999, 0, 0));
auto r = brep_union(a, b);
EXPECT_TRUE(r.is_valid());
}
SNAP_TEST(Boolean_ComplexMixture) {
auto a = make_box(3,3,3);
auto b = make_cylinder(1.5, 6, 16);
auto c = make_sphere(2, 12, 6, Point3D(1, 1, 0));
auto ab = brep_difference(a, b);
auto abc = brep_union(ab, c);
EXPECT_TRUE(abc.is_valid());
}
SNAP_TEST(Boolean_TorusBox_Valid) {
auto t = make_torus(4, 1, 16, 8);
auto b = make_box(3,3,3);
auto r = brep_union(t, b);
EXPECT_TRUE(r.is_valid());
}
SNAP_TEST(Boolean_ConeBox_Valid) {
auto c = make_cone(2, 1, 4, 16);
auto b = make_box(2,2,2);
auto r = brep_union(c, b);
EXPECT_TRUE(r.is_valid());
}
SNAP_TEST(Boolean_ManyToMany) {
std::vector<BrepModel> parts;
for (int i = 0; i < 5; ++i)
parts.push_back(make_box(0.5, 0.5, 0.5, Point3D(i*0.8, 0, 0)));
BrepModel result = parts[0];
for (size_t i = 1; i < parts.size(); ++i)
result = brep_union(result, parts[i]);
EXPECT_TRUE(result.is_valid());
EXPECT_GT(result.num_faces(), 0u);
}
SNAP_TEST(Boolean_EdgeCase_ZeroVolumeIntersection) {
// Bodies with barely any intersection should still behave
auto a = make_box(2,2,2);
auto b = make_box(2,2,2, Point3D(2.0000001, 0, 0));
EXPECT_NO_THROW({
auto r = brep_intersection(a, b);
(void)r.is_valid();
});
}
// 20 tests ✓
// ═══════════════════════════════════════════════════════════
// 3. 格式导出/导入一致性 (20)
// ═══════════════════════════════════════════════════════════
SNAP_TEST(Format_STEP_Box_Roundtrip_Consistent) {
auto box = make_box(2,3,4);
const char* tf = VDE_TEST_TEMP_DIR "snap_box.stp";
EXPECT_TRUE(export_step_file(tf, {box}));
auto imported = import_step(tf);
ASSERT_GE(imported.size(), 1u);
EXPECT_GT(imported[0].num_faces(), 0u);
EXPECT_TRUE(imported[0].is_valid());
std::remove(tf);
}
SNAP_TEST(Format_STEP_Sphere_Roundtrip_Valid) {
auto s = make_sphere(3, 16, 8);
const char* tf = VDE_TEST_TEMP_DIR "snap_sph.stp";
EXPECT_TRUE(export_step_file(tf, {s}));
auto imported = import_step(tf);
ASSERT_GE(imported.size(), 1u);
EXPECT_TRUE(imported[0].is_valid());
std::remove(tf);
}
SNAP_TEST(Format_STEP_Cylinder_Roundtrip_Faces) {
auto c = make_cylinder(2, 5, 24);
const char* tf = VDE_TEST_TEMP_DIR "snap_cyl.stp";
EXPECT_TRUE(export_step_file(tf, {c}));
auto imported = import_step(tf);
ASSERT_GE(imported.size(), 1u);
EXPECT_GT(imported[0].num_faces(), 0u);
std::remove(tf);
}
SNAP_TEST(Format_STEP_Cone_Roundtrip) {
auto c = make_cone(2, 1, 4, 16);
const char* tf = VDE_TEST_TEMP_DIR "snap_cone.stp";
EXPECT_TRUE(export_step_file(tf, {c}));
auto imported = import_step(tf);
ASSERT_GE(imported.size(), 1u);
EXPECT_GT(imported[0].num_faces(), 0u);
std::remove(tf);
}
SNAP_TEST(Format_STEP_Torus_Roundtrip) {
auto t = make_torus(5, 1, 16, 8);
const char* tf = VDE_TEST_TEMP_DIR "snap_torus.stp";
EXPECT_TRUE(export_step_file(tf, {t}));
auto imported = import_step(tf);
ASSERT_GE(imported.size(), 1u);
EXPECT_GT(imported[0].num_faces(), 0u);
std::remove(tf);
}
SNAP_TEST(Format_STEP_String_NonEmpty) {
auto b = make_box(2,2,2);
auto str = export_step({b});
EXPECT_GT(str.size(), 100u);
}
SNAP_TEST(Format_STEP_String_ContainsHeader) {
auto b = make_box(2,2,2);
auto str = export_step({b});
EXPECT_NE(str.find("ISO-10303-21"), std::string::npos);
EXPECT_NE(str.find("ENDSEC"), std::string::npos);
}
SNAP_TEST(Format_STEP_String_ContainsProduct) {
auto b = make_box(2,2,2);
auto str = export_step({b});
EXPECT_NE(str.find("PRODUCT"), std::string::npos);
}
SNAP_TEST(Format_STEP_ImportString_Roundtrip) {
auto b = make_box(3,3,3);
auto str = export_step({b});
auto imported = import_step_from_string(str);
ASSERT_GE(imported.size(), 1u);
EXPECT_GT(imported[0].num_faces(), 0u);
}
SNAP_TEST(Format_STEP_MultiBody_ExportImport) {
std::vector<BrepModel> parts;
parts.push_back(make_box(1,1,1));
parts.push_back(make_cylinder(1,2,12));
auto str = export_step(parts);
auto imported = import_step_from_string(str);
EXPECT_GE(imported.size(), 1u);
}
SNAP_TEST(Format_STEP_EmptyBodies_ProducesValidString) {
auto str = export_step({});
EXPECT_FALSE(str.empty());
}
SNAP_TEST(Format_STEP_ImportNonExistent_ReturnsEmpty) {
auto bodies = import_step(VDE_TEST_TEMP_DIR "nonexistent_snap_test_xyz.stp");
EXPECT_TRUE(bodies.empty());
}
SNAP_TEST(Format_STEP_ImportGarbage_ReturnsEmpty) {
auto bodies = import_step_from_string("not a valid step file content");
EXPECT_TRUE(bodies.empty());
}
SNAP_TEST(Format_STEP_ErrorHandling) {
auto bodies = import_step(VDE_TEST_TEMP_DIR "nonexistent_snap_test_xyz.stp");
EXPECT_TRUE(bodies.empty());
auto err = step_last_error();
EXPECT_NO_THROW({ (void)err; });
auto msg = step_last_error_message();
EXPECT_NO_THROW({ (void)msg; });
}
SNAP_TEST(Format_STEP_Diagnostics) {
auto b = make_box(1,1,1);
auto str = export_step({b});
auto imported = import_step_from_string(str);
(void)imported;
auto report = step_import_diagnostic();
EXPECT_GE(report.total_entities, 0);
}
SNAP_TEST(Format_IGES_Box_Roundtrip) {
auto b = make_box(2,3,4);
const char* tf = VDE_TEST_TEMP_DIR "snap_box.igs";
EXPECT_TRUE(export_iges_file(tf, {b}));
auto imported = import_iges(tf);
EXPECT_GE(imported.size(), 1u);
std::remove(tf);
}
SNAP_TEST(Format_IGES_Cylinder_Roundtrip) {
auto c = make_cylinder(1.5, 3, 16);
const char* tf = VDE_TEST_TEMP_DIR "snap_cyl.igs";
EXPECT_TRUE(export_iges_file(tf, {c}));
auto imported = import_iges(tf);
EXPECT_GE(imported.size(), 1u);
std::remove(tf);
}
SNAP_TEST(Format_IGES_NonExistent_ReturnsEmpty) {
auto bodies = import_iges(VDE_TEST_TEMP_DIR "nonexistent_snap_test_xyz.igs");
EXPECT_TRUE(bodies.empty());
}
SNAP_TEST(Format_STEP_LargeCoordinate) {
auto b = make_box(1,1,1, Point3D(1e6, 1e6, 1e6));
auto str = export_step({b});
EXPECT_GT(str.size(), 0u);
auto imported = import_step_from_string(str);
EXPECT_GE(imported.size(), 1u);
}
SNAP_TEST(Format_STEP_NegativeCoordinate) {
auto b = make_box(1,1,1, Point3D(-1e6, -1e6, -1e6));
auto str = export_step({b});
auto imported = import_step_from_string(str);
EXPECT_GE(imported.size(), 1u);
}
// 20 tests ✓
// ═══════════════════════════════════════════════════════════
// 4. 拓扑修复前后对比 (10)
// ═══════════════════════════════════════════════════════════
SNAP_TEST(Heal_Box_HealDoesNotBreak) {
auto body = make_box(2,2,2);
EXPECT_NO_THROW({ heal_topology(body, 1e-6); });
EXPECT_TRUE(body.is_valid());
}
SNAP_TEST(Heal_Cylinder_HealMaintainsFaces) {
auto body = make_cylinder(2, 4, 16);
size_t before = body.num_faces();
heal_topology(body, 1e-6);
EXPECT_GT(body.num_faces(), 0u);
EXPECT_TRUE(body.is_valid());
}
SNAP_TEST(Heal_Sphere_HealMaintainsValidity) {
auto body = make_sphere(3, 16, 8);
heal_topology(body, 1e-6);
EXPECT_TRUE(body.is_valid());
}
SNAP_TEST(Heal_BooleanResult_Heal) {
auto a = make_box(3,3,3);
auto b = make_cylinder(1.5, 6, 16);
auto r = brep_union(a, b);
heal_topology(r, 1e-6);
EXPECT_TRUE(r.is_valid());
auto v = validate(r);
EXPECT_EQ(v.dangling_edges, 0u);
}
SNAP_TEST(Heal_TightTolerance) {
auto body = make_box(2,2,2);
heal_topology(body, 1e-9);
EXPECT_TRUE(body.is_valid());
}
SNAP_TEST(Heal_LooseTolerance) {
auto body = make_sphere(5, 16, 8);
heal_topology(body, 1e-3);
EXPECT_TRUE(body.is_valid());
}
SNAP_TEST(Heal_ComplexBoolean_Heal) {
auto a = make_box(4,4,4);
auto b = make_cylinder(1.5, 10, 24);
auto c = make_sphere(2.5, 16, 8, Point3D(2,0,0));
auto r = brep_union(a, b);
r = brep_difference(r, c);
heal_topology(r, 1e-6);
EXPECT_TRUE(r.is_valid());
}
SNAP_TEST(Heal_ValidateBeforeAfter) {
auto body = make_box(2,2,2);
auto v_before = validate(body);
heal_topology(body, 1e-6);
auto v_after = validate(body);
EXPECT_GE(v_after.watertightness, 0.0);
}
SNAP_TEST(Heal_ChainHeal) {
auto body = make_cylinder(2, 5, 16);
for (int i = 0; i < 3; ++i) {
heal_topology(body, 1e-6);
EXPECT_TRUE(body.is_valid());
body = brep_union(body, make_box(0.5, 0.5, 0.5, Point3D(i*0.6, 0, 0)));
}
}
SNAP_TEST(Heal_DegenerateCase) {
auto body = make_box(0.0, 2, 2);
EXPECT_NO_THROW({ heal_topology(body, 1e-6); });
}
// 10 tests ✓
// ═══════════════════════════════════════════════════════════
// 5. 边缘情况快照 (10)
// ═══════════════════════════════════════════════════════════
SNAP_TEST(Edge_ZeroDimensionBox) {
auto b = make_box(0, 2, 2);
EXPECT_NO_THROW({ (void)b.is_valid(); });
}
SNAP_TEST(Edge_TinyBox) {
auto b = make_box(1e-12, 1e-12, 1e-12);
EXPECT_NO_THROW({ (void)b.is_valid(); });
}
SNAP_TEST(Edge_HugeCoordinates) {
auto b = make_box(1, 1, 1, Point3D(1e12, 1e12, 1e12));
auto str = export_step({b});
EXPECT_GT(str.size(), 0u);
}
SNAP_TEST(Edge_OverlappingIdenticalBodies) {
auto a = make_box(2,2,2);
auto r = brep_union(a, a);
EXPECT_TRUE(r.is_valid());
}
SNAP_TEST(Edge_FarApartBodies) {
auto a = make_box(1,1,1, Point3D(0,0,0));
auto b = make_box(1,1,1, Point3D(1000,1000,1000));
EXPECT_NO_THROW({ auto u = brep_union(a, b); (void)u.is_valid(); });
}
SNAP_TEST(Edge_ValidateEmptyModel) {
BrepModel empty;
EXPECT_NO_THROW({
auto v = validate(empty);
(void)v;
});
}
SNAP_TEST(Edge_HealEmptyModel) {
BrepModel empty;
EXPECT_NO_THROW({ heal_topology(empty, 1e-6); });
}
SNAP_TEST(Edge_NestedBoolean) {
auto outer = make_box(5,5,5);
auto inner = make_box(3,3,3, Point3D(0,0,0));
auto r = brep_difference(outer, inner);
EXPECT_TRUE(r.is_valid());
EXPECT_GT(r.num_faces(), 0u);
}
SNAP_TEST(Edge_ChainToDegeneration) {
BrepModel r = make_sphere(2, 12, 6);
for (int i = 0; i < 10; ++i) {
r = brep_intersection(r, make_box(4, 4, 4, Point3D(0, 0, 0)));
}
EXPECT_NO_THROW({ (void)r.is_valid(); });
}
SNAP_TEST(Edge_STEP_ExportEmptyModel) {
BrepModel empty;
EXPECT_NO_THROW({
auto str = export_step({empty});
(void)str;
});
}
// 10 tests ✓
// ═══════════════════════════════════════════════════════════
// 6. 数值精度快照 (10)
// ═══════════════════════════════════════════════════════════
SNAP_TEST(Precision_BoxBounds_Exact) {
auto b = make_box(2, 4, 6);
auto bb = b.bounds();
EXPECT_NEAR(bb.min().x(), -1.0, 1e-10);
EXPECT_NEAR(bb.max().x(), 1.0, 1e-10);
EXPECT_NEAR(bb.min().y(), -2.0, 1e-10);
EXPECT_NEAR(bb.max().y(), 2.0, 1e-10);
EXPECT_NEAR(bb.min().z(), -3.0, 1e-10);
EXPECT_NEAR(bb.max().z(), 3.0, 1e-10);
}
SNAP_TEST(Precision_SphereRadius_Check) {
auto s = make_sphere(3, 16, 8);
auto bb = s.bounds();
EXPECT_NEAR(bb.extent().x(), 6.0, 0.2);
EXPECT_NEAR(bb.extent().y(), 6.0, 0.2);
EXPECT_NEAR(bb.extent().z(), 6.0, 0.2);
}
SNAP_TEST(Precision_CylinderRadius_Check) {
auto c = make_cylinder(2, 4, 32);
auto bb = c.bounds();
EXPECT_NEAR(bb.extent().x(), 4.0, 0.1);
EXPECT_NEAR(bb.extent().z(), 4.0, 0.1);
}
SNAP_TEST(Precision_OffsetBox_Bounds) {
auto b = make_box(2,2,2, Point3D(5, 10, 15));
auto bb = b.bounds();
EXPECT_NEAR(bb.min().x(), 4.0, 1e-10);
EXPECT_NEAR(bb.max().x(), 6.0, 1e-10);
EXPECT_NEAR(bb.min().y(), 9.0, 1e-10);
EXPECT_NEAR(bb.max().y(), 11.0, 1e-10);
EXPECT_NEAR(bb.min().z(), 14.0, 1e-10);
EXPECT_NEAR(bb.max().z(), 16.0, 1e-10);
}
SNAP_TEST(Precision_VertexCoordinates) {
auto b = make_box(2,2,2);
const auto& v = b.vertex(0);
EXPECT_TRUE(std::isfinite(v.point.x()));
EXPECT_TRUE(std::isfinite(v.point.y()));
EXPECT_TRUE(std::isfinite(v.point.z()));
}
SNAP_TEST(Precision_NurbsSurface_Evaluate_Finite) {
std::vector<std::vector<Point3D>> cp = {
{Point3D(0,0,0), Point3D(0,1,0)},
{Point3D(1,0,0), Point3D(1,1,0)}
};
NurbsSurface s(cp, {0,0,1,1}, {0,0,1,1}, {}, 1, 1);
auto p = s.evaluate(0.5, 0.5);
EXPECT_NEAR(p.z(), 0.0, 1e-10);
}
SNAP_TEST(Precision_NurbsSurface_Derivative_Finite) {
std::vector<std::vector<Point3D>> cp = {
{Point3D(0,0,0), Point3D(0,1,0)},
{Point3D(1,0,0), Point3D(1,1,0)}
};
NurbsSurface s(cp, {0,0,1,1}, {0,0,1,1}, {}, 1, 1);
auto du = s.derivative_u(0.5, 0.5);
EXPECT_NEAR(du.x(), 1.0, 1e-10);
EXPECT_NEAR(du.y(), 0.0, 1e-10);
}
SNAP_TEST(Precision_NurbsSurface_Normal_Check) {
std::vector<std::vector<Point3D>> cp = {
{Point3D(0,0,0), Point3D(0,1,0)},
{Point3D(1,0,0), Point3D(1,1,0)}
};
NurbsSurface s(cp, {0,0,1,1}, {0,0,1,1}, {}, 1, 1);
auto n = s.normal(0.5, 0.5);
EXPECT_NEAR(n.x(), 0.0, 1e-10);
EXPECT_NEAR(n.y(), 0.0, 1e-10);
EXPECT_NEAR(std::abs(n.z()), 1.0, 1e-10);
}
SNAP_TEST(Precision_EdgeLength_Finite) {
auto b = make_box(2,2,2);
const auto& e = b.edge(0);
const auto& v0 = b.vertex(e.v_start);
const auto& v1 = b.vertex(e.v_end);
double len = (v1.point - v0.point).norm();
EXPECT_GT(len, 0.0);
EXPECT_TRUE(std::isfinite(len));
}
SNAP_TEST(Precision_FaceArea_Finite) {
auto b = make_box(2,2,2);
auto mesh = b.to_mesh();
EXPECT_GT(mesh.num_faces(), 0u);
EXPECT_GT(mesh.num_vertices(), 0u);
}
// 10 tests ✓
// ═══════════════════════════════════════════════════════════
// 7. 退化场景快照 (10)
// ═══════════════════════════════════════════════════════════
SNAP_TEST(Degenerate_FlatBox_Valid) {
auto b = make_box(2, 0, 2);
EXPECT_NO_THROW({ (void)b.is_valid(); });
}
SNAP_TEST(Degenerate_CoplanarBoolean) {
auto a = make_box(2,2,2);
auto b = make_box(2,2,2, Point3D(1, 0, 0));
auto r = brep_union(a, b);
EXPECT_TRUE(r.is_valid());
}
SNAP_TEST(Degenerate_ThinWallValid) {
auto a = make_box(3,3,3);
auto b = make_box(2.99, 3, 2.99, Point3D(0,0,0));
auto r = brep_difference(a, b);
EXPECT_NO_THROW({ (void)r.is_valid(); });
}
SNAP_TEST(Degenerate_MinimalSphere) {
auto s = make_sphere(1e-12, 4, 2);
EXPECT_NO_THROW({ (void)s.is_valid(); });
}
SNAP_TEST(Degenerate_NarrowCylinder) {
auto c = make_cylinder(1e-12, 5, 8);
EXPECT_NO_THROW({ (void)c.is_valid(); });
}
SNAP_TEST(Degenerate_ZeroCone) {
auto c = make_cone(0, 0, 3, 8);
EXPECT_NO_THROW({ (void)c.is_valid(); });
}
SNAP_TEST(Degenerate_BooleanWithZeroBox) {
auto a = make_box(2,2,2);
auto b = make_box(0, 0, 0);
EXPECT_NO_THROW({ auto r = brep_union(a, b); (void)r; });
}
SNAP_TEST(Degenerate_HealFlatBody) {
auto body = make_box(3, 1e-12, 3);
EXPECT_NO_THROW({ heal_topology(body, 1e-6); });
}
SNAP_TEST(Degenerate_STEP_FlatBody) {
auto body = make_box(3, 1e-6, 3);
auto str = export_step({body});
EXPECT_GT(str.size(), 0u);
}
SNAP_TEST(Degenerate_ValidateDegenerateBody) {
auto body = make_box(0, 3, 3);
EXPECT_NO_THROW({ auto v = validate(body); (void)v; });
}
// 10 tests ✓
// ===== Total: 20+20+20+10+10+10+10 = 100 tests ✓