1use super::sketch::FaceTag;
4use crate::{
5 errors::KclError,
6 execution::{ExecState, Face, KclValue, Solid, types::RuntimeType},
7 std::Args,
8};
9
10pub async fn face_of(exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
12 let solid = args.get_unlabeled_kw_arg("solid", &RuntimeType::solid(), exec_state)?;
13 let face = args.get_kw_arg("face", &RuntimeType::tagged_face(), exec_state)?;
14
15 let face = make_face(solid, face, exec_state, &args).await?;
16
17 Ok(KclValue::Face { value: face })
18}
19
20pub(super) async fn make_face(
21 solid: Box<Solid>,
22 tag: FaceTag,
23 exec_state: &mut ExecState,
24 args: &Args,
25) -> Result<Box<Face>, KclError> {
26 let extrude_plane_id = tag.get_face_id(&solid, exec_state, args, true).await?;
27
28 let object_id = exec_state.next_object_id();
29 #[cfg(feature = "artifact-graph")]
30 {
31 let face_object = crate::front::Object {
32 id: object_id,
33 kind: crate::front::ObjectKind::Face(crate::front::Face { id: object_id }),
34 label: Default::default(),
35 comments: Default::default(),
36 artifact_id: extrude_plane_id.into(),
37 source: args.source_range.into(),
38 };
39 exec_state.add_scene_object(face_object, args.source_range);
40 }
41
42 Ok(Box::new(Face {
43 id: extrude_plane_id,
44 artifact_id: extrude_plane_id.into(),
45 object_id,
46 value: tag.to_string(),
47 x_axis: solid.sketch.on.x_axis(),
49 y_axis: solid.sketch.on.y_axis(),
50 units: solid.units,
51 solid,
52 meta: vec![args.source_range.into()],
53 }))
54}