fix edge cuts & clone (#6572)

* fix edge cuts & clone

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* updates

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* fix edge_id

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* code comemnt

Signed-off-by: Jess Frazelle <github@jessfraz.com>

---------

Signed-off-by: Jess Frazelle <github@jessfraz.com>
This commit is contained in:
Jess Frazelle
2025-04-29 09:51:52 -07:00
committed by GitHub
parent 77e3efde9a
commit e0cd3efc64
25 changed files with 179 additions and 182 deletions

View File

@ -427,6 +427,13 @@ impl PartialOrd for Artifact {
}
Some(a.id.cmp(&b.id))
}
(Artifact::EdgeCut(a), Artifact::EdgeCut(b)) => {
if a.code_ref.range != b.code_ref.range {
return Some(a.code_ref.range.cmp(&b.code_ref.range));
}
Some(a.id.cmp(&b.id))
}
(Artifact::EdgeCutEdge(a), Artifact::EdgeCutEdge(b)) => Some(a.edge_cut_id.cmp(&b.edge_cut_id)),
(Artifact::Sweep(a), Artifact::Sweep(b)) => {
if a.code_ref.range != b.code_ref.range {
return Some(a.code_ref.range.cmp(&b.code_ref.range));

View File

@ -301,6 +301,9 @@ async fn inner_clone(
GeometryWithImportedGeometry::Sketch(new_sketch)
}
GeometryWithImportedGeometry::Solid(solid) => {
// We flush before the clone so all the shit exists.
args.flush_batch_for_solids(exec_state, &[solid.clone()]).await?;
let mut new_solid = solid.clone();
new_solid.id = new_id;
new_solid.sketch.original_id = new_id;
@ -361,17 +364,19 @@ async fn fix_tags_and_references(
// Fix the edge cuts.
for edge_cut in solid.edge_cuts.iter_mut() {
let Some(new_edge_id) = entity_id_map.get(&edge_cut.edge_id()) else {
anyhow::bail!("Failed to find new edge id for old edge id: {:?}", edge_cut.edge_id());
};
edge_cut.set_edge_id(*new_edge_id);
let Some(id) = entity_id_map.get(&edge_cut.id()) else {
anyhow::bail!(
if let Some(id) = entity_id_map.get(&edge_cut.id()) {
edge_cut.set_id(*id);
} else {
crate::log::logln!(
"Failed to find new edge cut id for old edge cut id: {:?}",
edge_cut.id()
);
};
edge_cut.set_id(*id);
}
if let Some(new_edge_id) = entity_id_map.get(&edge_cut.edge_id()) {
edge_cut.set_edge_id(*new_edge_id);
} else {
crate::log::logln!("Failed to find new edge id for old edge id: {:?}", edge_cut.edge_id());
}
}
// Do the after extrude things to update those ids, based on the new sketch
@ -462,10 +467,13 @@ async fn fix_sketch_tags_and_references(
) -> Result<()> {
// Fix the path references in the sketch.
for path in new_sketch.paths.as_mut_slice() {
let Some(new_path_id) = entity_id_map.get(&path.get_id()) else {
anyhow::bail!("Failed to find new path id for old path id: {:?}", path.get_id());
};
if let Some(new_path_id) = entity_id_map.get(&path.get_id()) {
path.set_id(*new_path_id);
} else {
// We log on these because we might have already flushed and the id is no longer
// relevant since filleted or something.
crate::log::logln!("Failed to find new path id for old path id: {:?}", path.get_id());
}
}
// Fix the tags
@ -479,14 +487,14 @@ async fn fix_sketch_tags_and_references(
}
// Fix the base path.
// TODO: Right now this one does not work, ignore for now and see if we really need it.
/* let Some(new_base_path) = entity_id_map.get(&new_sketch.start.geo_meta.id) else {
anyhow::bail!(
if let Some(new_base_path) = entity_id_map.get(&new_sketch.start.geo_meta.id) {
new_sketch.start.geo_meta.id = *new_base_path;
} else {
crate::log::logln!(
"Failed to find new base path id for old base path id: {:?}",
new_sketch.start.geo_meta.id
);
};
new_sketch.start.geo_meta.id = *new_base_path;*/
}
Ok(())
}
@ -845,7 +853,6 @@ clonedCube = clone(cube)
// references.
// WITH TAGS AND EDGE CUTS.
#[tokio::test(flavor = "multi_thread")]
#[ignore = "this test is not working yet, need to fix the edge cut ids"]
async fn kcl_test_clone_solid_with_edge_cuts() {
let code = r#"cube = startSketchOn(XY)
|> startProfile(at = [0,0]) // tag this one
@ -913,28 +920,11 @@ clonedCube = clone(cube)
#[cfg(feature = "artifact-graph")]
assert_eq!(cloned_cube.artifact_id, cloned_cube.id.into());
for (path, cloned_path) in cube.sketch.paths.iter().zip(cloned_cube.sketch.paths.iter()) {
assert_ne!(path.get_id(), cloned_path.get_id());
assert_eq!(path.get_tag(), cloned_path.get_tag());
}
for (value, cloned_value) in cube.value.iter().zip(cloned_cube.value.iter()) {
assert_ne!(value.get_id(), cloned_value.get_id());
assert_eq!(value.get_tag(), cloned_value.get_tag());
}
for (tag_name, tag) in &cube.sketch.tags {
let cloned_tag = cloned_cube.sketch.tags.get(tag_name).unwrap();
let tag_info = tag.get_cur_info().unwrap();
let cloned_tag_info = cloned_tag.get_cur_info().unwrap();
assert_ne!(tag_info.id, cloned_tag_info.id);
assert_ne!(tag_info.sketch, cloned_tag_info.sketch);
assert_ne!(tag_info.path, cloned_tag_info.path);
assert_ne!(tag_info.surface, cloned_tag_info.surface);
}
for (edge_cut, cloned_edge_cut) in cube.edge_cuts.iter().zip(cloned_cube.edge_cuts.iter()) {
assert_ne!(edge_cut.id(), cloned_edge_cut.id());
assert_ne!(edge_cut.edge_id(), cloned_edge_cut.edge_id());

View File

@ -49,7 +49,7 @@ flowchart LR
6 x--> 13
6 --- 18
6 --- 19
6 --- 23
6 --- 24
8 --- 9
8 --- 10
8 --- 11
@ -78,5 +78,5 @@ flowchart LR
15 <--x 14
16 <--x 14
17 <--x 14
18 <--x 24
18 <--x 23
```

View File

@ -37,7 +37,7 @@ flowchart LR
3 x--> 13
3 --- 18
3 --- 20
3 --- 23
3 --- 24
4 --- 10
4 x--> 13
4 --- 17
@ -78,5 +78,5 @@ flowchart LR
15 <--x 14
16 <--x 14
17 <--x 14
18 <--x 24
18 <--x 23
```

View File

@ -37,7 +37,7 @@ flowchart LR
3 x--> 13
3 --- 17
3 --- 20
3 --- 23
3 --- 24
4 --- 10
4 x--> 13
4 --- 18
@ -46,7 +46,7 @@ flowchart LR
5 x--> 13
5 --- 15
5 --- 22
5 --- 24
5 --- 23
6 --- 11
6 x--> 13
6 --- 16

View File

@ -249,7 +249,7 @@ flowchart LR
76 <--x 68
77 <--x 69
81 <--x 89
82 <--x 86
82 <--x 88
83 <--x 87
84 <--x 88
84 <--x 86
```

View File

@ -1015,36 +1015,36 @@ flowchart LR
200 <--x 138
201 <--x 138
202 <--x 138
206 <--x 297
208 <--x 288
212 <--x 271
213 <--x 268
215 <--x 281
216 <--x 274
217 <--x 286
220 <--x 292
222 <--x 282
225 <--x 284
226 <--x 293
227 <--x 276
228 <--x 275
229 <--x 273
231 <--x 289
232 <--x 285
235 <--x 287
237 <--x 269
238 <--x 280
240 <--x 290
242 <--x 283
243 <--x 270
246 <--x 294
252 <--x 278
253 <--x 272
206 <--x 288
208 <--x 294
212 <--x 270
213 <--x 277
215 <--x 268
216 <--x 281
217 <--x 289
220 <--x 296
222 <--x 269
225 <--x 287
226 <--x 298
227 <--x 273
228 <--x 276
229 <--x 274
231 <--x 283
232 <--x 297
235 <--x 292
237 <--x 279
238 <--x 271
240 <--x 284
242 <--x 293
243 <--x 272
246 <--x 286
252 <--x 280
253 <--x 275
254 <--x 295
255 <--x 267
256 <--x 296
257 <--x 291
262 <--x 279
264 <--x 277
265 <--x 298
256 <--x 291
257 <--x 285
262 <--x 278
264 <--x 282
265 <--x 290
```

View File

@ -313,16 +313,16 @@ flowchart LR
265["SweepEdge Adjacent"]
266["SweepEdge Adjacent"]
267["SweepEdge Adjacent"]
268["EdgeCut Fillet<br>[394, 452, 10]"]
269["EdgeCut Fillet<br>[394, 452, 10]"]
268["EdgeCut Fillet<br>[5113, 5624, 8]"]
269["EdgeCut Fillet<br>[5113, 5624, 8]"]
270["EdgeCut Fillet<br>[5113, 5624, 8]"]
271["EdgeCut Fillet<br>[5113, 5624, 8]"]
272["EdgeCut Fillet<br>[5113, 5624, 8]"]
273["EdgeCut Fillet<br>[5113, 5624, 8]"]
274["EdgeCut Fillet<br>[5113, 5624, 8]"]
275["EdgeCut Fillet<br>[5113, 5624, 8]"]
276["EdgeCut Fillet<br>[5113, 5624, 8]"]
277["EdgeCut Fillet<br>[5113, 5624, 8]"]
276["EdgeCut Fillet<br>[394, 452, 10]"]
277["EdgeCut Fillet<br>[394, 452, 10]"]
1 --- 8
1 --- 9
1 --- 10
@ -563,7 +563,7 @@ flowchart LR
71 x--> 181
71 --- 222
71 --- 267
71 --- 269
71 --- 276
72 --- 164
72 x--> 179
72 --- 209
@ -888,13 +888,13 @@ flowchart LR
211 <--x 188
212 <--x 188
213 <--x 188
222 <--x 268
250 <--x 275
251 <--x 274
252 <--x 277
253 <--x 276
255 <--x 270
256 <--x 271
257 <--x 273
258 <--x 272
222 <--x 277
250 <--x 271
251 <--x 272
252 <--x 273
253 <--x 270
255 <--x 269
256 <--x 274
257 <--x 275
258 <--x 268
```

View File

@ -165,8 +165,8 @@ flowchart LR
41 <--x 35
42 <--x 35
43 <--x 35
38 <--x 57
40 <--x 55
38 <--x 55
40 <--x 57
49 <--x 53
51 <--x 52
```

View File

@ -434,16 +434,16 @@ flowchart LR
127 <--x 113
128 <--x 113
129 <--x 113
130 <--x 154
131 <--x 157
132 <--x 156
133 <--x 155
135 <--x 149
136 <--x 147
137 <--x 146
138 <--x 148
130 <--x 155
131 <--x 154
132 <--x 157
133 <--x 156
135 <--x 146
136 <--x 149
137 <--x 148
138 <--x 147
142 <--x 153
143 <--x 151
144 <--x 150
145 <--x 152
144 <--x 152
145 <--x 150
```

View File

@ -142,14 +142,14 @@ flowchart LR
126["SweepEdge Adjacent"]
127["SweepEdge Adjacent"]
128["SweepEdge Adjacent"]
129["EdgeCut Fillet<br>[2863, 3008, 0]"]
130["EdgeCut Fillet<br>[2863, 3008, 0]"]
131["EdgeCut Fillet<br>[3691, 3836, 0]"]
132["EdgeCut Fillet<br>[3691, 3836, 0]"]
133["EdgeCut Fillet<br>[1840, 2099, 0]"]
134["EdgeCut Fillet<br>[1840, 2099, 0]"]
135["EdgeCut Fillet<br>[1840, 2099, 0]"]
136["EdgeCut Fillet<br>[1840, 2099, 0]"]
129["EdgeCut Fillet<br>[1840, 2099, 0]"]
130["EdgeCut Fillet<br>[1840, 2099, 0]"]
131["EdgeCut Fillet<br>[1840, 2099, 0]"]
132["EdgeCut Fillet<br>[1840, 2099, 0]"]
133["EdgeCut Fillet<br>[2863, 3008, 0]"]
134["EdgeCut Fillet<br>[2863, 3008, 0]"]
135["EdgeCut Fillet<br>[3691, 3836, 0]"]
136["EdgeCut Fillet<br>[3691, 3836, 0]"]
1 --- 6
2 --- 7
2 --- 8
@ -449,12 +449,12 @@ flowchart LR
103 <--x 82
104 <--x 82
105 <--x 82
107 <--x 129
108 <--x 130
117 <--x 132
120 <--x 131
122 <--x 136
123 <--x 135
126 <--x 133
128 <--x 134
107 <--x 134
108 <--x 133
117 <--x 136
120 <--x 135
122 <--x 129
123 <--x 131
126 <--x 132
128 <--x 130
```

View File

@ -485,8 +485,8 @@ flowchart LR
116 <--x 94
117 <--x 94
118 <--x 94
120 <--x 144
122 <--x 143
120 <--x 143
122 <--x 144
137 <--x 145
140 <--x 146
```

View File

@ -439,11 +439,11 @@ flowchart LR
120 <--x 106
121 <--x 106
126 <--x 150
127 <--x 151
128 <--x 148
127 <--x 148
128 <--x 151
129 <--x 149
140 <--x 145
140 <--x 147
141 <--x 144
142 <--x 147
142 <--x 145
143 <--x 146
```

View File

@ -944,12 +944,12 @@ flowchart LR
212 <--x 163
213 <--x 163
214 <--x 163
228 <--x 269
229 <--x 268
228 <--x 268
229 <--x 269
230 <--x 266
231 <--x 267
245 <--x 271
245 <--x 272
246 <--x 273
247 <--x 270
248 <--x 272
247 <--x 271
248 <--x 270
```

View File

@ -380,12 +380,12 @@ flowchart LR
91 <--x 75
92 <--x 75
93 <--x 75
100 <--x 117
101 <--x 116
100 <--x 116
101 <--x 117
102 <--x 114
103 <--x 115
109 <--x 119
109 <--x 120
110 <--x 121
111 <--x 118
112 <--x 120
111 <--x 119
112 <--x 118
```

View File

@ -1427,7 +1427,7 @@ flowchart LR
60 x--> 567
60 --- 676
60 --- 883
60 --- 1036
60 --- 1037
61 --- 410
61 x--> 567
61 --- 678
@ -1436,7 +1436,7 @@ flowchart LR
62 x--> 567
62 --- 677
62 --- 884
62 --- 1037
62 --- 1035
63 --- 412
63 x--> 567
63 --- 675
@ -3764,5 +3764,5 @@ flowchart LR
820 <--x 616
821 <--x 616
676 <--x 1034
677 <--x 1035
677 <--x 1036
```

View File

@ -121,8 +121,8 @@ flowchart LR
31 <--x 29
32 <--x 29
33 <--x 29
34 <--x 40
34 <--x 39
35 <--x 41
36 <--x 38
37 <--x 39
36 <--x 40
37 <--x 38
```

View File

@ -393,17 +393,17 @@ flowchart LR
341["SweepEdge Adjacent"]
342["SweepEdge Adjacent"]
343["SweepEdge Adjacent"]
344["EdgeCut Fillet<br>[321, 383, 10]"]
344["EdgeCut Chamfer<br>[777, 1054, 8]"]
345["EdgeCut Chamfer<br>[777, 1054, 8]"]
346["EdgeCut Chamfer<br>[777, 1054, 8]"]
347["EdgeCut Chamfer<br>[777, 1054, 8]"]
348["EdgeCut Chamfer<br>[777, 1054, 8]"]
349["EdgeCut Fillet<br>[958, 1020, 11]"]
350["EdgeCut Fillet<br>[1261, 1323, 12]"]
351["EdgeCut Fillet<br>[1106, 1168, 10]"]
352["EdgeCut Fillet<br>[1294, 1355, 8]"]
348["EdgeCut Fillet<br>[1294, 1355, 8]"]
349["EdgeCut Fillet<br>[321, 383, 10]"]
350["EdgeCut Fillet<br>[1106, 1168, 10]"]
351["EdgeCut Fillet<br>[2001, 2063, 10]"]
352["EdgeCut Fillet<br>[958, 1020, 11]"]
353["EdgeCut Fillet<br>[1351, 1413, 11]"]
354["EdgeCut Fillet<br>[2001, 2063, 10]"]
354["EdgeCut Fillet<br>[1261, 1323, 12]"]
1 --- 7
2 --- 12
3 --- 13
@ -1066,15 +1066,15 @@ flowchart LR
274 <--x 240
275 <--x 240
276 <--x 240
254 <--x 350
262 <--x 344
268 <--x 349
271 <--x 354
277 <--x 352
254 <--x 354
262 <--x 349
268 <--x 352
271 <--x 351
277 <--x 348
285 <--x 353
286 <--x 351
322 <--x 346
323 <--x 347
324 <--x 345
325 <--x 348
286 <--x 350
322 <--x 347
323 <--x 345
324 <--x 346
325 <--x 344
```

View File

@ -449,7 +449,7 @@ flowchart LR
60 x--> 167
60 --- 181
60 --- 212
60 --- 238
60 --- 239
61 --- 147
61 x--> 156
61 --- 201
@ -740,5 +740,5 @@ flowchart LR
197 <--x 173
205 <--x 174
206 <--x 175
181 <--x 239
181 <--x 238
```

View File

@ -226,7 +226,7 @@ flowchart LR
21 x--> 77
21 --- 98
21 --- 107
21 --- 127
21 --- 130
22 --- 74
22 x--> 77
22 --- 88
@ -267,7 +267,7 @@ flowchart LR
32 x--> 77
32 --- 86
32 --- 110
32 --- 129
32 --- 127
34 --- 56
34 x--> 74
34 --- 82
@ -446,6 +446,6 @@ flowchart LR
100 <--x 78
101 <--x 78
102 <--x 78
86 <--x 130
86 <--x 129
98 <--x 128
```

View File

@ -80,7 +80,7 @@ flowchart LR
7 x--> 32
7 --- 40
7 --- 48
7 --- 49
7 --- 50
8 --- 26
8 x--> 30
8 --- 36
@ -164,5 +164,5 @@ flowchart LR
38 <--x 29
39 <--x 29
33 <--x 51
40 <--x 50
40 <--x 49
```

View File

@ -1160,20 +1160,20 @@ flowchart LR
294 <--x 244
295 <--x 244
296 <--x 244
297 <--x 368
299 <--x 369
305 <--x 364
306 <--x 365
309 <--x 354
310 <--x 357
311 <--x 356
312 <--x 355
318 <--x 367
319 <--x 366
321 <--x 359
322 <--x 358
323 <--x 361
297 <--x 362
299 <--x 365
305 <--x 363
306 <--x 364
309 <--x 355
310 <--x 356
311 <--x 357
312 <--x 354
318 <--x 369
319 <--x 367
321 <--x 361
322 <--x 359
323 <--x 358
324 <--x 360
345 <--x 362
348 <--x 363
345 <--x 368
348 <--x 366
```

View File

@ -80,7 +80,7 @@ flowchart LR
7 x--> 32
7 --- 40
7 --- 48
7 --- 49
7 --- 50
8 --- 26
8 x--> 30
8 --- 36
@ -164,5 +164,5 @@ flowchart LR
38 <--x 29
39 <--x 29
33 <--x 51
40 <--x 50
40 <--x 49
```

View File

@ -80,7 +80,7 @@ flowchart LR
7 x--> 32
7 --- 40
7 --- 48
7 --- 49
7 --- 50
8 --- 26
8 x--> 30
8 --- 36
@ -164,5 +164,5 @@ flowchart LR
38 <--x 29
39 <--x 29
33 <--x 51
40 <--x 50
40 <--x 49
```

View File

@ -80,7 +80,7 @@ flowchart LR
7 x--> 32
7 --- 40
7 --- 48
7 --- 49
7 --- 50
8 --- 26
8 x--> 30
8 --- 36
@ -164,5 +164,5 @@ flowchart LR
38 <--x 29
39 <--x 29
33 <--x 51
40 <--x 50
40 <--x 49
```