Compare commits
	
		
			6 Commits
		
	
	
		
			pierremtb/
			...
			achalmers/
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| fa9680809b | |||
| 4f1a2b82a1 | |||
| 2d65ef5d0c | |||
| 4b7730ab59 | |||
| 7e481c5770 | |||
| dba842f57d | 
| Before Width: | Height: | Size: 49 KiB After Width: | Height: | Size: 52 KiB | 
| Before Width: | Height: | Size: 43 KiB After Width: | Height: | Size: 44 KiB | 
| Before Width: | Height: | Size: 55 KiB After Width: | Height: | Size: 57 KiB | 
| Before Width: | Height: | Size: 48 KiB After Width: | Height: | Size: 50 KiB | 
| Before Width: | Height: | Size: 46 KiB After Width: | Height: | Size: 48 KiB | 
| Before Width: | Height: | Size: 40 KiB After Width: | Height: | Size: 41 KiB | 
| @ -596,7 +596,13 @@ fn from_user_val<T: DeserializeOwned>(arg: &KclValue) -> Option<T> { | ||||
|         KclValue::UserVal(v) => v.value.clone(), | ||||
|         other => serde_json::to_value(other).ok()?, | ||||
|     }; | ||||
|     serde_json::from_value(v).ok() | ||||
|     match serde_json::from_value(v) { | ||||
|         Ok(x) => Some(x), | ||||
|         Err(e) => { | ||||
|             eprintln!("Deser error: {e}"); | ||||
|             None | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl_from_arg_via_json!(super::sketch::AngledLineData); | ||||
|  | ||||
| @ -81,6 +81,7 @@ lazy_static! { | ||||
|         Box::new(crate::std::sketch::Arc), | ||||
|         Box::new(crate::std::sketch::TangentialArc), | ||||
|         Box::new(crate::std::sketch::TangentialArcTo), | ||||
|         Box::new(crate::std::sketch::TangentialArcToRelative), | ||||
|         Box::new(crate::std::sketch::BezierCurve), | ||||
|         Box::new(crate::std::sketch::Hole), | ||||
|         Box::new(crate::std::patterns::PatternLinear2D), | ||||
|  | ||||
| @ -1634,8 +1634,6 @@ pub enum TangentialArcData { | ||||
|         /// Offset of the arc, in degrees. | ||||
|         offset: f64, | ||||
|     }, | ||||
|     /// A point where the arc should end. Must lie in the same plane as the current path pen position. Must not be colinear with current path pen position. | ||||
|     Point([f64; 2]), | ||||
| } | ||||
|  | ||||
| /// Draw a tangential arc. | ||||
| @ -1728,13 +1726,6 @@ async fn inner_tangential_arc( | ||||
|             .await?; | ||||
|             (center, to.into(), ccw) | ||||
|         } | ||||
|         TangentialArcData::Point(to) => { | ||||
|             args.batch_modeling_cmd(id, tan_arc_to(&sketch_group, &to)).await?; | ||||
|             // TODO: Figure out these calculations. | ||||
|             let ccw = false; | ||||
|             let center = Point2d { x: 0.0, y: 0.0 }; | ||||
|             (center, to, ccw) | ||||
|         } | ||||
|     }; | ||||
|  | ||||
|     let current_path = Path::TangentialArc { | ||||
| @ -1804,6 +1795,24 @@ pub async fn tangential_arc_to(args: Args) -> Result<KclValue, KclError> { | ||||
|     Ok(KclValue::new_user_val(new_sketch_group.meta.clone(), new_sketch_group)) | ||||
| } | ||||
|  | ||||
| /// Draw a tangential arc to a a specified distance. | ||||
| pub async fn tangential_arc_to_relative(args: Args) -> Result<KclValue, KclError> { | ||||
|     // Get arguments to function call | ||||
|     let (to, sketch_group, tag): ([f64; 2], SketchGroup, Option<TagDeclarator>) = | ||||
|         args.get_data_and_sketch_group_and_tag()?; | ||||
|     // let mut it = args.args.iter(); | ||||
|     // let to: [f64; 2] = get_arg(&mut it, src)?.get_json()?; | ||||
|     // let sketch_group: SketchGroup = get_arg(&mut it, src)?.get_json()?; | ||||
|     // let tag = if let Ok(memory_item) = get_arg(&mut it, src) { | ||||
|     //     memory_item.get_json_opt()? | ||||
|     // } else { | ||||
|     //     None | ||||
|     // }; | ||||
|  | ||||
|     let new_sketch_group = inner_tangential_arc_to_relative(to, sketch_group, tag, args).await?; | ||||
|     Ok(KclValue::new_user_val(new_sketch_group.meta.clone(), new_sketch_group)) | ||||
| } | ||||
|  | ||||
| /// Starting at the current sketch's origin, draw a curved line segment along | ||||
| /// some part of an imaginary circle until it reaches the desired (x, y) | ||||
| /// coordinates. | ||||
| @ -1829,6 +1838,45 @@ async fn inner_tangential_arc_to( | ||||
|     sketch_group: SketchGroup, | ||||
|     tag: Option<TagDeclarator>, | ||||
|     args: Args, | ||||
| ) -> Result<SketchGroup, KclError> { | ||||
|     do_tan_arc_to(false, to, sketch_group, tag, args).await | ||||
| } | ||||
|  | ||||
| /// Starting at the current path pen location, draw a curved line segment along | ||||
| /// some part of an imaginary circle until it reaches the desired (current.x + x, current.y + y) | ||||
| /// coordinates. | ||||
| /// | ||||
| /// ```no_run | ||||
| /// const exampleSketch = startSketchOn('XZ') | ||||
| ///   |> startProfileAt([0, 0], %) | ||||
| ///   |> angledLine({ | ||||
| ///     angle: 60, | ||||
| ///     length: 10, | ||||
| ///   }, %) | ||||
| ///   |> tangentialArcToRelative([15, 15], %) | ||||
| ///   |> line([10, -15], %) | ||||
| ///   |> close(%) | ||||
| /// | ||||
| /// const example = extrude(10, exampleSketch) | ||||
| /// ``` | ||||
| #[stdlib { | ||||
|     name = "tangentialArcToRelative", | ||||
| }] | ||||
| async fn inner_tangential_arc_to_relative( | ||||
|     to: [f64; 2], | ||||
|     sketch_group: SketchGroup, | ||||
|     tag: Option<TagDeclarator>, | ||||
|     args: Args, | ||||
| ) -> Result<SketchGroup, KclError> { | ||||
|     do_tan_arc_to(true, to, sketch_group, tag, args).await | ||||
| } | ||||
|  | ||||
| async fn do_tan_arc_to( | ||||
|     relative: bool, | ||||
|     to: [f64; 2], | ||||
|     sketch_group: SketchGroup, | ||||
|     tag: Option<TagDeclarator>, | ||||
|     args: Args, | ||||
| ) -> Result<SketchGroup, KclError> { | ||||
|     let from: Point2d = sketch_group.current_pen_position()?; | ||||
|     let tangent_info = sketch_group.get_tangential_info_from_paths(); | ||||
| @ -1844,10 +1892,14 @@ async fn inner_tangential_arc_to( | ||||
|         tan_previous_point, | ||||
|         obtuse: true, | ||||
|     }); | ||||
|     let to = if relative { | ||||
|         [to_x, to_y] | ||||
|     } else { | ||||
|         [to_x - from.x, to_y - from.y] | ||||
|     }; | ||||
|  | ||||
|     let delta = [to_x - from.x, to_y - from.y]; | ||||
|     let id = uuid::Uuid::new_v4(); | ||||
|     args.batch_modeling_cmd(id, tan_arc_to(&sketch_group, &delta)).await?; | ||||
|     args.batch_modeling_cmd(id, tan_arc_to(&sketch_group, &to)).await?; | ||||
|  | ||||
|     let current_path = Path::TangentialArcTo { | ||||
|         base: BasePath { | ||||
|  | ||||
| @ -4,45 +4,50 @@ let length = 120.0 | ||||
| let hand_thickness = 24.0 | ||||
| let corner_radius = 5.0 | ||||
|  | ||||
| fn tarc = (p, sg) => { | ||||
|   let p2 = [p[0] * corner_radius, p[1] * corner_radius] | ||||
|   return tangentialArcToRelative(p2, sg) | ||||
| } | ||||
|  | ||||
| // At first I thought this was going to be symmetric, | ||||
| // but I measured intentionally to not be symmetric, | ||||
| // because your wrist isn't a perfect cylindrical surface | ||||
| let brace_base = startSketchAt([corner_radius, 0]) | ||||
|   |> line([width - corner_radius, 0.0], %) | ||||
|   |> tangentialArc([corner_radius, corner_radius], %) | ||||
|   |> tarc([1, 1], %) | ||||
|   |> yLine(25.0 - corner_radius, %) | ||||
|   |> tangentialArc([-corner_radius, corner_radius], %) | ||||
|   |> tarc([-1, 1], %) | ||||
|   |> xLine(-(d_wrist_circumference[0] - (corner_radius * 2)), %) | ||||
|   |> tangentialArc([-corner_radius, corner_radius], %) | ||||
|   |> tarc([-1, 1], %) | ||||
|   |> yLine(length - 25.0 - 23.0 - (corner_radius * 2), %) | ||||
|   |> tangentialArc([corner_radius, corner_radius], %) | ||||
|   |> tarc([1, 1], %) | ||||
|   |> xLine(15.0 - (corner_radius * 2), %) | ||||
|   |> tangentialArc([corner_radius, corner_radius], %) | ||||
|   |> tarc([1, 1], %) | ||||
|   |> yLine(23.0 - corner_radius, %) | ||||
|   |> tangentialArc([-corner_radius, corner_radius], %) | ||||
|   |> tarc([-1, 1], %) | ||||
|   |> xLine(-(hand_thickness + 15.0 + 15.0 - (corner_radius * 2)), %) | ||||
|   |> tangentialArc([-corner_radius, -corner_radius], %) | ||||
|   |> tarc([-1, -1], %) | ||||
|   |> yLine(-(23.0 - corner_radius), %) | ||||
|   |> tangentialArc([corner_radius, -corner_radius], %) | ||||
|   |> tarc([1, -1], %) | ||||
|   |> xLine(15.0 - (corner_radius * 2), %) | ||||
|   |> tangentialArc([corner_radius, -corner_radius], %) | ||||
|   |> tarc([1, -1], %) | ||||
|   |> yLine(-(length - 25.0 - 23.0 - (corner_radius * 2)), %) | ||||
|   |> tangentialArc([-corner_radius, -corner_radius], %) | ||||
|   |> tarc([-1, -1], %) | ||||
|   |> xLine(-(d_wrist_circumference[1] + d_wrist_circumference[2] + d_wrist_circumference[3] - hand_thickness - corner_radius), %) | ||||
|   |> tangentialArc([-corner_radius, -corner_radius], %) | ||||
|   |> tarc([-1, -1], %) | ||||
|   |> yLine(-(25.0 - corner_radius), %) | ||||
|   |> tangentialArc([corner_radius, -corner_radius], %) | ||||
|   |> tarc([1, -1], %) | ||||
|   |> close(%) | ||||
|  | ||||
| let inner = startSketchAt([0, 0]) | ||||
|   |> xLine(1.0, %) | ||||
|   |> tangentialArc([corner_radius, corner_radius], %) | ||||
|   |> tarc([1, 1], %) | ||||
|   |> yLine(25.0 - (corner_radius * 2), %) | ||||
|   |> tangentialArc([-corner_radius, corner_radius], %) | ||||
|   |> tarc([-1, 1], %) | ||||
|   |> xLine(-1.0, %) | ||||
|   |> tangentialArc([-corner_radius, -corner_radius], %) | ||||
|   |> tarc([-1, -1], %) | ||||
|   |> yLine(-(25.0 - (corner_radius * 2)), %) | ||||
|   |> tangentialArc([corner_radius, -corner_radius], %) | ||||
|   |> tarc([1, -1], %) | ||||
|   |> close(%) | ||||
|  | ||||
| let final = brace_base | ||||
|  | ||||
| @ -186,7 +186,7 @@ async fn kcl_test_negative_args() { | ||||
| async fn kcl_test_basic_tangential_arc_with_point() { | ||||
|     let code = r#"const boxSketch = startSketchAt([0, 0]) | ||||
|     |> line([0, 10], %) | ||||
|     |> tangentialArc([-5, 5], %) | ||||
|     |> tangentialArcToRelative([-5, 5], %) | ||||
|     |> line([5, -15], %) | ||||
|     |> extrude(10, %) | ||||
| "#; | ||||
| @ -715,7 +715,7 @@ async fn kcl_test_error_sketch_on_arc_face() { | ||||
|     let code = r#"fn cube = (pos, scale) => { | ||||
|   const sg = startSketchOn('XY') | ||||
|   |> startProfileAt(pos, %) | ||||
|   |> tangentialArc([0, scale], %, $here) | ||||
|   |> tangentialArcToRelative([0, scale], %, $here) | ||||
|   |> line([scale, 0], %) | ||||
|   |> line([0, -scale], %) | ||||
|  | ||||
| @ -736,6 +736,8 @@ const part002 = startSketchOn(part001, part001.sketchGroup.tags.here) | ||||
|  | ||||
|     let result = execute_and_snapshot(code, UnitLength::Mm).await; | ||||
|  | ||||
|     println!("{}", &code[145..164]); | ||||
|  | ||||
|     assert!(result.is_err()); | ||||
|     assert_eq!( | ||||
|         result.err().unwrap().to_string(), | ||||
|  | ||||
![github-actions[bot]](/assets/img/avatar_default.png)