KCL: Break face-analyzing map into its own function (#3792)
This commit is contained in:
@ -1,8 +1,10 @@
|
|||||||
//! Functions related to extruding.
|
//! Functions related to extruding.
|
||||||
|
|
||||||
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use derive_docs::stdlib;
|
use derive_docs::stdlib;
|
||||||
use kittycad::types::ExtrusionFaceCapType;
|
use kittycad::types::{ExtrusionFaceCapType, ExtrusionFaceInfo};
|
||||||
use schemars::JsonSchema;
|
use schemars::JsonSchema;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
@ -217,26 +219,11 @@ pub(crate) async fn do_post_extrude(
|
|||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a hashmap for quick id lookup
|
let Faces {
|
||||||
let mut face_id_map = std::collections::HashMap::new();
|
sides: face_id_map,
|
||||||
// creating fake ids for start and end caps is to make extrudes mock-execute safe
|
start_cap_id,
|
||||||
let (mut start_cap_id, mut end_cap_id) = if args.ctx.is_mock {
|
end_cap_id,
|
||||||
(Some(Uuid::new_v4()), Some(Uuid::new_v4()))
|
} = analyze_faces(&args, face_infos);
|
||||||
} else {
|
|
||||||
(None, None)
|
|
||||||
};
|
|
||||||
for face_info in face_infos {
|
|
||||||
match face_info.cap {
|
|
||||||
ExtrusionFaceCapType::Bottom => start_cap_id = face_info.face_id,
|
|
||||||
ExtrusionFaceCapType::Top => end_cap_id = face_info.face_id,
|
|
||||||
ExtrusionFaceCapType::None => {
|
|
||||||
if let Some(curve_id) = face_info.curve_id {
|
|
||||||
face_id_map.insert(curve_id, face_info.face_id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Iterate over the sketch_group.value array and add face_id to GeoMeta
|
// Iterate over the sketch_group.value array and add face_id to GeoMeta
|
||||||
let new_value = sketch_group
|
let new_value = sketch_group
|
||||||
.value
|
.value
|
||||||
@ -300,3 +287,37 @@ pub(crate) async fn do_post_extrude(
|
|||||||
edge_cuts: vec![],
|
edge_cuts: vec![],
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Default)]
|
||||||
|
struct Faces {
|
||||||
|
/// Maps curve ID to face ID for each side.
|
||||||
|
sides: HashMap<Uuid, Option<Uuid>>,
|
||||||
|
/// Top face ID.
|
||||||
|
end_cap_id: Option<Uuid>,
|
||||||
|
/// Bottom face ID.
|
||||||
|
start_cap_id: Option<Uuid>,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn analyze_faces(args: &Args, face_infos: Vec<ExtrusionFaceInfo>) -> Faces {
|
||||||
|
let mut faces = Faces {
|
||||||
|
sides: HashMap::with_capacity(face_infos.len()),
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
if args.ctx.is_mock {
|
||||||
|
// Create fake IDs for start and end caps, to make extrudes mock-execute safe
|
||||||
|
faces.start_cap_id = Some(Uuid::new_v4());
|
||||||
|
faces.end_cap_id = Some(Uuid::new_v4());
|
||||||
|
}
|
||||||
|
for face_info in face_infos {
|
||||||
|
match face_info.cap {
|
||||||
|
ExtrusionFaceCapType::Bottom => faces.start_cap_id = face_info.face_id,
|
||||||
|
ExtrusionFaceCapType::Top => faces.end_cap_id = face_info.face_id,
|
||||||
|
ExtrusionFaceCapType::None => {
|
||||||
|
if let Some(curve_id) = face_info.curve_id {
|
||||||
|
faces.sides.insert(curve_id, face_info.face_id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
faces
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user