fix: add_surface 返回数组下标 + is_valid 按 ID 查找而非下标比较
This commit is contained in:
+15
-13
@@ -47,9 +47,9 @@ int BrepModel::add_body(const std::vector<int>& shell_ids, const std::string& na
|
||||
}
|
||||
|
||||
int BrepModel::add_surface(const curves::NurbsSurface& surf) {
|
||||
int id = next_id_++;
|
||||
int idx = static_cast<int>(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<int>(vertices_.size()) ||
|
||||
e.v_end >= static_cast<int>(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<int>(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<int>(surfaces_.size()))
|
||||
return false;
|
||||
}
|
||||
for (int li : f.loops) {
|
||||
if (li >= static_cast<int>(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;
|
||||
|
||||
Reference in New Issue
Block a user