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, 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::solids(),
473            RuntimeType::helices(),
474            RuntimeType::imported(),
475        ]),
476        exec_state,
477    )?;
478
479    let objects = hide_inner(objects, true, exec_state, args).await?;
480    Ok(objects.into())
481}
482
483async fn hide_inner(
484    mut objects: HideableGeometry,
485    hidden: bool,
486    exec_state: &mut ExecState,
487    args: Args,
488) -> Result<HideableGeometry, KclError> {
489    for object_id in objects.ids(&args.ctx).await? {
490        exec_state
491            .batch_modeling_cmd(
492                ModelingCmdMeta::from_args(exec_state, &args),
493                ModelingCmd::from(
494                    mcmd::ObjectVisible::builder()
495                        .object_id(object_id)
496                        .hidden(hidden)
497                        .build(),
498                ),
499            )
500            .await?;
501    }
502
503    Ok(objects)
504}
505
506#[cfg(test)]
507mod tests {
508    use pretty_assertions::assert_eq;
509
510    use crate::execution::parse_execute;
511
512    const PIPE: &str = r#"sweepPath = startSketchOn(XZ)
513    |> startProfile(at = [0.05, 0.05])
514    |> line(end = [0, 7])
515    |> tangentialArc(angle = 90, radius = 5)
516    |> line(end = [-3, 0])
517    |> tangentialArc(angle = -90, radius = 5)
518    |> line(end = [0, 7])
519
520// Create a hole for the pipe.
521pipeHole = startSketchOn(XY)
522    |> circle(
523        center = [0, 0],
524        radius = 1.5,
525    )
526sweepSketch = startSketchOn(XY)
527    |> circle(
528        center = [0, 0],
529        radius = 2,
530        )              
531    |> subtract2d(tool = pipeHole)
532    |> sweep(
533        path = sweepPath,
534    )"#;
535
536    #[tokio::test(flavor = "multi_thread")]
537    async fn test_rotate_empty() {
538        let ast = PIPE.to_string()
539            + r#"
540    |> rotate()
541"#;
542        let result = parse_execute(&ast).await;
543        assert!(result.is_err());
544        assert_eq!(
545            result.unwrap_err().message(),
546            r#"Expected `roll`, `pitch`, and `yaw` or `axis` and `angle` to be provided."#.to_string()
547        );
548    }
549
550    #[tokio::test(flavor = "multi_thread")]
551    async fn test_rotate_axis_no_angle() {
552        let ast = PIPE.to_string()
553            + r#"
554    |> rotate(
555    axis =  [0, 0, 1.0],
556    )
557"#;
558        let result = parse_execute(&ast).await;
559        assert!(result.is_err());
560        assert_eq!(
561            result.unwrap_err().message(),
562            r#"Expected `angle` to be provided when `axis` is provided."#.to_string()
563        );
564    }
565
566    #[tokio::test(flavor = "multi_thread")]
567    async fn test_rotate_angle_no_axis() {
568        let ast = PIPE.to_string()
569            + r#"
570    |> rotate(
571    angle = 90,
572    )
573"#;
574        let result = parse_execute(&ast).await;
575        assert!(result.is_err());
576        assert_eq!(
577            result.unwrap_err().message(),
578            r#"Expected `axis` to be provided when `angle` is provided."#.to_string()
579        );
580    }
581
582    #[tokio::test(flavor = "multi_thread")]
583    async fn test_rotate_angle_out_of_range() {
584        let ast = PIPE.to_string()
585            + r#"
586    |> rotate(
587    axis =  [0, 0, 1.0],
588    angle = 900,
589    )
590"#;
591        let result = parse_execute(&ast).await;
592        assert!(result.is_err());
593        assert_eq!(
594            result.unwrap_err().message(),
595            r#"Expected angle to be between -360 and 360, found `900`"#.to_string()
596        );
597    }
598
599    #[tokio::test(flavor = "multi_thread")]
600    async fn test_rotate_angle_axis_yaw() {
601        let ast = PIPE.to_string()
602            + r#"
603    |> rotate(
604    axis =  [0, 0, 1.0],
605    angle = 90,
606    yaw = 90,
607   ) 
608"#;
609        let result = parse_execute(&ast).await;
610        assert!(result.is_err());
611        assert_eq!(
612            result.unwrap_err().message(),
613            r#"Expected `axis` and `angle` to not be provided when `roll`, `pitch`, and `yaw` are provided."#
614                .to_string()
615        );
616    }
617
618    #[tokio::test(flavor = "multi_thread")]
619    async fn test_rotate_yaw_only() {
620        let ast = PIPE.to_string()
621            + r#"
622    |> rotate(
623    yaw = 90,
624    )
625"#;
626        parse_execute(&ast).await.unwrap();
627    }
628
629    #[tokio::test(flavor = "multi_thread")]
630    async fn test_rotate_pitch_only() {
631        let ast = PIPE.to_string()
632            + r#"
633    |> rotate(
634    pitch = 90,
635    )
636"#;
637        parse_execute(&ast).await.unwrap();
638    }
639
640    #[tokio::test(flavor = "multi_thread")]
641    async fn test_rotate_roll_only() {
642        let ast = PIPE.to_string()
643            + r#"
644    |> rotate(
645    pitch = 90,
646    )
647"#;
648        parse_execute(&ast).await.unwrap();
649    }
650
651    #[tokio::test(flavor = "multi_thread")]
652    async fn test_rotate_yaw_out_of_range() {
653        let ast = PIPE.to_string()
654            + r#"
655    |> rotate(
656    yaw = 900,
657    pitch = 90,
658    roll = 90,
659    )
660"#;
661        let result = parse_execute(&ast).await;
662        assert!(result.is_err());
663        assert_eq!(
664            result.unwrap_err().message(),
665            r#"Expected yaw to be between -360 and 360, found `900`"#.to_string()
666        );
667    }
668
669    #[tokio::test(flavor = "multi_thread")]
670    async fn test_rotate_roll_out_of_range() {
671        let ast = PIPE.to_string()
672            + r#"
673    |> rotate(
674    yaw = 90,
675    pitch = 90,
676    roll = 900,
677    )
678"#;
679        let result = parse_execute(&ast).await;
680        assert!(result.is_err());
681        assert_eq!(
682            result.unwrap_err().message(),
683            r#"Expected roll to be between -360 and 360, found `900`"#.to_string()
684        );
685    }
686
687    #[tokio::test(flavor = "multi_thread")]
688    async fn test_rotate_pitch_out_of_range() {
689        let ast = PIPE.to_string()
690            + r#"
691    |> rotate(
692    yaw = 90,
693    pitch = 900,
694    roll = 90,
695    )
696"#;
697        let result = parse_execute(&ast).await;
698        assert!(result.is_err());
699        assert_eq!(
700            result.unwrap_err().message(),
701            r#"Expected pitch to be between -360 and 360, found `900`"#.to_string()
702        );
703    }
704
705    #[tokio::test(flavor = "multi_thread")]
706    async fn test_rotate_roll_pitch_yaw_with_angle() {
707        let ast = PIPE.to_string()
708            + r#"
709    |> rotate(
710    yaw = 90,
711    pitch = 90,
712    roll = 90,
713    angle = 90,
714    )
715"#;
716        let result = parse_execute(&ast).await;
717        assert!(result.is_err());
718        assert_eq!(
719            result.unwrap_err().message(),
720            r#"Expected `axis` and `angle` to not be provided when `roll`, `pitch`, and `yaw` are provided."#
721                .to_string()
722        );
723    }
724
725    #[tokio::test(flavor = "multi_thread")]
726    async fn test_translate_no_args() {
727        let ast = PIPE.to_string()
728            + r#"
729    |> translate(
730    )
731"#;
732        let result = parse_execute(&ast).await;
733        assert!(result.is_err());
734        assert_eq!(
735            result.unwrap_err().message(),
736            r#"Expected `x`, `y`, or `z` to be provided."#.to_string()
737        );
738    }
739
740    #[tokio::test(flavor = "multi_thread")]
741    async fn test_scale_no_args() {
742        let ast = PIPE.to_string()
743            + r#"
744    |> scale(
745    )
746"#;
747        let result = parse_execute(&ast).await;
748        assert!(result.is_err());
749        assert_eq!(
750            result.unwrap_err().message(),
751            r#"Expected `x`, `y`, `z` or `factor` to be provided."#.to_string()
752        );
753    }
754
755    #[tokio::test(flavor = "multi_thread")]
756    async fn test_hide_pipe_solid_ok() {
757        let ast = PIPE.to_string()
758            + r#"
759    |> hide()
760"#;
761        parse_execute(&ast).await.unwrap();
762    }
763
764    #[tokio::test(flavor = "multi_thread")]
765    async fn test_hide_helix() {
766        let ast = r#"helixPath = helix(
767  axis = Z,
768  radius = 5,
769  length = 10,
770  revolutions = 3,
771  angleStart = 360,
772  ccw = false,
773)
774
775hide(helixPath)
776"#;
777        parse_execute(ast).await.unwrap();
778    }
779
780    #[tokio::test(flavor = "multi_thread")]
781    async fn test_hide_no_objects() {
782        let ast = r#"hidden = hide()"#;
783        let result = parse_execute(ast).await;
784        assert!(result.is_err());
785        assert_eq!(
786            result.unwrap_err().message(),
787            r#"This function expects an unlabeled first parameter, but you haven't passed it one."#.to_string()
788        );
789    }
790}