Skip to content

Commit 27e0177

Browse files
committed
Break into function to be more readable
1 parent d3b5688 commit 27e0177

1 file changed

Lines changed: 36 additions & 27 deletions

File tree

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

Lines changed: 36 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,41 @@ pub enum BeingExtruded {
730730
Face { face_id: Uuid, solid_id: Uuid },
731731
}
732732

733+
/// Which edge should we use for querying Solid3dGetExtrusionInfo and GetAdjacencyInfo?
734+
/// It can be any edge of the body, but if our body is a clone, we should use an edge of
735+
/// the original body, not the new cloned body.
736+
fn get_extrusion_info_edge_id(sketch: &Sketch, any_edge_id: Uuid, clone_id_map: Option<&HashMap<Uuid, Uuid>>) -> Uuid {
737+
// If this isn't a clone, there's no old/new body distinction.
738+
// So just use the edge.
739+
if sketch.clone.is_none() {
740+
return any_edge_id;
741+
}
742+
let Some(clone_map) = clone_id_map else {
743+
return any_edge_id;
744+
};
745+
746+
// clone_map maps old IDs -> new IDs.
747+
// If the `any_edge_id` is an ID of the OLD body
748+
// (we know this if it's a _key_ of the map)
749+
// we should use it (because that's the old body we're querying).
750+
if clone_map.contains_key(&any_edge_id) {
751+
return any_edge_id;
752+
}
753+
754+
// Otherwise, if the `any_edge_id` is an ID of the NEW body
755+
// (we know this if it's a _value_ of the map),
756+
// we should query the corresponding ID in the OLD body.
757+
// i.e. if it's a hashmap value, find the corresponding key.
758+
if let Some((old_edge_id, _)) = clone_map.iter().find(|(_, new_edge_id)| **new_edge_id == any_edge_id) {
759+
return *old_edge_id;
760+
}
761+
762+
// Fall back to this if the clone_map doesn't have the data we expect.
763+
// Probably will fail in the engine because it means the clone map was built wrong,
764+
// or KCL and the engine disagree about what geometry exists.
765+
any_edge_id
766+
}
767+
733768
#[allow(clippy::too_many_arguments)]
734769
pub(crate) async fn do_post_extrude<'a>(
735770
sketch: &Sketch,
@@ -772,33 +807,7 @@ pub(crate) async fn do_post_extrude<'a>(
772807

773808
// If the sketch is a clone, we will use the original info to get the extrusion face info.
774809
// So let's find an edge of the old body.
775-
let extrusion_info_edge_id = if sketch.clone.is_some() && clone_id_map.is_some() {
776-
if let Some(clone_map) = clone_id_map {
777-
// clone_map maps old IDs -> new IDs.
778-
// If the `any_edge_id` is an ID of the OLD body
779-
// (we know this if it's a _key_ of the map)
780-
// we should use it (because that's the old body we're querying).
781-
if clone_map.contains_key(&any_edge_id) {
782-
any_edge_id
783-
// Otherwise, if the `any_edge_id` is an ID of the NEW body
784-
// (we know this if it's a _value_ of the map),
785-
// we should query the corresponding ID in the OLD body.
786-
// i.e. if it's a hashmap value, find the corresponding key.
787-
} else if let Some((old_edge_id, _)) =
788-
clone_map.iter().find(|(_, new_edge_id)| **new_edge_id == any_edge_id)
789-
{
790-
*old_edge_id
791-
} else {
792-
any_edge_id
793-
}
794-
} else {
795-
any_edge_id
796-
}
797-
// If this isn't a clone, there's no old/new body distinction.
798-
// So just use the edge.
799-
} else {
800-
any_edge_id
801-
};
810+
let extrusion_info_edge_id = get_extrusion_info_edge_id(sketch, any_edge_id, clone_id_map);
802811
let mut sketch = sketch.clone();
803812
match body_type {
804813
BodyType::Solid => {

0 commit comments

Comments
 (0)