- F9: SweepOption.reference_surface 参考面定向(域采样+Gauss-Newton 精化) - F10: Catmull-Clark 细分 → NURBS 转换(subdivision 模块) - F11: 两阶段 B-spline 点云网格逆向重建(reconstruction 模块) - F12: 参数化公式/特征引擎最小实现(parameterization 模块) - W1: vertex_by_id 索引优先解析(链圆角崩溃根因) - W3: 带孔环顺时针绕数修正(裁剪岛) - W4: A 级光顺 Bezier 区间修正 + G2 迭代计数 - 截面/裁剪修复:整边在平面返回端点、共享边交点去重配对、Sutherland-Hodgman 半空间裁剪、柱面相切截面退化处理 测试:新增 3 个模块测试(细分 9/重建 7/参数化 10)+ 加固回归全通过
154 lines
5.3 KiB
C++
154 lines
5.3 KiB
C++
#include <gtest/gtest.h>
|
||
#include "vde/brep/section_view.h"
|
||
#include "vde/brep/modeling.h"
|
||
#include <cmath>
|
||
|
||
using namespace vde::brep;
|
||
using namespace vde::core;
|
||
|
||
// ═══════════════════════════════════════════════════════════
|
||
// section_plane
|
||
// ═══════════════════════════════════════════════════════════
|
||
|
||
TEST(SectionViewTest, SectionPlane_Basic) {
|
||
auto box = make_box(10, 10, 10);
|
||
|
||
// Section through the center in X direction (YZ plane at x=0)
|
||
auto curves = section_plane(box, Point3D::Zero(), Vector3D::UnitX());
|
||
|
||
// Should produce at least one section curve
|
||
EXPECT_GT(curves.size(), 0u);
|
||
}
|
||
|
||
TEST(SectionViewTest, SectionPlane_OutsideBody) {
|
||
auto box = make_box(10, 10, 10);
|
||
|
||
// Section plane far away from the box
|
||
auto curves = section_plane(box, Point3D(100, 0, 0), Vector3D::UnitX());
|
||
|
||
// No intersection → empty
|
||
EXPECT_EQ(curves.size(), 0u);
|
||
}
|
||
|
||
TEST(SectionViewTest, SectionPlane_DifferentDirections) {
|
||
auto box = make_box(10, 10, 10);
|
||
|
||
// X-normal section
|
||
auto cx = section_plane(box, Point3D::Zero(), Vector3D::UnitX());
|
||
// Y-normal section
|
||
auto cy = section_plane(box, Point3D::Zero(), Vector3D::UnitY());
|
||
// Z-normal section
|
||
auto cz = section_plane(box, Point3D::Zero(), Vector3D::UnitZ());
|
||
|
||
// All should produce curves for this box
|
||
EXPECT_GT(cx.size(), 0u);
|
||
EXPECT_GT(cy.size(), 0u);
|
||
EXPECT_GT(cz.size(), 0u);
|
||
}
|
||
|
||
TEST(SectionViewTest, SectionPlane_CurveValidity) {
|
||
auto box = make_box(10, 10, 10);
|
||
|
||
auto curves = section_plane(box, Point3D::Zero(), Vector3D::UnitZ());
|
||
|
||
for (const auto& c : curves) {
|
||
// Each curve should have control points
|
||
EXPECT_GT(c.control_points().size(), 0u);
|
||
}
|
||
}
|
||
|
||
// ═══════════════════════════════════════════════════════════
|
||
// clip_body
|
||
// ═══════════════════════════════════════════════════════════
|
||
|
||
TEST(SectionViewTest, ClipBody_KeepPositive) {
|
||
auto box = make_box(10, 10, 10);
|
||
|
||
// Clip at x=0, keep positive half-space (x > 0)
|
||
auto clipped = clip_body(box, Point3D::Zero(), Vector3D::UnitX(), true);
|
||
|
||
EXPECT_TRUE(clipped.is_valid());
|
||
auto b = clipped.bounds();
|
||
// Clipped box should have its x min near 0
|
||
EXPECT_GE(b.min().x(), -1.0);
|
||
}
|
||
|
||
TEST(SectionViewTest, ClipBody_KeepNegative) {
|
||
auto box = make_box(10, 10, 10);
|
||
|
||
// Clip at x=0, keep negative half-space (x < 0)
|
||
auto clipped = clip_body(box, Point3D::Zero(), Vector3D::UnitX(), false);
|
||
|
||
EXPECT_TRUE(clipped.is_valid());
|
||
auto b = clipped.bounds();
|
||
// Clipped box should have its x max near 0
|
||
EXPECT_LE(b.max().x(), 1.0);
|
||
}
|
||
|
||
TEST(SectionViewTest, ClipBody_FarPlane) {
|
||
auto box = make_box(10, 10, 10);
|
||
|
||
// Clip plane far away from the box
|
||
auto clipped = clip_body(box, Point3D(100, 0, 0), Vector3D::UnitX(), true);
|
||
|
||
// Box should be entirely in the keep-positive half-space
|
||
EXPECT_TRUE(clipped.is_valid());
|
||
}
|
||
|
||
TEST(SectionViewTest, ClipBody_ReducesVolume) {
|
||
auto box = make_box(10, 10, 10);
|
||
double original_vol = box.bounds().volume();
|
||
|
||
// Clip in half
|
||
auto clipped = clip_body(box, Point3D::Zero(), Vector3D::UnitX(), true);
|
||
double clipped_vol = clipped.bounds().volume();
|
||
|
||
// Clipped volume should be less than or equal to original
|
||
EXPECT_LE(clipped_vol, original_vol);
|
||
}
|
||
|
||
// ═══════════════════════════════════════════════════════════
|
||
// cross_section_extents
|
||
// ═══════════════════════════════════════════════════════════
|
||
|
||
TEST(SectionViewTest, CrossSectionExtents_Basic) {
|
||
auto box = make_box(10, 10, 10);
|
||
|
||
// 5 slices along X axis
|
||
auto areas = cross_section_extents(box, Vector3D::UnitX(), 5);
|
||
|
||
EXPECT_EQ(areas.size(), 5u);
|
||
// All areas should be positive (~100 each for a 10×10 box)
|
||
for (double a : areas) {
|
||
EXPECT_GT(a, 0.0);
|
||
EXPECT_NEAR(a, 100.0, 10.0);
|
||
}
|
||
}
|
||
|
||
TEST(SectionViewTest, CrossSectionExtents_TwoSlices) {
|
||
auto box = make_box(10, 6, 4);
|
||
|
||
auto areas = cross_section_extents(box, Vector3D::UnitX(), 2);
|
||
|
||
EXPECT_EQ(areas.size(), 2u);
|
||
EXPECT_GT(areas[0], 0.0);
|
||
EXPECT_GT(areas[1], 0.0);
|
||
}
|
||
|
||
TEST(SectionViewTest, CrossSectionExtents_Cylinder) {
|
||
auto cyl = make_cylinder(3.0, 20.0);
|
||
|
||
// Slices along the cylinder axis (X for default cylinder orientation)
|
||
auto areas = cross_section_extents(cyl, Vector3D::UnitX(), 5);
|
||
|
||
EXPECT_EQ(areas.size(), 5u);
|
||
// 两端切片恰好与圆柱表面相切(截面退化为直线),面积允许为 0;
|
||
// 中间切片应具有非零截面积(矩形 2r × h ≈ 120)。
|
||
int nonzero = 0;
|
||
for (double a : areas) {
|
||
EXPECT_GE(a, 0.0);
|
||
if (a > 0.0) ++nonzero;
|
||
}
|
||
EXPECT_GE(nonzero, 3);
|
||
}
|