From a5166262520045e26fe0396c966753fd79a83bf7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8C=82=E4=B9=8B=E9=92=B3?= Date: Thu, 23 Jul 2026 23:26:46 +0000 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=80=A7=E8=83=BD=E5=9F=BA=E5=87=86?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E5=A5=97=E4=BB=B6=20=E2=80=94=20M3=20?= =?UTF-8?q?=E9=87=8C=E7=A8=8B=E7=A2=91=E8=B5=B7=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 10 ++++++++++ CMakeLists.txt | 5 +++++ bench/bench_boolean.cpp | 32 ++++++++------------------------ docs/00-开发计划.md | 2 +- 4 files changed, 24 insertions(+), 25 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d6e6705..59c7c1e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,16 @@ ## [0.9.0] — 2026-07-23 +### M3 里程碑起步 — 性能基准测试套件 +- **新增 `bench/` 目录**:Google Benchmark 驱动的性能基准测试套件 +- **bench_bvh**:N=1K/10K/100K 随机三角形 SAH 构建 + 1K 射线最近命中查询 +- **bench_delaunay**:N=100/1K/10K 随机点 2D Bowyer-Watson 三角剖分 +- **bench_boolean**:两个球体 (N=100/500 面) 3D union/intersection 运算 +- **bench_curves**:N=10K/100K 次 Bezier/BSpline evaluate 吞吐量 +- **bench_spatial**:N=1K/10K/100K 点 R-Tree STR 构建 + KD-Tree 构建;kNN(n=10) 查询 +- **构建集成**:`BUILD_BENCHMARKS` 选项 (默认 OFF),Google Benchmark 通过 FetchContent 自动下载 +- **CTest 集成**:`ctest -R bench_` 一键运行全部基准 + ### Sprint 9 — 3D Delaunay/B-Rep/Boolean 测试补全 - **测试新增**:test_delaunay_3d(6 个用例)、test_boolean_mesh(22 个用例)、test_brep(17 个用例) - **3D Delaunay 测试**:空输入、正四面体、Delaunay 空外接球性质验证、退化点(共面/共线) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7adfc89..cc4f6f4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,6 +5,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) option(BUILD_TESTS "Build tests" ON) +option(BUILD_BENCHMARKS "Build benchmarks" OFF) option(BUILD_EXAMPLES "Build examples" ON) option(ENABLE_SANITIZERS "Enable ASan" OFF) option(VDE_USE_GMP "GMP exact arithmetic" OFF) @@ -23,6 +24,10 @@ endif() add_subdirectory(src) +if(BUILD_BENCHMARKS) + add_subdirectory(bench) +endif() + if(BUILD_TESTS) enable_testing() find_package(GTest QUIET) diff --git a/bench/bench_boolean.cpp b/bench/bench_boolean.cpp index bed42a9..c1e2dd4 100644 --- a/bench/bench_boolean.cpp +++ b/bench/bench_boolean.cpp @@ -13,7 +13,6 @@ #include #include #include -#include #include using namespace vde; @@ -25,34 +24,19 @@ struct SpherePair { mesh::HalfedgeMesh b; }; -/// Create two intersecting spheres (sphere_a at (-0.5, 0, 0), sphere_b at (+0.5, 0, 0)) -SpherePair make_sphere_pair(int segments) { - int seg_u = segments; - int seg_v = std::max(segments / 2, 4); +/// Create two intersecting spheres with approximately `face_count` faces each. +/// sphere_a at origin, sphere_b translated by +1.0 along X (overlap ~0.5) +SpherePair make_sphere_pair(int face_count) { + // make_sphere produces ~ 2 * seg_u * seg_v faces → solve for seg + int seg = std::max(static_cast(std::ceil(std::sqrt(face_count / 2.0))), 4); + int seg_u = seg; + int seg_v = seg; auto sphere_a = brep::make_sphere(1.0, seg_u, seg_v).to_mesh(); auto sphere_b = brep::make_sphere(1.0, seg_u, seg_v).to_mesh(); // Translate sphere_b by +1.0 along X so they overlap by ~0.5 - core::Transform3D t; - t.set_translation(core::Vector3D(1.0, 0.0, 0.0)); - - // Since HalfedgeMesh doesn't have a direct transform, we translate vertices manually - std::vector vb_verts; - for (size_t vi = 0; vi < sphere_b.num_vertices(); ++vi) { - auto p = sphere_b.vertex(vi); - vb_verts.push_back(core::Point3D(p.x() + 1.0, p.y(), p.z())); - } - - // Rebuild: extract face vertex indices and rebuild mesh - mesh::HalfedgeMesh sphere_b_moved; - for (size_t fi = 0; fi < sphere_b.num_faces(); ++fi) { - auto fv = sphere_b.face_vertices(static_cast(fi)); - sphere_b_moved.add_face(fv); - } - // Overwrite vertices (add_face adds them at original positions) - // Actually we need a different approach — just vertex-move the existing mesh - // Best: build directly from triangles + // Rebuild from triangles with translated vertices mesh::HalfedgeMesh b_moved; std::vector all_verts; std::vector> all_tris; diff --git a/docs/00-开发计划.md b/docs/00-开发计划.md index 2fc2302..32b24ef 100644 --- a/docs/00-开发计划.md +++ b/docs/00-开发计划.md @@ -42,5 +42,5 @@ |--------|------|--------| | **M1: MVP** | ✅ 已完成 | 可编译工程 + 40 个头文件 + 核心实现 | | **M2: 功能完整** | ✅ 完成 | 所有模块实现完整、138 测试 100% 通过 | -| **M3: 性能达标** | 📋 | 通过性能基准测试 | +| **M3: 性能达标** | 🚧 进行中 | 通过性能基准测试 | | **M4: v1.0 发布** | 📋 | 稳定 API + 完整文档 + 示例教程 |