fix(curves): initialize plane normal before coplanarity test in is_circle_section

is_circle_section used the caller's uninitialized Vector3D normal in the coplanarity sampling loop before assigning it at the end; suffix tests rewriting the stack flipped rational-circle sections to the generic resampling path, giving loft weight sum 26.414213562 instead of 23.485281374 and offset fit residuals 4.3e-2. Assign plane_normal before the loop and hand it back as the output.

Regression: MeasureTest.LoftOfRationalCirclesStaysRational (rational Coons prefix + 3-circle loft; weight sum and v-boundary tolerance 1e-12). test_measure 160/160; test_generative_surfaces 33/33; test_curve_tools 52/52; test_brep 96/96; PR gate 918/918.
This commit is contained in:
hm
2026-11-16 03:05:27 +08:00
parent bb9b8d846e
commit f5aeeeb424
4 changed files with 98 additions and 6 deletions
+33 -4
View File
@@ -14,6 +14,7 @@ VDE-1346 薄板/双孔板/碎片板 中面+壳面积一致
VDE-1347 薄板/双孔板 tetra 闭合、体积校验通过
VDE-1276 真实语料 display 缝 open_edge 2412→0(plate)/ 576→0(PWB body2,2026-11-15)
analytic_measure 逐面并行 PWB body2 body_volume 32.8 s→7.8 s(数值不变,2026-11-15)
test_measure 顺序 flake 有理 loft 权重退化(未初始化法向 UB)修复 160/160(2026-11-15)
~~~
## 未关闭
@@ -78,8 +79,8 @@ test_fea_mesh 68/68(去掉 CorpusProbe.BatchSweep)
test_vde1346_cae_preprocess 10/10
test_display_mesh 16/16
test_vde1239_display_quality 13/13
test_measure 158/159(含 AnalyticMeasureParallel.MatchesSerialBitwise;
MeasureTest.OffsetSurfaceLoftIsHighAccuracy 全量顺序 flake)
test_measure 160/160(含 AnalyticMeasureParallel.MatchesSerialBitwise、
LoftOfRationalCirclesStaysRational)
PR gate 868/868(2026-11-15 实测 167.45 s;并行度量后复跑 159.19 s)
~~~
@@ -146,8 +147,36 @@ tests/brep/test_real_corpus_feedback.cpp
回归:`tests/brep/test_real_corpus_feedback.cpp` 的
`HostExportedSplineBodyDisplayMeshKeepsFaceTags`/`HostExportedStepRoundTripImports`
覆盖该体导入;`test_measure` 158 例(`MeasureTest.OffsetSurfaceLoftIsHighAccuracy`
全量跑既有顺序相关 flake,单跑 PASS,与本改动无关)。
覆盖该体导入;`test_measure` 160 例(含 `LoftOfRationalCirclesStaysRational` 锁定理有
loft 权重,替换此前标注的 `OffsetSurfaceLoftIsHighAccuracy` 顺序相关 flake)。
## 关闭记录:test_measure 顺序相关 flake(2026-11-15)
现象:`test_measure` 全量跑 158/159,`MeasureTest.OffsetSurfaceLoftIsHighAccuracy`
残差 4.35e-2(期望 1e-5);单跑 PASS。二分定位到
`MeasureTest.CoonsPatchRationalBoundariesAreGeometricallyExact` 先跑即触发。
根因(UB):`src/curves/generative_surfaces.cpp` 的 `is_circle_section` 把法向当纯
输出参数,却在赋值前用 `d.dot(normal)` 做共面判定 → 读取调用方未初始化的
`Vector3D normal`(call site 是 `align_closed_section_starts` 的局部变量)。后缀用例
改变栈内容后判定翻转:有理圆被判成非共面 → 落入 `rotate_generic_closed`(采样点直接
当控制点的非有理折线)→ `loft_surface` 权重和 23.485281374→26.414213562,v 边界不再
是原圆;offset 拟合残差由 2e-6 恶化到 4.3e-2。
~~~text
修复:先算 const Vector3D plane_normal = b0.cross(c0).normalized();
共面采样判定改用 plane_normal;末尾 normal = plane_normal;
验证(A/B 同源码对比)
修复前:test_measure 158/160;Loft 与新增 LoftOfRationalCirclesStaysRational 均 FAIL
新增用例单跑即 FAIL,wsum=26.414213562373096(非有理退化的指纹)
修复后:test_measure 160/160(62.7 s,含 AnalyticMeasureParallel 与新增用例)
~~~
回归:tests/brep/test_measure.cpp 的 `MeasureTest.LoftOfRationalCirclesStaysRational`
(先构造有理边界 Coons 曲面复现栈状态,再断言 loft 权重和 23.485281374 及 v=0/v=1
边界与输入圆偏差 ≤1e-12)。
## 整圆/圆弧统一采样原型(2026-11-14)
@@ -87,3 +87,4 @@
| 日期 | 版本 | 变更 |
|---|---|---|
| 2026-11-09 | 1.0.282 | is_circle_section 采样验证 + loft 权重行 → 边界偏差 0;注册 8,653 |
| 2026-11-15 | — | 后续修复:§修复 1 的共面判定 `|d·n|` 在 `normal` 赋值前执行(读取调用方未初始化 `Vector3D`,UB;后缀用例可翻转判定 → 有理圆退化成非有理折线)。改为先算 `plane_normal = b0.cross(c0).normalized()` 再做采样判定;回归 `test_measure.cpp` 的 `MeasureTest.LoftOfRationalCirclesStaysRational` |