fix(v1.0.1): VDE-011/012/013 — write_stl return bool, StlTrianglef, module options
Build & Test / build-and-test (push) Waiting to run
Build & Test / python-bindings (push) Blocked by required conditions
CI / Build & Test (push) Failing after 36s
CI / Release Build (push) Failing after 36s

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
This commit is contained in:
茂之钳
2026-07-27 22:51:03 +08:00
parent a73c5e8954
commit c021855597
4 changed files with 75 additions and 4 deletions
+12 -1
View File
@@ -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)
+29
View File
@@ -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 配置通过
+21 -1
View File
@@ -92,6 +92,7 @@ std::vector<StlTriangle> read_stl(const std::string& filepath);
* @ingroup foundation
*/
void write_stl(const std::string& filepath, const std::vector<StlTriangle>& tris);
bool write_stl(const std::string& filepath, const std::vector<StlTriangle>& tris);
/**
* @brief 写入 ASCII STL 文件
@@ -100,17 +101,36 @@ void write_stl(const std::string& filepath, const std::vector<StlTriangle>& tris
*
* @param filepath 输出文件路径
* @param tris 三角形面片列表
* @return true 写入成功,false 文件创建失败
*
* @warning ASCII STL 文件体积约为二进制 STL 的 5-10 倍,不适合大规模网格
*
* @code{.cpp}
* std::vector<StlTriangle> 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<StlTriangle>& tris);
bool write_stl_ascii(const std::string& filepath, const std::vector<StlTriangle>& 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
+13 -2
View File
@@ -115,8 +115,9 @@ std::vector<StlTriangle> read_stl(const std::string& filepath) {
return read_stl_binary(filepath);
}
void write_stl(const std::string& filepath, const std::vector<StlTriangle>& tris) {
bool write_stl(const std::string& filepath, const std::vector<StlTriangle>& tris) {
std::ofstream file(filepath, std::ios::binary);
if (!file) return false;
char header[80] = {};
file.write(header, 80);
uint32_t count = static_cast<uint32_t>(tris.size());
@@ -129,10 +130,12 @@ void write_stl(const std::string& filepath, const std::vector<StlTriangle>& tris
uint16_t attr = 0;
file.write(reinterpret_cast<const char*>(&attr), 2);
}
return true;
}
void write_stl_ascii(const std::string& filepath, const std::vector<StlTriangle>& tris) {
bool write_stl_ascii(const std::string& filepath, const std::vector<StlTriangle>& 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<StlTriangle>
file << " endfacet\n";
}
file << "endsolid vde\n";
return true;
}
StlTrianglef to_stl_trianglef(const StlTriangle& t) {
return {t.normal.cast<float>(), t.v0.cast<float>(), t.v1.cast<float>(), t.v2.cast<float>()};
}
StlTriangle from_stl_trianglef(const StlTrianglef& t) {
return {t.normal.cast<double>(), t.v0.cast<double>(), t.v1.cast<double>(), t.v2.cast<double>()};
}
} // namespace vde::foundation