Skip to main content

kcl_lib/std/
transform.rs

1//! Standard library transforms.
2
3use anyhow::Result;
4use kcmc::ModelingCmd;
5use kcmc::each_cmd as mcmd;
6use kcmc::length_unit::LengthUnit;
7use kcmc::shared;
8use kcmc::shared::OriginType;
9use kcmc::shared::Point3d;
10use kittycad_modeling_cmds as kcmc;
11
12use crate::errors::KclError;
13use crate::errors::KclErrorDetails;
14use crate::execution::ExecState;
15use crate::execution::HideableGeometry;
16use crate::execution::KclValue;
17use crate::execution::ModelingCmdMeta;
18use crate::execution::SolidOrSketchOrImportedGeometry;
19use crate::execution::types::PrimitiveType;
20use crate::execution::types::RuntimeType;
21use crate::std::Args;
22use crate::std::args::TyF64;
23use crate::std::axis_or_reference::Axis3dOrPoint3d;
24
25fn transform_by<T>(property: T, set: bool, origin: OriginType) -> shared::TransformBy<T> {
26    shared::TransformBy::builder()
27        .property(property)
28        .set(set)
29        .origin(origin)
30        .build()
31}
32
33/// Scale a solid or a sketch.
34pub async fn scale(exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
35    let objects = args.get_unlabeled_kw_arg(
36        "objects",
37        &RuntimeType::Union(vec![
38            RuntimeType::sketches(),
39            RuntimeType::solids(),
40            RuntimeType::imported(),
41        ]),
42        exec_state,
43    )?;
44    let scale_x: Option<TyF64> = args.get_kw_arg_opt("x", &RuntimeType::count(), exec_state)?;
45    let scale_y: Option<TyF64> = args.get_kw_arg_opt("y", &RuntimeType::count(), exec_state)?;
46    let scale_z: Option<TyF64> = args.get_kw_arg_opt("z", &RuntimeType::count(), exec_state)?;
47    let factor: Option<TyF64> = args.get_kw_arg_opt("factor", &RuntimeType::count(), exec_state)?;
48    for scale_dim in [&scale_x, &scale_y, &scale_z, &factor] {
49        if let Some(num) = scale_dim
50            && num.n == 0.0
51        {
52            return Err(KclError::new_semantic(KclErrorDetails::new(
53                "Cannot scale by 0".to_string(),
54                vec![args.source_range],
55            )));
56        }
57    }
58    let (scale_x, scale_y, scale_z) = match (scale_x, scale_y, scale_z, factor) {
59        (None, None, None, Some(factor)) => (Some(factor.clone()), Some(factor.clone()), Some(factor)),
60        // Ensure at least one scale value is provided.
61        (None, None, None, None) => {
62            return Err(KclError::new_semantic(KclErrorDetails::new(
63                "Expected `x`, `y`, `z` or `factor` to be provided.".to_string(),
64                vec![args.source_range],
65            )));
66        }
67        (x, y, z, None) => (x, y, z),
68        _ => {
69            return Err(KclError::new_semantic(KclErrorDetails::new(
70                "If you give `factor` then you cannot use  `x`, `y`, or `z`".to_string(),
71                vec![args.source_range],
72            )));
73        }
74    };
75    let global = args.get_kw_arg_opt("global", &RuntimeType::bool(), exec_state)?;
76
77    let objects = inner_scale(
78        objects,
79        scale_x.map(|t| t.n),
80        scale_y.map(|t| t.n),
81        scale_z.map(|t| t.n),
82        global,
83        exec_state,
84        args,
85    )
86    .await?;
87    Ok(objects.into())
88}
89
90async fn inner_scale(
91    objects: SolidOrSketchOrImportedGeometry,
92    x: Option<f64>,
93    y: Option<f64>,
94    z: Option<f64>,
95    global: Option<bool>,
96    exec_state: &mut ExecState,
97    args: Args,
98) -> Result<SolidOrSketchOrImportedGeometry, KclError> {
99    // If we have a solid, flush the fillets and chamfers.
100    // Only transforms needs this, it is very odd, see: https://github.com/KittyCAD/modeling-app/issues/5880
101    if let SolidOrSketchOrImportedGeometry::SolidSet(solids) = &objects {
102        exec_state
103            .flush_batch_for_solids(ModelingCmdMeta::from_args(exec_state, &args), solids)
104            .await?;
105    }
106
107    let is_global = global.unwrap_or(false);
108    let origin = if is_global {
109        OriginType::Global
110    } else {
111        OriginType::Local
112    };
113
114    let mut objects = objects.clone();
115    for object_id in objects.ids(&args.ctx).await? {
116        let transform = shared::ComponentTransform::builder()
117            .scale(transform_by(
118                Point3d {
119                    x: x.unwrap_or(1.0),
120                    y: y.unwrap_or(1.0),
121                    z: z.unwrap_or(1.0),
122                },
123                false,
124                origin,
125            ))
126            .build();
127        let transforms = vec![transform];
128        exec_state
129            .batch_modeling_cmd(
130                ModelingCmdMeta::from_args(exec_state, &args),
131                ModelingCmd::from(
132                    mcmd::SetObjectTransform::builder()
133                        .object_id(object_id)
134                        .transforms(transforms)
135                        .build(),
136                ),
137            )
138            .await?;
139    }
140
141    Ok(objects)
142}
143
144/// Move a solid or a sketch.
145pub async fn translate(exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
146    let objects = args.get_unlabeled_kw_arg(
147        "objects",
148        &RuntimeType::Union(vec![
149            RuntimeType::sketches(),
150            RuntimeType::solids(),
151            RuntimeType::imported(),
152        ]),
153        exec_state,
154    )?;
155    let translate_x: Option<TyF64> = args.get_kw_arg_opt("x", &RuntimeType::length(), exec_state)?;
156    let translate_y: Option<TyF64> = args.get_kw_arg_opt("y", &RuntimeType::length(), exec_state)?;
157    let translate_z: Option<TyF64> = args.get_kw_arg_opt("z", &RuntimeType::length(), exec_state)?;
158    let xyz: Option<[TyF64; 3]> = args.get_kw_arg_opt("xyz", &RuntimeType::point3d(), exec_state)?;
159    let global = args.get_kw_arg_opt("global", &RuntimeType::bool(), exec_state)?;
160
161    let objects = inner_translate(
162        objects,
163        xyz,
164        translate_x,
165        translate_y,
166        translate_z,
167        global,
168        exec_state,
169        args,
170    )
171    .await?;
172    Ok(objects.into())
173}
174
175#[allow(clippy::too_many_arguments)]
176async fn inner_translate(
177    objects: SolidOrSketchOrImportedGeometry,
178    xyz: Option<[TyF64; 3]>,
179    x: Option<TyF64>,
180    y: Option<TyF64>,
181    z: Option<TyF64>,
182    global: Option<bool>,
183    exec_state: &mut ExecState,
184    args: Args,
185) -> Result<SolidOrSketchOrImportedGeometry, KclError> {
186    let (x, y, z) = match (xyz, x, y, z) {
187        (None, None, None, None) => {
188            return Err(KclError::new_semantic(KclErrorDetails::new(
189                "Expected `x`, `y`, or `z` to be provided.".to_string(),
190                vec![args.source_range],
191            )));
192        }
193        (Some(xyz), None, None, None) => {
194            let [x, y, z] = xyz;
195            (Some(x), Some(y), Some(z))
196        }
197        (None, x, y, z) => (x, y, z),
198        (Some(_), _, _, _) => {
199            return Err(KclError::new_semantic(KclErrorDetails::new(
200                "If you provide all 3 distances via the `xyz` arg, you cannot provide them separately via the `x`, `y` or `z` args."
201                    .to_string(),
202                vec![args.source_range],
203            )));
204        }
205    };
206    // If we have a solid, flush the fillets and chamfers.
207    // Only transforms needs this, it is very odd, see: https://github.com/KittyCAD/modeling-app/issues/5880
208    if let SolidOrSketchOrImportedGeometry::SolidSet(solids) = &objects {
209        exec_state
210            .flush_batch_for_solids(ModelingCmdMeta::from_args(exec_state, &args), solids)
211            .await?;
212    }
213
214    let is_global = global.unwrap_or(false);
215    let origin = if is_global {
216        OriginType::Global
217    } else {
218        OriginType::Local
219    };
220
221    let translation = shared::Point3d {
222        x: LengthUnit(x.as_ref().map(|t| t.to_mm()).unwrap_or_default()),
223        y: LengthUnit(y.as_ref().map(|t| t.to_mm()).unwrap_or_default()),
224        z: LengthUnit(z.as_ref().map(|t| t.to_mm()).unwrap_or_default()),
225    };
226    let mut objects = objects.clone();
227    for object_id in objects.ids(&args.ctx).await? {
228        let transform = shared::ComponentTransform::builder()
229            .translate(transform_by(translation, false, origin))
230            .build();
231        let transforms = vec![transform];
232        exec_state
233            .batch_modeling_cmd(
234                ModelingCmdMeta::from_args(exec_state, &args),
235                ModelingCmd::from(
236                    mcmd::SetObjectTransform::builder()
237                        .object_id(object_id)
238                        .transforms(transforms)
239                        .build(),
240                ),
241            )
242            .await?;
243    }
244
245    Ok(objects)
246}
247
248/// Rotate a solid or a sketch.
249pub async fn rotate(exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
250    let objects = args.get_unlabeled_kw_arg(
251        "objects",
252        &RuntimeType::Union(vec![
253            RuntimeType::sketches(),
254            RuntimeType::solids(),
255            RuntimeType::imported(),
256        ]),
257        exec_state,
258    )?;
259    let roll: Option<TyF64> = args.get_kw_arg_opt("roll", &RuntimeType::degrees(), exec_state)?;
260    let pitch: Option<TyF64> = args.get_kw_arg_opt("pitch", &RuntimeType::degrees(), exec_state)?;
261    let yaw: Option<TyF64> = args.get_kw_arg_opt("yaw", &RuntimeType::degrees(), exec_state)?;
262    let axis: Option<Axis3dOrPoint3d> = args.get_kw_arg_opt(
263        "axis",
264        &RuntimeType::Union(vec![
265            RuntimeType::Primitive(PrimitiveType::Axis3d),
266            RuntimeType::point3d(),
267        ]),
268        exec_state,
269    )?;
270    let origin = axis.clone().map(|a| a.axis_origin()).unwrap_or_default();
271    let axis = axis.map(|a| a.to_point3d());
272    let angle: Option<TyF64> = args.get_kw_arg_opt("angle", &RuntimeType::degrees(), exec_state)?;
273    let global = args.get_kw_arg_opt("global", &RuntimeType::bool(), exec_state)?;
274
275    // Check if no rotation values are provided.
276    if roll.is_none() && pitch.is_none() && yaw.is_none() && axis.is_none() && angle.is_none() {
277        return Err(KclError::new_semantic(KclErrorDetails::new(
278            "Expected `roll`, `pitch`, and `yaw` or `axis` and `angle` to be provided.".to_string(),
279            vec![args.source_range],
280        )));
281    }
282
283    // If they give us a roll, pitch, or yaw, they must give us at least one of them.
284    if roll.is_some() || pitch.is_some() || yaw.is_some() {
285        // Ensure they didn't also provide an axis or angle.
286        if axis.is_some() || angle.is_some() {
287            return Err(KclError::new_semantic(KclErrorDetails::new(
288                "Expected `axis` and `angle` to not be provided when `roll`, `pitch`, and `yaw` are provided."
289                    .to_owned(),
290                vec![args.source_range],
291            )));
292        }
293    }
294
295    // If they give us an axis or angle, they must give us both.
296    if axis.is_some() || angle.is_some() {
297        if axis.is_none() {
298            return Err(KclError::new_semantic(KclErrorDetails::new(
299                "Expected `axis` to be provided when `angle` is provided.".to_string(),
300                vec![args.source_range],
301            )));
302        }
303        if angle.is_none() {
304            return Err(KclError::new_semantic(KclErrorDetails::new(
305                "Expected `angle` to be provided when `axis` is provided.".to_string(),
306                vec![args.source_range],
307            )));
308        }
309
310        // Ensure they didn't also provide a roll, pitch, or yaw.
311        if roll.is_some() || pitch.is_some() || yaw.is_some() {
312            return Err(KclError::new_semantic(KclErrorDetails::new(
313                "Expected `roll`, `pitch`, and `yaw` to not be provided when `axis` and `angle` are provided."
314                    .to_owned(),
315                vec![args.source_range],
316            )));
317        }
318    }
319
320    // Validate the roll, pitch, and yaw values.
321    if let Some(roll) = &roll
322        && !(-360.0..=360.0).contains(&roll.n)
323    {
324        return Err(KclError::new_semantic(KclErrorDetails::new(
325            format!("Expected roll to be between -360 and 360, found `{}`", roll.n),
326            vec![args.source_range],
327        )));
328    }
329    if let Some(pitch) = &pitch
330        && !(-360.0..=360.0).contains(&pitch.n)
331    {
332        return Err(KclError::new_semantic(KclErrorDetails::new(
333            format!("Expected pitch to be between -360 and 360, found `{}`", pitch.n),
334            vec![args.source_range],
335        )));
336    }
337    if let Some(yaw) = &yaw
338        && !(-360.0..=360.0).contains(&yaw.n)
339    {
340        return Err(KclError::new_semantic(KclErrorDetails::new(
341            format!("Expected yaw to be between -360 and 360, found `{}`", yaw.n),
342            vec![args.source_range],
343        )));
344    }
345
346    // Validate the axis and angle values.
347    if let Some(angle) = &angle
348        && !(-360.0..=360.0).contains(&angle.n)
349    {
350        return Err(KclError::new_semantic(KclErrorDetails::new(
351            format!("Expected angle to be between -360 and 360, found `{}`", angle.n),
352            vec![args.source_range],
353        )));
354    }
355
356    let objects = inner_rotate(
357        objects,
358        roll.map(|t| t.n),
359        pitch.map(|t| t.n),
360        yaw.map(|t| t.n),
361        // Don't adjust axis units since the axis must be normalized and only the direction
362        // should be significant, not the magnitude.
363        axis.map(|a| [a[0].n, a[1].n, a[2].n]),
364        origin.map(|a| [a[0].n, a[1].n, a[2].n]),
365        angle.map(|t| t.n),
366        global,
367        exec_state,
368        args,
369    )
370    .await?;
371    Ok(objects.into())
372}
373
374#[allow(clippy::too_many_arguments)]
375async fn inner_rotate(
376    objects: SolidOrSketchOrImportedGeometry,
377    roll: Option<f64>,
378    pitch: Option<f64>,
379    yaw: Option<f64>,
380    axis: Option<[f64; 3]>,
381    origin: Option<[f64; 3]>,
382    angle: Option<f64>,
383    global: Option<bool>,
384    exec_state: &mut ExecState,
385    args: Args,
386) -> Result<SolidOrSketchOrImportedGeometry, KclError> {
387    // If we have a solid, flush the fillets and chamfers.
388    // Only transforms needs this, it is very odd, see: https://github.com/KittyCAD/modeling-app/issues/5880
389    if let SolidOrSketchOrImportedGeometry::SolidSet(solids) = &objects {
390        exec_state
391            .flush_batch_for_solids(ModelingCmdMeta::from_args(exec_state, &args), solids)
392            .await?;
393    }
394
395    let origin = if let Some(origin) = origin {
396        OriginType::Custom {
397            origin: shared::Point3d {
398                x: origin[0],
399                y: origin[1],
400                z: origin[2],
401            },
402        }
403    } else if global.unwrap_or(false) {
404        OriginType::Global
405    } else {
406        OriginType::Local
407    };
408
409    let mut objects = objects.clone();
410    for object_id in objects.ids(&args.ctx).await? {
411        if let (Some(axis), Some(angle)) = (&axis, angle) {
412            let transform = shared::ComponentTransform::builder()
413                .rotate_angle_axis(transform_by(
414                    shared::Point4d {
415                        x: axis[0],
416                        y: axis[1],
417                        z: axis[2],
418                        w: angle,
419                    },
420                    false,
421                    origin,
422                ))
423                .build();
424            let transforms = vec![transform];
425            exec_state
426                .batch_modeling_cmd(
427                    ModelingCmdMeta::from_args(exec_state, &args),
428                    ModelingCmd::from(
429                        mcmd::SetObjectTransform::builder()
430                            .object_id(object_id)
431                            .transforms(transforms)
432                            .build(),
433                    ),
434                )
435                .await?;
436        } else {
437            // Do roll, pitch, and yaw.
438            let transform = shared::ComponentTransform::builder()
439                .rotate_rpy(transform_by(
440                    shared::Point3d {
441                        x: roll.unwrap_or(0.0),
442                        y: pitch.unwrap_or(0.0),
443                        z: yaw.unwrap_or(0.0),
444                    },
445                    false,
446                    origin,
447                ))
448                .build();
449            let transforms = vec![transform];
450            exec_state
451                .batch_modeling_cmd(
452                    ModelingCmdMeta::from_args(exec_state, &args),
453                    ModelingCmd::from(
454                        mcmd::SetObjectTransform::builder()
455                            .object_id(object_id)
456                            .transforms(transforms)
457                            .build(),
458                    ),
459                )
460                .await?;
461        }
462    }
463
464    Ok(objects)
465}
466
467/// Hide solids, sketches, helices, or imported objects.
468pub async fn hide(exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
469    let objects = args.get_unlabeled_kw_arg(
470        "objects",
471        &RuntimeType::Union(vec![
472            RuntimeType::sketches(),
473            RuntimeType::solids(),
474            RuntimeType::helices(),
475            RuntimeType::imported(),
476            RuntimeType::gdts(),
477        ]),
478        exec_state,
479    )?;
480
481    let objects = hide_inner(objects, true, exec_state, args).await?;
482    Ok(objects.into())
483}
484
485async fn hide_inner(
486    mut objects: HideableGeometry,
487    hidden: bool,
488    exec_state: &mut ExecState,
489    args: Args,
490) -> Result<HideableGeometry, KclError> {
491    for object_id in objects.ids(&args.ctx).await? {
492        exec_state
493            .batch_modeling_cmd(
494                ModelingCmdMeta::from_args(exec_state, &args),
495                ModelingCmd::from(
496                    mcmd::ObjectVisible::builder()
497                        .object_id(object_id)
498                        .hidden(hidden)
499                        .build(),
500                ),
501            )
502            .await?;
503    }
504
505    Ok(objects)
506}
507
508#[cfg(test)]
509mod tests {
510    use pretty_assertions::assert_eq;
511
512    use crate::execution::parse_execute;
513
514    const PIPE: &str = r#"sweepPath = startSketchOn(XZ)
515    |> startProfile(at = [0.05, 0.05])
516    |> line(end = [0, 7])
517    |> tangentialArc(angle = 90, radius = 5)
518    |> line(end = [-3, 0])
519    |> tangentialArc(angle = -90, radius = 5)
520    |> line(end = [0, 7])
521
522// Create a hole for the pipe.
523pipeHole = startSketchOn(XY)
524    |> circle(
525        center = [0, 0],
526        radius = 1.5,
527    )
528sweepSketch = startSketchOn(XY)
529    |> circle(
530        center = [0, 0],
531        radius = 2,
532        )              
533    |> subtract2d(tool = pipeHole)
534    |> sweep(
535        path = sweepPath,
536    )"#;
537
538    #[tokio::test(flavor = "multi_thread")]
539    async fn test_rotate_empty() {
540        let ast = PIPE.to_string()
541            + r#"
542    |> rotate()
543"#;
544        let result = parse_execute(&ast).await;
545        assert!(result.is_err());
546        assert_eq!(
547            result.unwrap_err().message(),
548            r#"Expected `roll`, `pitch`, and `yaw` or `axis` and `angle` to be provided."#.to_string()
549        );
550    }
551
552    #[tokio::test(flavor = "multi_thread")]
553    async fn test_rotate_axis_no_angle() {
554        let ast = PIPE.to_string()
555            + r#"
556    |> rotate(
557    axis =  [0, 0, 1.0],
558    )
559"#;
560        let result = parse_execute(&ast).await;
561        assert!(result.is_err());
562        assert_eq!(
563            result.unwrap_err().message(),
564            r#"Expected `angle` to be provided when `axis` is provided."#.to_string()
565        );
566    }
567
568    #[tokio::test(flavor = "multi_thread")]
569    async fn test_rotate_angle_no_axis() {
570        let ast = PIPE.to_string()
571            + r#"
572    |> rotate(
573    angle = 90,
574    )
575"#;
576        let result = parse_execute(&ast).await;
577        assert!(result.is_err());
578        assert_eq!(
579            result.unwrap_err().message(),
580            r#"Expected `axis` to be provided when `angle` is provided."#.to_string()
581        );
582    }
583
584    #[tokio::test(flavor = "multi_thread")]
585    async fn test_rotate_angle_out_of_range() {
586        let ast = PIPE.to_string()
587            + r#"
588    |> rotate(
589    axis =  [0, 0, 1.0],
590    angle = 900,
591    )
592"#;
593        let result = parse_execute(&ast).await;
594        assert!(result.is_err());
595        assert_eq!(
596            result.unwrap_err().message(),
597            r#"Expected angle to be between -360 and 360, found `900`"#.to_string()
598        );
599    }
600
601    #[tokio::test(flavor = "multi_thread")]
602    async fn test_rotate_angle_axis_yaw() {
603        let ast = PIPE.to_string()
604            + r#"
605    |> rotate(
606    axis =  [0, 0, 1.0],
607    angle = 90,
608    yaw = 90,
609   ) 
610"#;
611        let result = parse_execute(&ast).await;
612        assert!(result.is_err());
613        assert_eq!(
614            result.unwrap_err().message(),
615            r#"Expected `axis` and `angle` to not be provided when `roll`, `pitch`, and `yaw` are provided."#
616                .to_string()
617        );
618    }
619
620    #[tokio::test(flavor = "multi_thread")]
621    async fn test_rotate_yaw_only() {
622        let ast = PIPE.to_string()
623            + r#"
624    |> rotate(
625    yaw = 90,
626    )
627"#;
628        parse_execute(&ast).await.unwrap();
629    }
630
631    #[tokio::test(flavor = "multi_thread")]
632    async fn test_rotate_pitch_only() {
633        let ast = PIPE.to_string()
634            + r#"
635    |> rotate(
636    pitch = 90,
637    )
638"#;
639        parse_execute(&ast).await.unwrap();
640    }
641
642    #[tokio::test(flavor = "multi_thread")]
643    async fn test_rotate_roll_only() {
644        let ast = PIPE.to_string()
645            + r#"
646    |> rotate(
647    pitch = 90,
648    )
649"#;
650        parse_execute(&ast).await.unwrap();
651    }
652
653    #[tokio::test(flavor = "multi_thread")]
654    async fn test_rotate_yaw_out_of_range() {
655        let ast = PIPE.to_string()
656            + r#"
657    |> rotate(
658    yaw = 900,
659    pitch = 90,
660    roll = 90,
661    )
662"#;
663        let result = parse_execute(&ast).await;
664        assert!(result.is_err());
665        assert_eq!(
666            result.unwrap_err().message(),
667            r#"Expected yaw to be between -360 and 360, found `900`"#.to_string()
668        );
669    }
670
671    #[tokio::test(flavor = "multi_thread")]
672    async fn test_rotate_roll_out_of_range() {
673        let ast = PIPE.to_string()
674            + r#"
675    |> rotate(
676    yaw = 90,
677    pitch = 90,
678    roll = 900,
679    )
680"#;
681        let result = parse_execute(&ast).await;
682        assert!(result.is_err());
683        assert_eq!(
684            result.unwrap_err().message(),
685            r#"Expected roll to be between -360 and 360, found `900`"#.to_string()
686        );
687    }
688
689    #[tokio::test(flavor = "multi_thread")]
690    async fn test_rotate_pitch_out_of_range() {
691        let ast = PIPE.to_string()
692            + r#"
693    |> rotate(
694    yaw = 90,
695    pitch = 900,
696    roll = 90,
697    )
698"#;
699        let result = parse_execute(&ast).await;
700        assert!(result.is_err());
701        assert_eq!(
702            result.unwrap_err().message(),
703            r#"Expected pitch to be between -360 and 360, found `900`"#.to_string()
704        );
705    }
706
707    #[tokio::test(flavor = "multi_thread")]
708    async fn test_rotate_roll_pitch_yaw_with_angle() {
709        let ast = PIPE.to_string()
710            + r#"
711    |> rotate(
712    yaw = 90,
713    pitch = 90,
714    roll = 90,
715    angle = 90,
716    )
717"#;
718        let result = parse_execute(&ast).await;
719        assert!(result.is_err());
720        assert_eq!(
721            result.unwrap_err().message(),
722            r#"Expected `axis` and `angle` to not be provided when `roll`, `pitch`, and `yaw` are provided."#
723                .to_string()
724        );
725    }
726
727    #[tokio::test(flavor = "multi_thread")]
728    async fn test_translate_no_args() {
729        let ast = PIPE.to_string()
730            + r#"
731    |> translate(
732    )
733"#;
734        let result = parse_execute(&ast).await;
735        assert!(result.is_err());
736        assert_eq!(
737            result.unwrap_err().message(),
738            r#"Expected `x`, `y`, or `z` to be provided."#.to_string()
739        );
740    }
741
742    #[tokio::test(flavor = "multi_thread")]
743    async fn test_scale_no_args() {
744        let ast = PIPE.to_string()
745            + r#"
746    |> scale(
747    )
748"#;
749        let result = parse_execute(&ast).await;
750        assert!(result.is_err());
751        assert_eq!(
752            result.unwrap_err().message(),
753            r#"Expected `x`, `y`, `z` or `factor` to be provided."#.to_string()
754        );
755    }
756
757    #[tokio::test(flavor = "multi_thread")]
758    async fn test_hide_pipe_solid_ok() {
759        let ast = PIPE.to_string()
760            + r#"
761    |> hide()
762"#;
763        parse_execute(&ast).await.unwrap();
764    }
765
766    #[tokio::test(flavor = "multi_thread")]
767    async fn test_hide_helix() {
768        let ast = r#"helixPath = helix(
769  axis = Z,
770  radius = 5,
771  length = 10,
772  revolutions = 3,
773  angleStart = 360,
774  ccw = false,
775)
776
777hide(helixPath)
778"#;
779        parse_execute(ast).await.unwrap();
780    }
781
782    #[tokio::test(flavor = "multi_thread")]
783    async fn test_hide_sketch_block() {
784        let ast = r#"sketch001 = sketch(on = XY) {
785  circle001 = circle(start = [var 1.16mm, var 4.24mm], center = [var -1.81mm, var -0.5mm])
786}
787
788hide(sketch001)
789"#;
790        parse_execute(ast).await.unwrap();
791    }
792
793    #[tokio::test(flavor = "multi_thread")]
794    async fn test_hide_no_objects() {
795        let ast = r#"hidden = hide()"#;
796        let result = parse_execute(ast).await;
797        assert!(result.is_err());
798        assert_eq!(
799            result.unwrap_err().message(),
800            r#"This function expects an unlabeled first parameter, but you haven't passed it one."#.to_string()
801        );
802    }
803}