Skip to content

Commit 85ccc69

Browse files
authored
Do multiple chamfer/fillet in one API call (#6750)
KCL's `fillet` function takes an array of edges to fillet. Previously this would do `n` fillet API commands, one per edge. This PR combines them all into one call, which should improve performance. You can see the effect in the artifact_commands snapshots, e.g. `rust/kcl-lib/tests/kcl_samples/axial-fan/artifact_commands.snap` Besides performance, this should fix a bug where some KCL fillets would fail, when they should have succeeded. Example from @max-mrgrsk: ```kcl sketch001 = startSketchOn(XY) |> startProfile(at = [-12, -6]) |> line(end = [0, 12], tag = $seg04) |> line(end = [24, 0], tag = $seg03) |> line(end = [0, -12], tag = $seg02) |> line(endAbsolute = [profileStartX(%), profileStartY(%)], tag = $seg01) |> close() extrude001 = extrude( sketch001, length = 12, tagEnd = $capEnd001, tagStart = $capStart001, ) |> fillet( radius = 5, tags = [ getCommonEdge(faces = [seg02, capEnd001]), getCommonEdge(faces = [seg01, capEnd001]), getCommonEdge(faces = [seg03, capEnd001]), getCommonEdge(faces = [seg04, capEnd001]) ], ) ``` This program fails on main, but succeeds on this branch.
1 parent 4e2deca commit 85ccc69

File tree

58 files changed

+419
-2499
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+419
-2499
lines changed

rust/kcl-lib/src/std/fillet.rs

Lines changed: 57 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -82,43 +82,67 @@ async fn inner_fillet(
8282
exec_state: &mut ExecState,
8383
args: Args,
8484
) -> Result<Box<Solid>, KclError> {
85+
// If you try and tag multiple edges with a tagged fillet, we want to return an
86+
// error to the user that they can only tag one edge at a time.
87+
if tag.is_some() && tags.len() > 1 {
88+
return Err(KclError::Type(KclErrorDetails {
89+
message: "You can only tag one edge at a time with a tagged fillet. Either delete the tag for the fillet fn if you don't need it OR separate into individual fillet functions for each tag.".to_string(),
90+
source_ranges: vec![args.source_range],
91+
backtrace: Default::default(),
92+
}));
93+
}
94+
if tags.is_empty() {
95+
return Err(KclError::Semantic(KclErrorDetails {
96+
source_ranges: vec![args.source_range],
97+
message: "You must fillet at least one tag".to_owned(),
98+
backtrace: Default::default(),
99+
}));
100+
}
101+
85102
let mut solid = solid.clone();
86-
for edge_tag in tags {
87-
let edge_id = edge_tag.get_engine_id(exec_state, &args)?;
103+
let edge_ids = tags
104+
.into_iter()
105+
.map(|edge_tag| edge_tag.get_engine_id(exec_state, &args))
106+
.collect::<Result<Vec<_>, _>>()?;
88107

89-
let id = exec_state.next_uuid();
90-
args.batch_end_cmd(
91-
id,
92-
ModelingCmd::from(mcmd::Solid3dFilletEdge {
93-
edge_id: None,
94-
edge_ids: vec![edge_id],
95-
extra_face_ids: vec![],
96-
strategy: Default::default(),
97-
object_id: solid.id,
98-
radius: LengthUnit(radius.to_mm()),
99-
tolerance: LengthUnit(tolerance.as_ref().map(|t| t.to_mm()).unwrap_or(DEFAULT_TOLERANCE)),
100-
cut_type: CutType::Fillet,
101-
}),
102-
)
103-
.await?;
108+
let id = exec_state.next_uuid();
109+
let mut extra_face_ids = Vec::new();
110+
let num_extra_ids = edge_ids.len() - 1;
111+
for _ in 0..num_extra_ids {
112+
extra_face_ids.push(exec_state.next_uuid());
113+
}
114+
args.batch_end_cmd(
115+
id,
116+
ModelingCmd::from(mcmd::Solid3dFilletEdge {
117+
edge_id: None,
118+
edge_ids: edge_ids.clone(),
119+
extra_face_ids,
120+
strategy: Default::default(),
121+
object_id: solid.id,
122+
radius: LengthUnit(radius.to_mm()),
123+
tolerance: LengthUnit(tolerance.as_ref().map(|t| t.to_mm()).unwrap_or(DEFAULT_TOLERANCE)),
124+
cut_type: CutType::Fillet,
125+
}),
126+
)
127+
.await?;
104128

105-
solid.edge_cuts.push(EdgeCut::Fillet {
106-
id,
107-
edge_id,
108-
radius: radius.clone(),
109-
tag: Box::new(tag.clone()),
110-
});
129+
let new_edge_cuts = edge_ids.into_iter().map(|edge_id| EdgeCut::Fillet {
130+
id,
131+
edge_id,
132+
radius: radius.clone(),
133+
tag: Box::new(tag.clone()),
134+
});
135+
solid.edge_cuts.extend(new_edge_cuts);
111136

112-
if let Some(ref tag) = tag {
113-
solid.value.push(ExtrudeSurface::Fillet(FilletSurface {
114-
face_id: id,
115-
tag: Some(tag.clone()),
116-
geo_meta: GeoMeta {
117-
id,
118-
metadata: args.source_range.into(),
119-
},
120-
}));
121-
}
137+
if let Some(ref tag) = tag {
138+
solid.value.push(ExtrudeSurface::Fillet(FilletSurface {
139+
face_id: id,
140+
tag: Some(tag.clone()),
141+
geo_meta: GeoMeta {
142+
id,
143+
metadata: args.source_range.into(),
144+
},
145+
}));
122146
}
123147

124148
Ok(solid)

rust/kcl-lib/tests/basic_fillet_cube_close_opposite/artifact_commands.snap

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -224,30 +224,16 @@ description: Artifact commands basic_fillet_cube_close_opposite.kcl
224224
"object_id": "[uuid]",
225225
"edge_id": null,
226226
"edge_ids": [
227+
"[uuid]",
227228
"[uuid]"
228229
],
229230
"radius": 2.0,
230231
"tolerance": 0.0000001,
231232
"cut_type": "fillet",
232233
"strategy": "automatic",
233-
"extra_face_ids": []
234-
}
235-
},
236-
{
237-
"cmdId": "[uuid]",
238-
"range": [],
239-
"command": {
240-
"type": "solid3d_fillet_edge",
241-
"object_id": "[uuid]",
242-
"edge_id": null,
243-
"edge_ids": [
234+
"extra_face_ids": [
244235
"[uuid]"
245-
],
246-
"radius": 2.0,
247-
"tolerance": 0.0000001,
248-
"cut_type": "fillet",
249-
"strategy": "automatic",
250-
"extra_face_ids": []
236+
]
251237
}
252238
},
253239
{

rust/kcl-lib/tests/basic_fillet_cube_close_opposite/artifact_graph_flowchart.snap.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ flowchart LR
3939
22["SweepEdge Adjacent"]
4040
23["EdgeCut Fillet<br>[221, 281, 0]"]
4141
%% [ProgramBodyItem { index: 0 }, VariableDeclarationDeclaration, VariableDeclarationInit, PipeBodyItem { index: 7 }]
42-
24["EdgeCut Fillet<br>[221, 281, 0]"]
43-
%% [ProgramBodyItem { index: 0 }, VariableDeclarationDeclaration, VariableDeclarationInit, PipeBodyItem { index: 7 }]
4442
1 --- 2
4543
2 --- 3
4644
2 --- 4
@@ -64,7 +62,7 @@ flowchart LR
6462
6 x--> 13
6563
6 --- 15
6664
6 --- 19
67-
6 --- 24
65+
6 --- 23
6866
8 --- 9
6967
8 --- 10
7068
8 --- 11
@@ -95,5 +93,4 @@ flowchart LR
9593
16 <--x 14
9694
17 <--x 14
9795
18 <--x 14
98-
15 <--x 23
9996
```

rust/kcl-lib/tests/basic_fillet_cube_end/artifact_commands.snap

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -224,30 +224,16 @@ description: Artifact commands basic_fillet_cube_end.kcl
224224
"object_id": "[uuid]",
225225
"edge_id": null,
226226
"edge_ids": [
227+
"[uuid]",
227228
"[uuid]"
228229
],
229230
"radius": 2.0,
230231
"tolerance": 0.0000001,
231232
"cut_type": "fillet",
232233
"strategy": "automatic",
233-
"extra_face_ids": []
234-
}
235-
},
236-
{
237-
"cmdId": "[uuid]",
238-
"range": [],
239-
"command": {
240-
"type": "solid3d_fillet_edge",
241-
"object_id": "[uuid]",
242-
"edge_id": null,
243-
"edge_ids": [
234+
"extra_face_ids": [
244235
"[uuid]"
245-
],
246-
"radius": 2.0,
247-
"tolerance": 0.0000001,
248-
"cut_type": "fillet",
249-
"strategy": "automatic",
250-
"extra_face_ids": []
236+
]
251237
}
252238
},
253239
{

rust/kcl-lib/tests/basic_fillet_cube_end/artifact_graph_flowchart.snap.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ flowchart LR
3939
22["SweepEdge Adjacent"]
4040
23["EdgeCut Fillet<br>[209, 267, 0]"]
4141
%% [ProgramBodyItem { index: 0 }, VariableDeclarationDeclaration, VariableDeclarationInit, PipeBodyItem { index: 7 }]
42-
24["EdgeCut Fillet<br>[209, 267, 0]"]
43-
%% [ProgramBodyItem { index: 0 }, VariableDeclarationDeclaration, VariableDeclarationInit, PipeBodyItem { index: 7 }]
4442
1 --- 2
4543
2 --- 3
4644
2 --- 4
@@ -52,7 +50,7 @@ flowchart LR
5250
3 x--> 13
5351
3 --- 18
5452
3 --- 22
55-
3 --- 24
53+
3 --- 23
5654
4 --- 10
5755
4 x--> 13
5856
4 --- 17
@@ -95,5 +93,4 @@ flowchart LR
9593
16 <--x 14
9694
17 <--x 14
9795
18 <--x 14
98-
18 <--x 23
9996
```

rust/kcl-lib/tests/basic_fillet_cube_start/artifact_commands.snap

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -224,30 +224,16 @@ description: Artifact commands basic_fillet_cube_start.kcl
224224
"object_id": "[uuid]",
225225
"edge_id": null,
226226
"edge_ids": [
227+
"[uuid]",
227228
"[uuid]"
228229
],
229230
"radius": 2.0,
230231
"tolerance": 0.0000001,
231232
"cut_type": "fillet",
232233
"strategy": "automatic",
233-
"extra_face_ids": []
234-
}
235-
},
236-
{
237-
"cmdId": "[uuid]",
238-
"range": [],
239-
"command": {
240-
"type": "solid3d_fillet_edge",
241-
"object_id": "[uuid]",
242-
"edge_id": null,
243-
"edge_ids": [
234+
"extra_face_ids": [
244235
"[uuid]"
245-
],
246-
"radius": 2.0,
247-
"tolerance": 0.0000001,
248-
"cut_type": "fillet",
249-
"strategy": "automatic",
250-
"extra_face_ids": []
236+
]
251237
}
252238
}
253239
]

rust/kcl-lib/tests/basic_fillet_cube_start/artifact_graph_flowchart.snap.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ flowchart LR
3939
22["SweepEdge Adjacent"]
4040
23["EdgeCut Fillet<br>[209, 251, 0]"]
4141
%% [ProgramBodyItem { index: 0 }, VariableDeclarationDeclaration, VariableDeclarationInit, PipeBodyItem { index: 7 }]
42-
24["EdgeCut Fillet<br>[209, 251, 0]"]
43-
%% [ProgramBodyItem { index: 0 }, VariableDeclarationDeclaration, VariableDeclarationInit, PipeBodyItem { index: 7 }]
4442
1 --- 2
4543
2 --- 3
4644
2 --- 4
@@ -61,7 +59,6 @@ flowchart LR
6159
5 x--> 13
6260
5 --- 16
6361
5 --- 20
64-
5 --- 24
6562
6 --- 11
6663
6 x--> 13
6764
6 --- 15

rust/kcl-lib/tests/fillet-and-shell/artifact_commands.snap

Lines changed: 7 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -351,64 +351,20 @@ description: Artifact commands fillet-and-shell.kcl
351351
"object_id": "[uuid]",
352352
"edge_id": null,
353353
"edge_ids": [
354+
"[uuid]",
355+
"[uuid]",
356+
"[uuid]",
354357
"[uuid]"
355358
],
356359
"radius": 1.0,
357360
"tolerance": 0.0000001,
358361
"cut_type": "fillet",
359362
"strategy": "automatic",
360-
"extra_face_ids": []
361-
}
362-
},
363-
{
364-
"cmdId": "[uuid]",
365-
"range": [],
366-
"command": {
367-
"type": "solid3d_fillet_edge",
368-
"object_id": "[uuid]",
369-
"edge_id": null,
370-
"edge_ids": [
363+
"extra_face_ids": [
364+
"[uuid]",
365+
"[uuid]",
371366
"[uuid]"
372-
],
373-
"radius": 1.0,
374-
"tolerance": 0.0000001,
375-
"cut_type": "fillet",
376-
"strategy": "automatic",
377-
"extra_face_ids": []
378-
}
379-
},
380-
{
381-
"cmdId": "[uuid]",
382-
"range": [],
383-
"command": {
384-
"type": "solid3d_fillet_edge",
385-
"object_id": "[uuid]",
386-
"edge_id": null,
387-
"edge_ids": [
388-
"[uuid]"
389-
],
390-
"radius": 1.0,
391-
"tolerance": 0.0000001,
392-
"cut_type": "fillet",
393-
"strategy": "automatic",
394-
"extra_face_ids": []
395-
}
396-
},
397-
{
398-
"cmdId": "[uuid]",
399-
"range": [],
400-
"command": {
401-
"type": "solid3d_fillet_edge",
402-
"object_id": "[uuid]",
403-
"edge_id": null,
404-
"edge_ids": [
405-
"[uuid]"
406-
],
407-
"radius": 1.0,
408-
"tolerance": 0.0000001,
409-
"cut_type": "fillet",
410-
"strategy": "automatic",
411-
"extra_face_ids": []
367+
]
412368
}
413369
},
414370
{

rust/kcl-lib/tests/fillet-and-shell/artifact_graph_flowchart.snap.md

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,6 @@ flowchart LR
174174
85["SweepEdge Adjacent"]
175175
86["EdgeCut Fillet<br>[1068, 1274, 0]"]
176176
%% [ProgramBodyItem { index: 17 }, VariableDeclarationDeclaration, VariableDeclarationInit, PipeBodyItem { index: 7 }]
177-
87["EdgeCut Fillet<br>[1068, 1274, 0]"]
178-
%% [ProgramBodyItem { index: 17 }, VariableDeclarationDeclaration, VariableDeclarationInit, PipeBodyItem { index: 7 }]
179-
88["EdgeCut Fillet<br>[1068, 1274, 0]"]
180-
%% [ProgramBodyItem { index: 17 }, VariableDeclarationDeclaration, VariableDeclarationInit, PipeBodyItem { index: 7 }]
181-
89["EdgeCut Fillet<br>[1068, 1274, 0]"]
182-
%% [ProgramBodyItem { index: 17 }, VariableDeclarationDeclaration, VariableDeclarationInit, PipeBodyItem { index: 7 }]
183177
1 --- 7
184178
2 --- 8
185179
3 --- 10
@@ -319,8 +313,5 @@ flowchart LR
319313
74 <--x 69
320314
75 <--x 69
321315
76 <--x 69
322-
81 <--x 89
323-
82 <--x 87
324-
83 <--x 88
325-
84 <--x 86
316+
81 <--x 86
326317
```

0 commit comments

Comments
 (0)