fix(v4.2): shared topology for make_box + precise tolerance system
- 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:
@@ -184,6 +184,7 @@ public:
|
||||
* @return 新顶点的 ID
|
||||
*/
|
||||
int add_vertex(const Point3D& p);
|
||||
/** @brief 添加顶点(自动去重) * 若已有顶点在 tolerance 内,返回已有顶点索引。 */ int add_vertex_unique(const Point3D& p, double tolerance = 1e-9);
|
||||
|
||||
/**
|
||||
* @brief 添加直线边
|
||||
@@ -201,6 +202,7 @@ public:
|
||||
* @return 新边的 ID
|
||||
*/
|
||||
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 添加环
|
||||
|
||||
+24
-5
@@ -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}},
|
||||
};
|
||||
// 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;
|
||||
for (int i = 0; i < 6; ++i) {
|
||||
int v0=model.add_vertex(corners[i][0]), v1=model.add_vertex(corners[i][1]);
|
||||
int v2=model.add_vertex(corners[i][2]), v3=model.add_vertex(corners[i][3]);
|
||||
int s=model.add_surface(make_plane_surface(corners[i][0],corners[i][1],corners[i][2],corners[i][3]));
|
||||
int e1=model.add_edge(v0,v1), e2=model.add_edge(v1,v2);
|
||||
int e3=model.add_edge(v2,v3), e4=model.add_edge(v3,v0);
|
||||
int v0=verts[i][0],v1=verts[i][1],v2=verts[i][2],v3=verts[i][3];
|
||||
auto p0=model.vertex(v0).point,p1=model.vertex(v1).point;
|
||||
auto p2=model.vertex(v2).point,p3=model.vertex(v3).point;
|
||||
int s=model.add_surface(make_plane_surface(p0,p1,p2,p3));
|
||||
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);
|
||||
face_ids.push_back(model.add_face(s,{lp}));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user