diff --git a/src/wasm-lib/kcl/src/std/args.rs b/src/wasm-lib/kcl/src/std/args.rs index 0036db270..0fdd46cef 100644 --- a/src/wasm-lib/kcl/src/std/args.rs +++ b/src/wasm-lib/kcl/src/std/args.rs @@ -596,7 +596,13 @@ fn from_user_val(arg: &KclValue) -> Option { 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); diff --git a/src/wasm-lib/kcl/src/std/sketch.rs b/src/wasm-lib/kcl/src/std/sketch.rs index 6258ddab9..82d9469ce 100644 --- a/src/wasm-lib/kcl/src/std/sketch.rs +++ b/src/wasm-lib/kcl/src/std/sketch.rs @@ -1797,17 +1797,17 @@ pub async fn tangential_arc_to(args: Args) -> Result { /// Draw a tangential arc to a a specified distance. pub async fn tangential_arc_to_relative(args: Args) -> Result { - let src = args.source_range; - // Get arguments to function call - 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 (to, sketch_group, tag): ([f64; 2], SketchGroup, Option) = + 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)) @@ -1839,14 +1839,7 @@ async fn inner_tangential_arc_to( tag: Option, args: Args, ) -> Result { - let from: Point2d = sketch_group.current_pen_position()?; - let tangent_info = sketch_group.get_tangential_info_from_paths(); - let tan_previous_point = if tangent_info.is_center { - get_tangent_point_from_previous_arc(tangent_info.center_or_tangent_point, tangent_info.ccw, from.into()) - } else { - tangent_info.center_or_tangent_point - }; - do_tan_arc_to(to, sketch_group, tag, args, tan_previous_point, from).await + do_tan_arc_to(false, to, sketch_group, tag, args).await } /// Starting at the current path pen location, draw a curved line segment along @@ -1874,6 +1867,16 @@ async fn inner_tangential_arc_to_relative( sketch_group: SketchGroup, tag: Option, args: Args, +) -> Result { + 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, + args: Args, ) -> Result { let from: Point2d = sketch_group.current_pen_position()?; let tangent_info = sketch_group.get_tangential_info_from_paths(); @@ -1882,25 +1885,6 @@ async fn inner_tangential_arc_to_relative( } else { tangent_info.center_or_tangent_point }; - do_tan_arc_to( - [to[0] + from.x, to[1] + from.y], - sketch_group, - tag, - args, - tan_previous_point, - from, - ) - .await -} - -async fn do_tan_arc_to( - to: [f64; 2], - sketch_group: SketchGroup, - tag: Option, - args: Args, - tan_previous_point: [f64; 2], - from: Point2d, -) -> Result { let [to_x, to_y] = to; let result = get_tangential_arc_to_info(TangentialArcInfoInput { arc_start_point: [from.x, from.y], @@ -1908,10 +1892,14 @@ async fn do_tan_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 { diff --git a/src/wasm-lib/tests/executor/main.rs b/src/wasm-lib/tests/executor/main.rs index c4f905e8b..0954fd5ac 100644 --- a/src/wasm-lib/tests/executor/main.rs +++ b/src/wasm-lib/tests/executor/main.rs @@ -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(),