From ecb33291771f6879f990fe8ced1b149c5112d6a0 Mon Sep 17 00:00:00 2001 From: Adam Chalmers Date: Wed, 7 Aug 2024 19:33:33 -0500 Subject: [PATCH] Add 'relative: bool' to tanArcTo, remove 'to' mode from tanArc --- src/wasm-lib/kcl/src/std/sketch.rs | 45 ++++++++---------------------- 1 file changed, 11 insertions(+), 34 deletions(-) diff --git a/src/wasm-lib/kcl/src/std/sketch.rs b/src/wasm-lib/kcl/src/std/sketch.rs index 510188f9b..c65d59dd2 100644 --- a/src/wasm-lib/kcl/src/std/sketch.rs +++ b/src/wasm-lib/kcl/src/std/sketch.rs @@ -14,7 +14,7 @@ use crate::{ errors::{KclError, KclErrorDetails}, executor::{ BasePath, ExtrudeGroup, Face, GeoMeta, MemoryItem, Path, Plane, PlaneType, Point2d, Point3d, SketchGroup, - SketchGroupSet, SketchSurface, SourceRange, TagEngineInfo, TagIdentifier, UserVal, + SketchGroupSet, SketchSurface, TagEngineInfo, TagIdentifier, UserVal, }, std::{ utils::{ @@ -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 { @@ -1775,32 +1766,13 @@ fn tan_arc_to(sketch_group: &SketchGroup, to: &[f64; 2]) -> ModelingCmd { } } -fn too_few_args(source_range: SourceRange) -> KclError { - KclError::Syntax(KclErrorDetails { - source_ranges: vec![source_range], - message: "too few arguments".to_owned(), - }) -} - -fn get_arg(it: &mut I, src: SourceRange) -> Result { - it.next().ok_or_else(|| too_few_args(src)) -} - /// Draw a tangential arc to a specific point. pub async fn tangential_arc_to(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: Box = 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, relative, sketch_group, tag): ([f64; 2], bool, Box, Option) = + super::args::FromArgs::from_args(&args, 0)?; - let new_sketch_group = inner_tangential_arc_to(to, sketch_group, tag, args).await?; + let new_sketch_group = inner_tangential_arc_to(to, relative, sketch_group, tag, args).await?; Ok(MemoryItem::SketchGroup(new_sketch_group)) } @@ -1826,6 +1798,7 @@ pub async fn tangential_arc_to(args: Args) -> Result { }] async fn inner_tangential_arc_to( to: [f64; 2], + relative: bool, sketch_group: Box, tag: Option, args: Args, @@ -1845,9 +1818,13 @@ async fn inner_tangential_arc_to( obtuse: true, }); - let delta = [to_x - from.x, to_y - from.y]; + let to = if relative { + [to_x, to_y] + } else { + [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 {