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