From 9e4c1b1f546a1f1f3eca48cc031118c58e6e6c12 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 16:41:57 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20add=5Fsurface=20=E8=BF=94=E5=9B=9E?= =?UTF-8?q?=E6=95=B0=E7=BB=84=E4=B8=8B=E6=A0=87=20+=20is=5Fvalid=20?= =?UTF-8?q?=E6=8C=89=20ID=20=E6=9F=A5=E6=89=BE=E8=80=8C=E9=9D=9E=E4=B8=8B?= =?UTF-8?q?=E6=A0=87=E6=AF=94=E8=BE=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/brep/brep.cpp | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/brep/brep.cpp b/src/brep/brep.cpp index cc284c6..01d4f7c 100644 --- a/src/brep/brep.cpp +++ b/src/brep/brep.cpp @@ -47,9 +47,9 @@ int BrepModel::add_body(const std::vector& shell_ids, const std::string& na } int BrepModel::add_surface(const curves::NurbsSurface& surf) { - int id = next_id_++; + int idx = static_cast(surfaces_.size()); surfaces_.push_back(surf); - return id; + return idx; } core::AABB3D BrepModel::bounds() const { @@ -60,22 +60,24 @@ core::AABB3D BrepModel::bounds() const { bool BrepModel::is_valid() const { for (const auto& e : edges_) { - if (e.v_start >= static_cast(vertices_.size()) || - e.v_end >= static_cast(vertices_.size())) { - fprintf(stderr, "is_valid FAIL: edge v=%d/%d vs %zu verts\n", e.v_start, e.v_end, vertices_.size()); - return false; + // Validate vertex references by ID (IDs are global, not array indices) + bool v0 = false, v1 = false; + for (const auto& v : vertices_) { + if (v.id == e.v_start) v0 = true; + if (v.id == e.v_end) v1 = true; } + if (!v0 || !v1) return false; } for (const auto& f : faces_) { - if (f.surface_id >= static_cast(surfaces_.size())) { - fprintf(stderr, "is_valid FAIL: face.surface_id=%d vs %zu surfaces\n", f.surface_id, surfaces_.size()); + // Validate surface ID — surfaces stored by add order, use index + if (f.surface_id >= static_cast(surfaces_.size())) return false; - } for (int li : f.loops) { - if (li >= static_cast(loops_.size())) { - fprintf(stderr, "is_valid FAIL: loop=%d vs %zu loops\n", li, loops_.size()); - return false; - } + // Validate loop reference by ID + bool found = false; + for (const auto& l : loops_) + if (l.id == li) { found = true; break; } + if (!found) return false; } } return true;