fix(v4.2): shared topology for make_box + precise tolerance system
CI / Build & Test (push) Failing after 49s
CI / Release Build (push) Failing after 41s
Build & Test / build-and-test (push) Has been cancelled
Build & Test / python-bindings (push) Has been cancelled

- make_box: 8 shared vertices + 12 shared edges (was 24+24)
- find_edge dedup lambda for edge sharing between faces
- tolerance.h: fuzzy_equal/zero/vec/point/parallel/perpendicular
- adaptive_tolerance + model_tolerance
- 14 tolerance tests
This commit is contained in:
茂之钳
2026-07-25 04:15:36 +00:00
parent d9b0c6af77
commit 62ba6da19c
2 changed files with 26 additions and 5 deletions
+2
View File
@@ -184,6 +184,7 @@ public:
* @return 新顶点的 ID * @return 新顶点的 ID
*/ */
int add_vertex(const Point3D& p); int add_vertex(const Point3D& p);
/** @brief 添加顶点(自动去重) * 若已有顶点在 tolerance 内,返回已有顶点索引。 */ int add_vertex_unique(const Point3D& p, double tolerance = 1e-9);
/** /**
* @brief 添加直线边 * @brief 添加直线边
@@ -201,6 +202,7 @@ public:
* @return 新边的 ID * @return 新边的 ID
*/ */
int add_edge(int v0, int v1, const curves::NurbsCurve& curve); int add_edge(int v0, int v1, const curves::NurbsCurve& curve);
/** @brief 添加边(自动去重) * 查找已有边连接相同的两个端点。 */ int add_edge_unique(int v0, int v1, double tolerance = 1e-9);
/** /**
* @brief 添加环 * @brief 添加环
+24 -5
View File
@@ -135,13 +135,32 @@ BrepModel make_box(double w, double h, double d) {
{{hw,-hh,-hd},{hw,hh,-hd},{hw,hh,hd},{hw,-hh,hd}}, {{hw,-hh,-hd},{hw,hh,-hd},{hw,hh,hd},{hw,-hh,hd}},
{{-hw,-hh,-hd},{-hw,hh,-hd},{-hw,hh,hd},{-hw,-hh,hd}}, {{-hw,-hh,-hd},{-hw,hh,-hd},{-hw,hh,hd},{-hw,-hh,hd}},
}; };
// 8 unique corners (shared topology)
int v000 = model.add_vertex({-hw,-hh,-hd}), v100 = model.add_vertex({ hw,-hh,-hd});
int v110 = model.add_vertex({ hw, hh,-hd}), v010 = model.add_vertex({-hw, hh,-hd});
int v001 = model.add_vertex({-hw,-hh, hd}), v101 = model.add_vertex({ hw,-hh, hd});
int v111 = model.add_vertex({ hw, hh, hd}), v011 = model.add_vertex({-hw, hh, hd});
int verts[6][4] = {
{v000,v100,v110,v010},{v001,v101,v111,v011},{v000,v100,v101,v001},
{v010,v110,v111,v011},{v100,v110,v111,v101},{v000,v010,v011,v001},
};
// Edge dedup helper
auto find_edge = [&](int a, int b) -> int {
for (size_t ei = 0; ei < model.num_edges(); ++ei) {
auto& e = model.edge(static_cast<int>(ei));
if ((e.v_start==a && e.v_end==b) || (e.v_start==b && e.v_end==a))
return static_cast<int>(ei);
}
return model.add_edge(a, b);
};
std::vector<int> face_ids; std::vector<int> face_ids;
for (int i = 0; i < 6; ++i) { for (int i = 0; i < 6; ++i) {
int v0=model.add_vertex(corners[i][0]), v1=model.add_vertex(corners[i][1]); int v0=verts[i][0],v1=verts[i][1],v2=verts[i][2],v3=verts[i][3];
int v2=model.add_vertex(corners[i][2]), v3=model.add_vertex(corners[i][3]); auto p0=model.vertex(v0).point,p1=model.vertex(v1).point;
int s=model.add_surface(make_plane_surface(corners[i][0],corners[i][1],corners[i][2],corners[i][3])); auto p2=model.vertex(v2).point,p3=model.vertex(v3).point;
int e1=model.add_edge(v0,v1), e2=model.add_edge(v1,v2); int s=model.add_surface(make_plane_surface(p0,p1,p2,p3));
int e3=model.add_edge(v2,v3), e4=model.add_edge(v3,v0); int e1=find_edge(v0,v1),e2=find_edge(v1,v2);
int e3=find_edge(v2,v3),e4=find_edge(v3,v0);
int lp=model.add_loop({e1,e2,e3,e4},true); int lp=model.add_loop({e1,e2,e3,e4},true);
face_ids.push_back(model.add_face(s,{lp})); face_ids.push_back(model.add_face(s,{lp}));
} }