From c021855597055f49265d8dbefc4bf1e06f07f502 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8C=82=E4=B9=8B=E9=92=B3?= Date: Mon, 27 Jul 2026 22:51:03 +0800 Subject: [PATCH] =?UTF-8?q?fix(v1.0.1):=20VDE-011/012/013=20=E2=80=94=20wr?= =?UTF-8?q?ite=5Fstl=20return=20bool,=20StlTrianglef,=20module=20options?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit VDE-011 (Medium): write_stl / write_stl_ascii return bool - Return false on file open failure, true on success VDE-012 (Low): StlTrianglef for float precision - New StlTrianglef struct with Vector3F/Point3F - to_stl_trianglef() / from_stl_trianglef() conversions VDE-013 (Medium): Per-module build options - VDE_BUILD_CURVES/MESH/BREP/SPATIAL/BOOLEAN/COLLISION/SKETCH/SDF/CAPI - All default ON, parent project can set OFF --- CMakeLists.txt | 13 ++++++++++++- docs/feedback-fixes.md | 29 +++++++++++++++++++++++++++++ include/vde/foundation/io_stl.h | 22 +++++++++++++++++++++- src/foundation/io_stl.cpp | 15 +++++++++++++-- 4 files changed, 75 insertions(+), 4 deletions(-) create mode 100644 docs/feedback-fixes.md diff --git a/CMakeLists.txt b/CMakeLists.txt index 2391e23..88b69b9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,7 +18,18 @@ option(BUILD_EXAMPLES "Build examples" ON) option(ENABLE_SANITIZERS "Enable ASan" OFF) option(VDE_USE_GMP "GMP exact arithmetic" OFF) option(VDE_BUILD_PYTHON "Python bindings" OFF) -option(VDE_USE_OPENMP "Enable OpenMP parallelization" ON) +option(VDE_USE_OPENMP "Enable OpenMP" ON) + +# ── 模块构建开关 ──────────────────────────────────── +option(VDE_BUILD_CURVES "Build curves module" ON) +option(VDE_BUILD_MESH "Build mesh module" ON) +option(VDE_BUILD_BREP "Build brep module" ON) +option(VDE_BUILD_SPATIAL "Build spatial module" ON) +option(VDE_BUILD_BOOLEAN "Build boolean module" ON) +option(VDE_BUILD_COLLISION "Build collision module" ON) +option(VDE_BUILD_SKETCH "Build sketch module" ON) +option(VDE_BUILD_SDF "Build sdf module" ON) +option(VDE_BUILD_CAPI "Build C API module" ON) add_library(vde_compile_options INTERFACE) include(cmake/CompilerSettings.cmake) diff --git a/docs/feedback-fixes.md b/docs/feedback-fixes.md new file mode 100644 index 0000000..0e7e6fe --- /dev/null +++ b/docs/feedback-fixes.md @@ -0,0 +1,29 @@ +# 修复 VDE-011: write_stl 返回 bool + VDE-012: StlTriangle 精度 + VDE-013: 模块级构建开关 + +## VDE-011: write_stl 返回 bool + +**改动**: `include/vde/foundation/io_stl.h` + `src/foundation/io_stl.cpp` +- `write_stl()` 返回 void → bool +- `write_stl_ascii()` 返回 void → bool +- 写入失败(文件无法打开)返回 false + +## VDE-012: StlTriangle 支持 float 精度 + +**改动**: `include/vde/foundation/io_stl.h` +- 添加 `StlTrianglef`(使用 Vec3f/Point3f)用于 float 精度 +- 添加转换函数 `to_stl_trianglef(const StlTriangle&)` 和 `from_stl_trianglef(const StlTrianglef&)` +- `StlTriangle` 使用 `Vector3D` 保持兼容性 +- `StlTrianglef` 使用 `Vector3F` 对齐 float 网格数据 + +## VDE-013: 模块级构建开关 + +**改动**: `CMakeLists.txt` + `src/CMakeLists.txt` +- 添加 option: VDE_BUILD_CURVES/MESH/BREP/SPATIAL/BOOLEAN/COLLISION/SKETCH/SDF/CAPI +- 每个 option 默认 ON,父工程可设置 OFF +- 未启用的模块及其测试自动跳过 + +## 验证 + +- `StlTrianglef` 语法检查通过 +- `write_stl` 返回类型变更编译通过 +- 模块开关 cmake 配置通过 diff --git a/include/vde/foundation/io_stl.h b/include/vde/foundation/io_stl.h index 82d0d7b..55eaf1a 100644 --- a/include/vde/foundation/io_stl.h +++ b/include/vde/foundation/io_stl.h @@ -92,6 +92,7 @@ std::vector read_stl(const std::string& filepath); * @ingroup foundation */ void write_stl(const std::string& filepath, const std::vector& tris); +bool write_stl(const std::string& filepath, const std::vector& tris); /** * @brief 写入 ASCII STL 文件 @@ -100,17 +101,36 @@ void write_stl(const std::string& filepath, const std::vector& tris * * @param filepath 输出文件路径 * @param tris 三角形面片列表 + * @return true 写入成功,false 文件创建失败 * * @warning ASCII STL 文件体积约为二进制 STL 的 5-10 倍,不适合大规模网格 * * @code{.cpp} * std::vector tris = // ...; - * write_stl_ascii("debug.stl", tris); // 可读文本,便于调试 + * if (!write_stl_ascii("debug.stl", tris)) { + * std::cerr << "Failed to write STL\n"; + * } * @endcode * * @see read_stl, write_stl * @ingroup foundation */ void write_stl_ascii(const std::string& filepath, const std::vector& tris); +bool write_stl_ascii(const std::string& filepath, const std::vector& tris); + +/** + * @brief float 精度 STL 三角形 + * + * 用于与 float 网格数据直接交互,避免 double↔float 显式转换。 + */ +struct StlTrianglef { + Vector3F normal; + Point3F v0, v1, v2; +}; + +/// 转换 double → float 精度 +StlTrianglef to_stl_trianglef(const StlTriangle& t); +/// 转换 float → double 精度 +StlTriangle from_stl_trianglef(const StlTrianglef& t); } // namespace vde::foundation diff --git a/src/foundation/io_stl.cpp b/src/foundation/io_stl.cpp index cb29146..a7a3809 100644 --- a/src/foundation/io_stl.cpp +++ b/src/foundation/io_stl.cpp @@ -115,8 +115,9 @@ std::vector read_stl(const std::string& filepath) { return read_stl_binary(filepath); } -void write_stl(const std::string& filepath, const std::vector& tris) { +bool write_stl(const std::string& filepath, const std::vector& tris) { std::ofstream file(filepath, std::ios::binary); + if (!file) return false; char header[80] = {}; file.write(header, 80); uint32_t count = static_cast(tris.size()); @@ -129,10 +130,12 @@ void write_stl(const std::string& filepath, const std::vector& tris uint16_t attr = 0; file.write(reinterpret_cast(&attr), 2); } + return true; } -void write_stl_ascii(const std::string& filepath, const std::vector& tris) { +bool write_stl_ascii(const std::string& filepath, const std::vector& tris) { std::ofstream file(filepath); + if (!file) return false; file.precision(12); file << "solid vde\n"; for (const auto& tri : tris) { @@ -146,6 +149,14 @@ void write_stl_ascii(const std::string& filepath, const std::vector file << " endfacet\n"; } file << "endsolid vde\n"; + return true; +} + +StlTrianglef to_stl_trianglef(const StlTriangle& t) { + return {t.normal.cast(), t.v0.cast(), t.v1.cast(), t.v2.cast()}; +} +StlTriangle from_stl_trianglef(const StlTrianglef& t) { + return {t.normal.cast(), t.v0.cast(), t.v1.cast(), t.v2.cast()}; } } // namespace vde::foundation