diff --git a/docs/kcl/angleToMatchLengthX.md b/docs/kcl/angleToMatchLengthX.md index 1a2e623752..8757a9bdfc 100644 --- a/docs/kcl/angleToMatchLengthX.md +++ b/docs/kcl/angleToMatchLengthX.md @@ -17,7 +17,7 @@ angleToMatchLengthX(segment_name: string, to: number, sketch_group: SketchGroup) ```js const part001 = startSketchOn('XY') |> startProfileAt([0, 0], %) - |> line({ to: [1, 3.82], tag: 'seg01' }, %) + |> line([1, 3.82], %, 'seg01') |> angledLineToX([ -angleToMatchLengthX('seg01', 10, %), 5 diff --git a/docs/kcl/angleToMatchLengthY.md b/docs/kcl/angleToMatchLengthY.md index e58817b522..1d4972e9e3 100644 --- a/docs/kcl/angleToMatchLengthY.md +++ b/docs/kcl/angleToMatchLengthY.md @@ -17,7 +17,7 @@ angleToMatchLengthY(segment_name: string, to: number, sketch_group: SketchGroup) ```js const part001 = startSketchOn('XY') |> startProfileAt([0, 0], %) - |> line({ to: [1, 3.82], tag: 'seg01' }, %) + |> line([1, 3.82], %, 'seg01') |> angledLineToX([ -angleToMatchLengthY('seg01', 10, %), 5 diff --git a/docs/kcl/angledLine.md b/docs/kcl/angledLine.md index b916615d14..827e7b1bf4 100644 --- a/docs/kcl/angledLine.md +++ b/docs/kcl/angledLine.md @@ -9,7 +9,7 @@ Draw an angled line. ```js -angledLine(data: AngledLineData, sketch_group: SketchGroup) -> SketchGroup +angledLine(data: AngledLineData, sketch_group: SketchGroup, tag?: String) -> SketchGroup ``` ### Examples @@ -17,7 +17,7 @@ angledLine(data: AngledLineData, sketch_group: SketchGroup) -> SketchGroup ```js startSketchOn('XY') |> startProfileAt([0, 0], %) - |> angledLine({ angle: 45, length: 10, tag: "edge1" }, %) + |> angledLine({ angle: 45, length: 10 }, %, "edge1") |> line([10, 10], %) |> line([0, 10], %) |> close(%, "edge2") @@ -33,8 +33,6 @@ startSketchOn('XY') angle: number, // The length of the line. length: number, - // The tag. - tag: string, } | [number, number] ``` @@ -202,6 +200,7 @@ startSketchOn('XY') }, } ``` +* `tag`: `String` (OPTIONAL) ### Returns diff --git a/docs/kcl/angledLineOfXLength.md b/docs/kcl/angledLineOfXLength.md index 23c65e3846..a909a12fab 100644 --- a/docs/kcl/angledLineOfXLength.md +++ b/docs/kcl/angledLineOfXLength.md @@ -9,7 +9,7 @@ Draw an angled line of a given x length. ```js -angledLineOfXLength(data: AngledLineData, sketch_group: SketchGroup) -> SketchGroup +angledLineOfXLength(data: AngledLineData, sketch_group: SketchGroup, tag?: String) -> SketchGroup ``` ### Examples @@ -17,7 +17,7 @@ angledLineOfXLength(data: AngledLineData, sketch_group: SketchGroup) -> SketchGr ```js startSketchOn('XZ') |> startProfileAt([0, 0], %) - |> angledLineOfXLength({ angle: 45, length: 10, tag: "edge1" }, %) + |> angledLineOfXLength({ angle: 45, length: 10 }, %, "edge1") |> line([10, 10], %) |> line([0, 10], %) |> close(%, "edge2") @@ -33,8 +33,6 @@ startSketchOn('XZ') angle: number, // The length of the line. length: number, - // The tag. - tag: string, } | [number, number] ``` @@ -202,6 +200,7 @@ startSketchOn('XZ') }, } ``` +* `tag`: `String` (OPTIONAL) ### Returns diff --git a/docs/kcl/angledLineOfYLength.md b/docs/kcl/angledLineOfYLength.md index 1fafa778d5..6f21a65ed7 100644 --- a/docs/kcl/angledLineOfYLength.md +++ b/docs/kcl/angledLineOfYLength.md @@ -9,7 +9,7 @@ Draw an angled line of a given y length. ```js -angledLineOfYLength(data: AngledLineData, sketch_group: SketchGroup) -> SketchGroup +angledLineOfYLength(data: AngledLineData, sketch_group: SketchGroup, tag?: String) -> SketchGroup ``` ### Examples @@ -17,7 +17,7 @@ angledLineOfYLength(data: AngledLineData, sketch_group: SketchGroup) -> SketchGr ```js startSketchOn('YZ') |> startProfileAt([0, 0], %) - |> angledLineOfYLength({ angle: 45, length: 10, tag: "edge1" }, %) + |> angledLineOfYLength({ angle: 45, length: 10 }, %, "edge1") |> line([10, 10], %) |> line([0, 10], %) |> close(%, "edge2") @@ -34,8 +34,6 @@ startSketchOn('YZ') angle: number, // The length of the line. length: number, - // The tag. - tag: string, } | [number, number] ``` @@ -203,6 +201,7 @@ startSketchOn('YZ') }, } ``` +* `tag`: `String` (OPTIONAL) ### Returns diff --git a/docs/kcl/angledLineThatIntersects.md b/docs/kcl/angledLineThatIntersects.md index f57ccf0f46..ecbae1c0e3 100644 --- a/docs/kcl/angledLineThatIntersects.md +++ b/docs/kcl/angledLineThatIntersects.md @@ -9,7 +9,7 @@ Draw an angled line that intersects with a given line. ```js -angledLineThatIntersects(data: AngledLineThatIntersectsData, sketch_group: SketchGroup) -> SketchGroup +angledLineThatIntersects(data: AngledLineThatIntersectsData, sketch_group: SketchGroup, tag?: String) -> SketchGroup ``` ### Examples @@ -17,14 +17,13 @@ angledLineThatIntersects(data: AngledLineThatIntersectsData, sketch_group: Sketc ```js const part001 = startSketchOn('XY') |> startProfileAt([0, 0], %) - |> lineTo({ to: [2, 2], tag: "yo" }, %) + |> lineTo([2, 2], %, "yo") |> lineTo([3, 1], %) |> angledLineThatIntersects({ angle: 180, intersectTag: 'yo', - offset: 12, - tag: "yo2" - }, %) + offset: 12 + }, %, "yo2") |> line([4, 0], %) |> close(%, "yo3") |> extrude(10, %) @@ -41,8 +40,6 @@ const part001 = startSketchOn('XY') intersectTag: string, // The offset from the intersecting line. offset: number, - // The tag. - tag: string, } ``` * `sketch_group`: `SketchGroup` - A sketch group is a collection of paths. (REQUIRED) @@ -209,6 +206,7 @@ const part001 = startSketchOn('XY') }, } ``` +* `tag`: `String` (OPTIONAL) ### Returns diff --git a/docs/kcl/angledLineToX.md b/docs/kcl/angledLineToX.md index 0510e2d541..ea470eac49 100644 --- a/docs/kcl/angledLineToX.md +++ b/docs/kcl/angledLineToX.md @@ -9,7 +9,7 @@ Draw an angled line to a given x coordinate. ```js -angledLineToX(data: AngledLineToData, sketch_group: SketchGroup) -> SketchGroup +angledLineToX(data: AngledLineToData, sketch_group: SketchGroup, tag?: String) -> SketchGroup ``` ### Examples @@ -17,7 +17,7 @@ angledLineToX(data: AngledLineToData, sketch_group: SketchGroup) -> SketchGroup ```js startSketchOn('XY') |> startProfileAt([0, 0], %) - |> angledLineToX({ angle: 45, to: 10, tag: "edge1" }, %) + |> angledLineToX({ angle: 45, to: 10 }, %, "edge1") |> line([10, 10], %) |> line([0, 10], %) |> close(%, "edge2") @@ -32,12 +32,9 @@ startSketchOn('XY') { // The angle of the line. angle: number, - // The tag. - tag: string, // The point to draw to. to: number, -} | -[number, number] +} ``` * `sketch_group`: `SketchGroup` - A sketch group is a collection of paths. (REQUIRED) ```js @@ -203,6 +200,7 @@ startSketchOn('XY') }, } ``` +* `tag`: `String` (OPTIONAL) ### Returns diff --git a/docs/kcl/angledLineToY.md b/docs/kcl/angledLineToY.md index c6899d0fc7..a4f865f7d9 100644 --- a/docs/kcl/angledLineToY.md +++ b/docs/kcl/angledLineToY.md @@ -9,7 +9,7 @@ Draw an angled line to a given y coordinate. ```js -angledLineToY(data: AngledLineToData, sketch_group: SketchGroup) -> SketchGroup +angledLineToY(data: AngledLineToData, sketch_group: SketchGroup, tag?: String) -> SketchGroup ``` ### Examples @@ -17,7 +17,7 @@ angledLineToY(data: AngledLineToData, sketch_group: SketchGroup) -> SketchGroup ```js startSketchOn('XY') |> startProfileAt([0, 0], %) - |> angledLineToY({ angle: 45, to: 10, tag: "edge1" }, %) + |> angledLineToY({ angle: 45, to: 10 }, %, "edge1") |> line([10, 10], %) |> line([0, 10], %) |> close(%, "edge2") @@ -31,12 +31,9 @@ startSketchOn('XY') { // The angle of the line. angle: number, - // The tag. - tag: string, // The point to draw to. to: number, -} | -[number, number] +} ``` * `sketch_group`: `SketchGroup` - A sketch group is a collection of paths. (REQUIRED) ```js @@ -202,6 +199,7 @@ startSketchOn('XY') }, } ``` +* `tag`: `String` (OPTIONAL) ### Returns diff --git a/docs/kcl/arc.md b/docs/kcl/arc.md index 4358559788..d8ef4d2cef 100644 --- a/docs/kcl/arc.md +++ b/docs/kcl/arc.md @@ -9,7 +9,7 @@ Draw an arc. ```js -arc(data: ArcData, sketch_group: SketchGroup) -> SketchGroup +arc(data: ArcData, sketch_group: SketchGroup, tag?: String) -> SketchGroup ``` ### Examples @@ -20,9 +20,8 @@ startSketchOn('-YZ') |> arc({ angle_start: 0, angle_end: 360, - radius: 10, - tag: "edge1" - }, %) + radius: 10 + }, %, "edge1") |> extrude(10, %) ``` @@ -37,16 +36,12 @@ startSketchOn('-YZ') angle_start: number, // The radius. radius: number, - // The tag. - tag: string, } | { // The center. center: [number, number], // The radius. radius: number, - // The tag. - tag: string, // The to point. to: [number, number], } @@ -215,6 +210,7 @@ startSketchOn('-YZ') }, } ``` +* `tag`: `String` (OPTIONAL) ### Returns diff --git a/docs/kcl/bezierCurve.md b/docs/kcl/bezierCurve.md index 1e8a74e86d..aa4a52d48f 100644 --- a/docs/kcl/bezierCurve.md +++ b/docs/kcl/bezierCurve.md @@ -9,7 +9,7 @@ Draw a bezier curve. ```js -bezierCurve(data: BezierData, sketch_group: SketchGroup) -> SketchGroup +bezierCurve(data: BezierData, sketch_group: SketchGroup, tag?: String) -> SketchGroup ``` ### Examples @@ -20,9 +20,8 @@ startSketchOn('XY') |> bezierCurve({ to: [10, 10], control1: [5, 0], - control2: [5, 10], - tag: "edge1" - }, %) + control2: [5, 10] + }, %, "edge1") |> close(%) |> extrude(10, %) ``` @@ -36,8 +35,6 @@ startSketchOn('XY') control1: [number, number], // The second control point. control2: [number, number], - // The tag. - tag: string, // The to point. to: [number, number], } @@ -206,6 +203,7 @@ startSketchOn('XY') }, } ``` +* `tag`: `String` (OPTIONAL) ### Returns diff --git a/docs/kcl/fillet.md b/docs/kcl/fillet.md index 3b356f50be..8c2d8d52ac 100644 --- a/docs/kcl/fillet.md +++ b/docs/kcl/fillet.md @@ -17,9 +17,9 @@ fillet(data: FilletData, extrude_group: ExtrudeGroup) -> ExtrudeGroup ```js const part001 = startSketchOn('XY') |> startProfileAt([0, 0], %) - |> line({ to: [0, 10], tag: "thing" }, %) + |> line([0, 10], %, "thing") |> line([10, 0], %) - |> line({ to: [0, -10], tag: "thing2" }, %) + |> line([0, -10], %, "thing2") |> close(%) |> extrude(10, %) |> fillet({ radius: 2, tags: ["thing", "thing2"] }, %) diff --git a/docs/kcl/getExtrudeWallTransform.md b/docs/kcl/getExtrudeWallTransform.md index 8e544394df..77d6ed1200 100644 --- a/docs/kcl/getExtrudeWallTransform.md +++ b/docs/kcl/getExtrudeWallTransform.md @@ -19,7 +19,7 @@ const box = startSketchOn('XY') |> startProfileAt([0, 0], %) |> line([0, 10], %) |> line([10, 0], %) - |> line({ to: [0, -10], tag: "surface" }, %) + |> line([0, -10], %, "surface") |> close(%) |> extrude(5, %) diff --git a/docs/kcl/getNextAdjacentEdge.md b/docs/kcl/getNextAdjacentEdge.md index 86baecbffd..ead0fb105d 100644 --- a/docs/kcl/getNextAdjacentEdge.md +++ b/docs/kcl/getNextAdjacentEdge.md @@ -17,9 +17,9 @@ getNextAdjacentEdge(tag: String, extrude_group: ExtrudeGroup) -> Uuid ```js const part001 = startSketchOn('XY') |> startProfileAt([0, 0], %) - |> line({ to: [0, 10], tag: "thing" }, %) - |> line({ to: [10, 0], tag: "thing1" }, %) - |> line({ to: [0, -10], tag: "thing2" }, %) + |> line([0, 10], %, "thing") + |> line([10, 0], %, "thing1") + |> line([0, -10], %, "thing2") |> close(%) |> extrude(10, %) |> fillet({ diff --git a/docs/kcl/getOppositeEdge.md b/docs/kcl/getOppositeEdge.md index be6af84d96..6124cece3f 100644 --- a/docs/kcl/getOppositeEdge.md +++ b/docs/kcl/getOppositeEdge.md @@ -17,9 +17,9 @@ getOppositeEdge(tag: String, extrude_group: ExtrudeGroup) -> Uuid ```js const part001 = startSketchOn('XY') |> startProfileAt([0, 0], %) - |> line({ to: [0, 10], tag: "thing" }, %) + |> line([0, 10], %, "thing") |> line([10, 0], %) - |> line({ to: [0, -10], tag: "thing2" }, %) + |> line([0, -10], %, "thing2") |> close(%) |> extrude(10, %) |> fillet({ diff --git a/docs/kcl/getPreviousAdjacentEdge.md b/docs/kcl/getPreviousAdjacentEdge.md index ff63ca182c..a688d793e5 100644 --- a/docs/kcl/getPreviousAdjacentEdge.md +++ b/docs/kcl/getPreviousAdjacentEdge.md @@ -17,9 +17,9 @@ getPreviousAdjacentEdge(tag: String, extrude_group: ExtrudeGroup) -> Uuid ```js const part001 = startSketchOn('XY') |> startProfileAt([0, 0], %) - |> line({ to: [0, 10], tag: "thing" }, %) - |> line({ to: [10, 0], tag: "thing1" }, %) - |> line({ to: [0, -10], tag: "thing2" }, %) + |> line([0, 10], %, "thing") + |> line([10, 0], %, "thing1") + |> line([0, -10], %, "thing2") |> close(%) |> extrude(10, %) |> fillet({ diff --git a/docs/kcl/lastSegX.md b/docs/kcl/lastSegX.md index 2b2a773072..6714035da3 100644 --- a/docs/kcl/lastSegX.md +++ b/docs/kcl/lastSegX.md @@ -17,7 +17,7 @@ lastSegX(sketch_group: SketchGroup) -> number ```js startSketchOn("YZ") |> startProfileAt([0, 0], %) - |> line({ to: [5, 0], tag: "thing" }, %) + |> line([5, 0], %, "thing") |> line([5, 5], %) |> line([0, lastSegX(%)], %) |> close(%) diff --git a/docs/kcl/lastSegY.md b/docs/kcl/lastSegY.md index 44f242377c..57bf61e47e 100644 --- a/docs/kcl/lastSegY.md +++ b/docs/kcl/lastSegY.md @@ -17,7 +17,7 @@ lastSegY(sketch_group: SketchGroup) -> number ```js startSketchOn("YZ") |> startProfileAt([0, 0], %) - |> line({ to: [5, 0], tag: "thing" }, %) + |> line([5, 0], %, "thing") |> line([5, 5], %) |> line([0, lastSegY(%)], %) |> close(%) diff --git a/docs/kcl/line.md b/docs/kcl/line.md index c2e32e9fb7..423a4aed85 100644 --- a/docs/kcl/line.md +++ b/docs/kcl/line.md @@ -9,7 +9,7 @@ Draw a line. ```js -line(data: LineData, sketch_group: SketchGroup) -> SketchGroup +line(delta: [number], sketch_group: SketchGroup, tag?: String) -> SketchGroup ``` ### Examples @@ -18,23 +18,14 @@ line(data: LineData, sketch_group: SketchGroup) -> SketchGroup startSketchOn('-XY') |> startProfileAt([0, 0], %) |> line([10, 10], %) - |> line({ to: [20, 10], tag: "edge1" }, %) + |> line([20, 10], %, "edge1") |> close(%, "edge2") |> extrude(10, %) ``` ### Arguments -* `data`: `LineData` - Data to draw a line. (REQUIRED) -```js -{ - // The tag. - tag: string, - // The to point. - to: [number, number], -} | -[number, number] -``` +* `delta`: `[number]` (REQUIRED) * `sketch_group`: `SketchGroup` - A sketch group is a collection of paths. (REQUIRED) ```js { @@ -199,6 +190,7 @@ startSketchOn('-XY') }, } ``` +* `tag`: `String` (OPTIONAL) ### Returns diff --git a/docs/kcl/lineTo.md b/docs/kcl/lineTo.md index aefa8da62f..7f0453efa2 100644 --- a/docs/kcl/lineTo.md +++ b/docs/kcl/lineTo.md @@ -9,7 +9,7 @@ Draw a line to a point. ```js -lineTo(data: LineToData, sketch_group: SketchGroup) -> SketchGroup +lineTo(to: [number], sketch_group: SketchGroup, tag?: String) -> SketchGroup ``` ### Examples @@ -18,18 +18,9 @@ lineTo(data: LineToData, sketch_group: SketchGroup) -> SketchGroup fn rectShape = (pos, w, l) => { const rr = startSketchOn('YZ') |> startProfileAt([pos[0] - (w / 2), pos[1] - (l / 2)], %) - |> lineTo({ - to: [pos[0] + w / 2, pos[1] - (l / 2)], - tag: "edge1" - }, %) - |> lineTo({ - to: [pos[0] + w / 2, pos[1] + l / 2], - tag: "edge2" - }, %) - |> lineTo({ - to: [pos[0] - (w / 2), pos[1] + l / 2], - tag: "edge3" - }, %) + |> lineTo([pos[0] + w / 2, pos[1] - (l / 2)], %, "edge1") + |> lineTo([pos[0] + w / 2, pos[1] + l / 2], %, "edge2") + |> lineTo([pos[0] - (w / 2), pos[1] + l / 2], %, "edge3") |> close(%, "edge4") return rr } @@ -40,16 +31,7 @@ const part = rectShape([0, 0], 20, 20) ### Arguments -* `data`: `LineToData` - Data to draw a line to a point. (REQUIRED) -```js -{ - // The tag. - tag: string, - // The to point. - to: [number, number], -} | -[number, number] -``` +* `to`: `[number]` (REQUIRED) * `sketch_group`: `SketchGroup` - A sketch group is a collection of paths. (REQUIRED) ```js { @@ -214,6 +196,7 @@ const part = rectShape([0, 0], 20, 20) }, } ``` +* `tag`: `String` (OPTIONAL) ### Returns diff --git a/docs/kcl/segAng.md b/docs/kcl/segAng.md index ffdebae55b..fddb2ee9cd 100644 --- a/docs/kcl/segAng.md +++ b/docs/kcl/segAng.md @@ -18,7 +18,7 @@ segAng(segment_name: string, sketch_group: SketchGroup) -> number const part001 = startSketchOn('XY') |> startProfileAt([4.83, 12.56], %) |> line([15.1, 2.48], %) - |> line({ to: [3.15, -9.85], tag: 'seg01' }, %) + |> line([3.15, -9.85], %, 'seg01') |> line([-15.17, -4.1], %) |> angledLine([segAng('seg01', %), 12.35], %) |> line([-13.02, 10.03], %) diff --git a/docs/kcl/segEndX.md b/docs/kcl/segEndX.md index 9119121445..3df6b9bac7 100644 --- a/docs/kcl/segEndX.md +++ b/docs/kcl/segEndX.md @@ -17,7 +17,7 @@ segEndX(segment_name: string, sketch_group: SketchGroup) -> number ```js startSketchOn("YZ") |> startProfileAt([0, 0], %) - |> line({ to: [5, 0], tag: "thing" }, %) + |> line([5, 0], %, "thing") |> line([5, 5], %) |> line([segEndX("thing", %), 5], %) |> close(%) diff --git a/docs/kcl/segEndY.md b/docs/kcl/segEndY.md index 456bc4b20c..c165b07967 100644 --- a/docs/kcl/segEndY.md +++ b/docs/kcl/segEndY.md @@ -17,7 +17,7 @@ segEndY(segment_name: string, sketch_group: SketchGroup) -> number ```js startSketchOn("YZ") |> startProfileAt([0, 0], %) - |> line({ to: [5, 0], tag: "thing" }, %) + |> line([5, 0], %, "thing") |> line([5, 5], %) |> line([segEndY("thing", %), 5], %) |> close(%) diff --git a/docs/kcl/segLen.md b/docs/kcl/segLen.md index b95b417bc0..97f40fa54b 100644 --- a/docs/kcl/segLen.md +++ b/docs/kcl/segLen.md @@ -17,7 +17,7 @@ segLen(segment_name: string, sketch_group: SketchGroup) -> number ```js startSketchOn("YZ") |> startProfileAt([0, 0], %) - |> line({ to: [5, 0], tag: "thing" }, %) + |> line([5, 0], %, "thing") |> line([5, 5], %) |> line([0, segLen("thing", %)], %) |> close(%) diff --git a/docs/kcl/startProfileAt.md b/docs/kcl/startProfileAt.md index 17e10ee499..2c62fa3b81 100644 --- a/docs/kcl/startProfileAt.md +++ b/docs/kcl/startProfileAt.md @@ -9,7 +9,7 @@ Start a profile at a given point. ```js -startProfileAt(data: LineData, sketch_surface: SketchSurface) -> SketchGroup +startProfileAt(to: [number], sketch_surface: SketchSurface, tag?: String) -> SketchGroup ``` ### Examples @@ -22,16 +22,7 @@ startSketchOn('XY') ### Arguments -* `data`: `LineData` - Data to draw a line. (REQUIRED) -```js -{ - // The tag. - tag: string, - // The to point. - to: [number, number], -} | -[number, number] -``` +* `to`: `[number]` (REQUIRED) * `sketch_surface`: `SketchSurface` - A sketch group type. (REQUIRED) ```js { @@ -93,6 +84,7 @@ startSketchOn('XY') }, } ``` +* `tag`: `String` (OPTIONAL) ### Returns diff --git a/docs/kcl/startSketchAt.md b/docs/kcl/startSketchAt.md index 92827dfa84..c537753666 100644 --- a/docs/kcl/startSketchAt.md +++ b/docs/kcl/startSketchAt.md @@ -9,7 +9,7 @@ Start a sketch at a given point on the 'XY' plane. ```js -startSketchAt(data: LineData) -> SketchGroup +startSketchAt(data: [number]) -> SketchGroup ``` ### Examples @@ -21,16 +21,7 @@ startSketchAt([0, 0]) ### Arguments -* `data`: `LineData` - Data to draw a line. (REQUIRED) -```js -{ - // The tag. - tag: string, - // The to point. - to: [number, number], -} | -[number, number] -``` +* `data`: `[number]` (REQUIRED) ### Returns diff --git a/docs/kcl/startSketchOn.md b/docs/kcl/startSketchOn.md index 57ae1db852..db64bad887 100644 --- a/docs/kcl/startSketchOn.md +++ b/docs/kcl/startSketchOn.md @@ -18,7 +18,7 @@ startSketchOn(data: SketchData, tag?: SketchOnFaceTag) -> SketchSurface startSketchOn('XY') |> startProfileAt([0, 0], %) |> line([10, 10], %) - |> line({ to: [20, 10], tag: "edge1" }, %) + |> line([20, 10], %, "edge1") |> close(%, "edge2") ``` @@ -40,7 +40,7 @@ const box = cube([0, 0], 20) const part001 = startSketchOn(box, "start") |> startProfileAt([0, 0], %) |> line([10, 10], %) - |> line({ to: [20, 10], tag: "edge1" }, %) + |> line([20, 10], %, "edge1") |> close(%) |> extrude(20, %) ``` diff --git a/docs/kcl/std.json b/docs/kcl/std.json index f141594886..205d7c7e76 100644 --- a/docs/kcl/std.json +++ b/docs/kcl/std.json @@ -1058,7 +1058,7 @@ "unpublished": false, "deprecated": false, "examples": [ - "const part001 = startSketchOn('XY')\n |> startProfileAt([0, 0], %)\n |> line({ to: [1, 3.82], tag: 'seg01' }, %)\n |> angledLineToX([\n -angleToMatchLengthX('seg01', 10, %),\n 5\n ], %)\n |> close(%)" + "const part001 = startSketchOn('XY')\n |> startProfileAt([0, 0], %)\n |> line([1, 3.82], %, 'seg01')\n |> angledLineToX([\n -angleToMatchLengthX('seg01', 10, %),\n 5\n ], %)\n |> close(%)" ] }, { @@ -2058,7 +2058,7 @@ "unpublished": false, "deprecated": false, "examples": [ - "const part001 = startSketchOn('XY')\n |> startProfileAt([0, 0], %)\n |> line({ to: [1, 3.82], tag: 'seg01' }, %)\n |> angledLineToX([\n -angleToMatchLengthY('seg01', 10, %),\n 5\n ], %)\n |> close(%)" + "const part001 = startSketchOn('XY')\n |> startProfileAt([0, 0], %)\n |> line([1, 3.82], %, 'seg01')\n |> angledLineToX([\n -angleToMatchLengthY('seg01', 10, %),\n 5\n ], %)\n |> close(%)" ] }, { @@ -2074,12 +2074,11 @@ "description": "Data to draw an angled line.", "anyOf": [ { - "description": "An angle and length with a tag.", + "description": "An angle and length with explicitly named parameters", "type": "object", "required": [ "angle", - "length", - "tag" + "length" ], "properties": { "angle": { @@ -2091,15 +2090,11 @@ "description": "The length of the line.", "type": "number", "format": "double" - }, - "tag": { - "description": "The tag.", - "type": "string" } } }, { - "description": "An angle and length.", + "description": "An angle and length given as a pair", "type": "array", "items": { "type": "number", @@ -3072,6 +3067,15 @@ } }, "required": true + }, + { + "name": "tag", + "type": "String", + "schema": { + "type": "string", + "nullable": true + }, + "required": false } ], "returnValue": { @@ -4038,7 +4042,7 @@ "unpublished": false, "deprecated": false, "examples": [ - "startSketchOn('XY')\n |> startProfileAt([0, 0], %)\n |> angledLine({ angle: 45, length: 10, tag: \"edge1\" }, %)\n |> line([10, 10], %)\n |> line([0, 10], %)\n |> close(%, \"edge2\")\n |> extrude(10, %)" + "startSketchOn('XY')\n |> startProfileAt([0, 0], %)\n |> angledLine({ angle: 45, length: 10 }, %, \"edge1\")\n |> line([10, 10], %)\n |> line([0, 10], %)\n |> close(%, \"edge2\")\n |> extrude(10, %)" ] }, { @@ -4054,12 +4058,11 @@ "description": "Data to draw an angled line.", "anyOf": [ { - "description": "An angle and length with a tag.", + "description": "An angle and length with explicitly named parameters", "type": "object", "required": [ "angle", - "length", - "tag" + "length" ], "properties": { "angle": { @@ -4071,15 +4074,11 @@ "description": "The length of the line.", "type": "number", "format": "double" - }, - "tag": { - "description": "The tag.", - "type": "string" } } }, { - "description": "An angle and length.", + "description": "An angle and length given as a pair", "type": "array", "items": { "type": "number", @@ -5052,6 +5051,15 @@ } }, "required": true + }, + { + "name": "tag", + "type": "String", + "schema": { + "type": "string", + "nullable": true + }, + "required": false } ], "returnValue": { @@ -6018,7 +6026,7 @@ "unpublished": false, "deprecated": false, "examples": [ - "startSketchOn('XZ')\n |> startProfileAt([0, 0], %)\n |> angledLineOfXLength({ angle: 45, length: 10, tag: \"edge1\" }, %)\n |> line([10, 10], %)\n |> line([0, 10], %)\n |> close(%, \"edge2\")\n |> extrude(10, %)" + "startSketchOn('XZ')\n |> startProfileAt([0, 0], %)\n |> angledLineOfXLength({ angle: 45, length: 10 }, %, \"edge1\")\n |> line([10, 10], %)\n |> line([0, 10], %)\n |> close(%, \"edge2\")\n |> extrude(10, %)" ] }, { @@ -6034,12 +6042,11 @@ "description": "Data to draw an angled line.", "anyOf": [ { - "description": "An angle and length with a tag.", + "description": "An angle and length with explicitly named parameters", "type": "object", "required": [ "angle", - "length", - "tag" + "length" ], "properties": { "angle": { @@ -6051,15 +6058,11 @@ "description": "The length of the line.", "type": "number", "format": "double" - }, - "tag": { - "description": "The tag.", - "type": "string" } } }, { - "description": "An angle and length.", + "description": "An angle and length given as a pair", "type": "array", "items": { "type": "number", @@ -7032,6 +7035,15 @@ } }, "required": true + }, + { + "name": "tag", + "type": "String", + "schema": { + "type": "string", + "nullable": true + }, + "required": false } ], "returnValue": { @@ -7998,7 +8010,7 @@ "unpublished": false, "deprecated": false, "examples": [ - "startSketchOn('YZ')\n |> startProfileAt([0, 0], %)\n |> angledLineOfYLength({ angle: 45, length: 10, tag: \"edge1\" }, %)\n |> line([10, 10], %)\n |> line([0, 10], %)\n |> close(%, \"edge2\")\n |> extrude(10, %)\n |> fillet({ radius: 2, tags: [\"edge1\"] }, %)" + "startSketchOn('YZ')\n |> startProfileAt([0, 0], %)\n |> angledLineOfYLength({ angle: 45, length: 10 }, %, \"edge1\")\n |> line([10, 10], %)\n |> line([0, 10], %)\n |> close(%, \"edge2\")\n |> extrude(10, %)\n |> fillet({ radius: 2, tags: [\"edge1\"] }, %)" ] }, { @@ -8032,11 +8044,6 @@ "type": "number", "format": "double", "nullable": true - }, - "tag": { - "description": "The tag.", - "type": "string", - "nullable": true } } }, @@ -9002,6 +9009,15 @@ } }, "required": true + }, + { + "name": "tag", + "type": "String", + "schema": { + "type": "string", + "nullable": true + }, + "required": false } ], "returnValue": { @@ -9968,7 +9984,7 @@ "unpublished": false, "deprecated": false, "examples": [ - "const part001 = startSketchOn('XY')\n |> startProfileAt([0, 0], %)\n |> lineTo({ to: [2, 2], tag: \"yo\" }, %)\n |> lineTo([3, 1], %)\n |> angledLineThatIntersects({\n angle: 180,\n intersectTag: 'yo',\n offset: 12,\n tag: \"yo2\"\n }, %)\n |> line([4, 0], %)\n |> close(%, \"yo3\")\n |> extrude(10, %)" + "const part001 = startSketchOn('XY')\n |> startProfileAt([0, 0], %)\n |> lineTo([2, 2], %, \"yo\")\n |> lineTo([3, 1], %)\n |> angledLineThatIntersects({\n angle: 180,\n intersectTag: 'yo',\n offset: 12\n }, %, \"yo2\")\n |> line([4, 0], %)\n |> close(%, \"yo3\")\n |> extrude(10, %)" ] }, { @@ -9982,43 +9998,23 @@ "type": "AngledLineToData", "schema": { "description": "Data to draw an angled line to a point.", - "anyOf": [ - { - "description": "An angle and point with a tag.", - "type": "object", - "required": [ - "angle", - "tag", - "to" - ], - "properties": { - "angle": { - "description": "The angle of the line.", - "type": "number", - "format": "double" - }, - "tag": { - "description": "The tag.", - "type": "string" - }, - "to": { - "description": "The point to draw to.", - "type": "number", - "format": "double" - } - } + "type": "object", + "required": [ + "angle", + "to" + ], + "properties": { + "angle": { + "description": "The angle of the line.", + "type": "number", + "format": "double" }, - { - "description": "An angle and point to draw to.", - "type": "array", - "items": { - "type": "number", - "format": "double" - }, - "maxItems": 2, - "minItems": 2 + "to": { + "description": "The point to draw to.", + "type": "number", + "format": "double" } - ] + } }, "required": true }, @@ -10982,6 +10978,15 @@ } }, "required": true + }, + { + "name": "tag", + "type": "String", + "schema": { + "type": "string", + "nullable": true + }, + "required": false } ], "returnValue": { @@ -11948,7 +11953,7 @@ "unpublished": false, "deprecated": false, "examples": [ - "startSketchOn('XY')\n |> startProfileAt([0, 0], %)\n |> angledLineToX({ angle: 45, to: 10, tag: \"edge1\" }, %)\n |> line([10, 10], %)\n |> line([0, 10], %)\n |> close(%, \"edge2\")\n |> extrude(10, %)\n |> fillet({ radius: 2, tags: [\"edge1\"] }, %)" + "startSketchOn('XY')\n |> startProfileAt([0, 0], %)\n |> angledLineToX({ angle: 45, to: 10 }, %, \"edge1\")\n |> line([10, 10], %)\n |> line([0, 10], %)\n |> close(%, \"edge2\")\n |> extrude(10, %)\n |> fillet({ radius: 2, tags: [\"edge1\"] }, %)" ] }, { @@ -11962,43 +11967,23 @@ "type": "AngledLineToData", "schema": { "description": "Data to draw an angled line to a point.", - "anyOf": [ - { - "description": "An angle and point with a tag.", - "type": "object", - "required": [ - "angle", - "tag", - "to" - ], - "properties": { - "angle": { - "description": "The angle of the line.", - "type": "number", - "format": "double" - }, - "tag": { - "description": "The tag.", - "type": "string" - }, - "to": { - "description": "The point to draw to.", - "type": "number", - "format": "double" - } - } + "type": "object", + "required": [ + "angle", + "to" + ], + "properties": { + "angle": { + "description": "The angle of the line.", + "type": "number", + "format": "double" }, - { - "description": "An angle and point to draw to.", - "type": "array", - "items": { - "type": "number", - "format": "double" - }, - "maxItems": 2, - "minItems": 2 + "to": { + "description": "The point to draw to.", + "type": "number", + "format": "double" } - ] + } }, "required": true }, @@ -12962,6 +12947,15 @@ } }, "required": true + }, + { + "name": "tag", + "type": "String", + "schema": { + "type": "string", + "nullable": true + }, + "required": false } ], "returnValue": { @@ -13928,7 +13922,7 @@ "unpublished": false, "deprecated": false, "examples": [ - "startSketchOn('XY')\n |> startProfileAt([0, 0], %)\n |> angledLineToY({ angle: 45, to: 10, tag: \"edge1\" }, %)\n |> line([10, 10], %)\n |> line([0, 10], %)\n |> close(%, \"edge2\")\n |> extrude(10, %)" + "startSketchOn('XY')\n |> startProfileAt([0, 0], %)\n |> angledLineToY({ angle: 45, to: 10 }, %, \"edge1\")\n |> line([10, 10], %)\n |> line([0, 10], %)\n |> close(%, \"edge2\")\n |> extrude(10, %)" ] }, { @@ -13966,12 +13960,6 @@ "description": "The radius.", "type": "number", "format": "double" - }, - "tag": { - "description": "The tag.", - "default": null, - "type": "string", - "nullable": true } } }, @@ -13999,12 +13987,6 @@ "type": "number", "format": "double" }, - "tag": { - "description": "The tag.", - "default": null, - "type": "string", - "nullable": true - }, "to": { "description": "The to point.", "type": "array", @@ -14981,6 +14963,15 @@ } }, "required": true + }, + { + "name": "tag", + "type": "String", + "schema": { + "type": "string", + "nullable": true + }, + "required": false } ], "returnValue": { @@ -15947,7 +15938,7 @@ "unpublished": false, "deprecated": false, "examples": [ - "startSketchOn('-YZ')\n |> startProfileAt([0, 0], %)\n |> arc({\n angle_start: 0,\n angle_end: 360,\n radius: 10,\n tag: \"edge1\"\n }, %)\n |> extrude(10, %)" + "startSketchOn('-YZ')\n |> startProfileAt([0, 0], %)\n |> arc({\n angle_start: 0,\n angle_end: 360,\n radius: 10\n }, %, \"edge1\")\n |> extrude(10, %)" ] }, { @@ -16050,11 +16041,6 @@ "maxItems": 2, "minItems": 2 }, - "tag": { - "description": "The tag.", - "type": "string", - "nullable": true - }, "to": { "description": "The to point.", "type": "array", @@ -17029,6 +17015,15 @@ } }, "required": true + }, + { + "name": "tag", + "type": "String", + "schema": { + "type": "string", + "nullable": true + }, + "required": false } ], "returnValue": { @@ -17995,7 +17990,7 @@ "unpublished": false, "deprecated": false, "examples": [ - "startSketchOn('XY')\n |> startProfileAt([0, 0], %)\n |> bezierCurve({\n to: [10, 10],\n control1: [5, 0],\n control2: [5, 10],\n tag: \"edge1\"\n }, %)\n |> close(%)\n |> extrude(10, %)" + "startSketchOn('XY')\n |> startProfileAt([0, 0], %)\n |> bezierCurve({\n to: [10, 10],\n control1: [5, 0],\n control2: [5, 10]\n }, %, \"edge1\")\n |> close(%)\n |> extrude(10, %)" ] }, { @@ -25592,7 +25587,7 @@ "unpublished": false, "deprecated": false, "examples": [ - "const part001 = startSketchOn('XY')\n |> startProfileAt([0, 0], %)\n |> line({ to: [0, 10], tag: \"thing\" }, %)\n |> line([10, 0], %)\n |> line({ to: [0, -10], tag: \"thing2\" }, %)\n |> close(%)\n |> extrude(10, %)\n |> fillet({ radius: 2, tags: [\"thing\", \"thing2\"] }, %)" + "const part001 = startSketchOn('XY')\n |> startProfileAt([0, 0], %)\n |> line([0, 10], %, \"thing\")\n |> line([10, 0], %)\n |> line([0, -10], %, \"thing2\")\n |> close(%)\n |> extrude(10, %)\n |> fillet({ radius: 2, tags: [\"thing\", \"thing2\"] }, %)" ] }, { @@ -26456,7 +26451,7 @@ "unpublished": false, "deprecated": false, "examples": [ - "const box = startSketchOn('XY')\n |> startProfileAt([0, 0], %)\n |> line([0, 10], %)\n |> line([10, 0], %)\n |> line({ to: [0, -10], tag: \"surface\" }, %)\n |> close(%)\n |> extrude(5, %)\n\nconst transform = getExtrudeWallTransform('surface', box)" + "const box = startSketchOn('XY')\n |> startProfileAt([0, 0], %)\n |> line([0, 10], %)\n |> line([10, 0], %)\n |> line([0, -10], %, \"surface\")\n |> close(%)\n |> extrude(5, %)\n\nconst transform = getExtrudeWallTransform('surface', box)" ] }, { @@ -27242,7 +27237,7 @@ "unpublished": false, "deprecated": false, "examples": [ - "const part001 = startSketchOn('XY')\n |> startProfileAt([0, 0], %)\n |> line({ to: [0, 10], tag: \"thing\" }, %)\n |> line({ to: [10, 0], tag: \"thing1\" }, %)\n |> line({ to: [0, -10], tag: \"thing2\" }, %)\n |> close(%)\n |> extrude(10, %)\n |> fillet({\n radius: 2,\n tags: [getNextAdjacentEdge(\"thing\", %)]\n }, %)" + "const part001 = startSketchOn('XY')\n |> startProfileAt([0, 0], %)\n |> line([0, 10], %, \"thing\")\n |> line([10, 0], %, \"thing1\")\n |> line([0, -10], %, \"thing2\")\n |> close(%)\n |> extrude(10, %)\n |> fillet({\n radius: 2,\n tags: [getNextAdjacentEdge(\"thing\", %)]\n }, %)" ] }, { @@ -28028,7 +28023,7 @@ "unpublished": false, "deprecated": false, "examples": [ - "const part001 = startSketchOn('XY')\n |> startProfileAt([0, 0], %)\n |> line({ to: [0, 10], tag: \"thing\" }, %)\n |> line([10, 0], %)\n |> line({ to: [0, -10], tag: \"thing2\" }, %)\n |> close(%)\n |> extrude(10, %)\n |> fillet({\n radius: 2,\n tags: [\"thing\", getOppositeEdge(\"thing\", %)]\n }, %)" + "const part001 = startSketchOn('XY')\n |> startProfileAt([0, 0], %)\n |> line([0, 10], %, \"thing\")\n |> line([10, 0], %)\n |> line([0, -10], %, \"thing2\")\n |> close(%)\n |> extrude(10, %)\n |> fillet({\n radius: 2,\n tags: [\"thing\", getOppositeEdge(\"thing\", %)]\n }, %)" ] }, { @@ -28814,7 +28809,7 @@ "unpublished": false, "deprecated": false, "examples": [ - "const part001 = startSketchOn('XY')\n |> startProfileAt([0, 0], %)\n |> line({ to: [0, 10], tag: \"thing\" }, %)\n |> line({ to: [10, 0], tag: \"thing1\" }, %)\n |> line({ to: [0, -10], tag: \"thing2\" }, %)\n |> close(%)\n |> extrude(10, %)\n |> fillet({\n radius: 2,\n tags: [getPreviousAdjacentEdge(\"thing2\", %)]\n }, %)" + "const part001 = startSketchOn('XY')\n |> startProfileAt([0, 0], %)\n |> line([0, 10], %, \"thing\")\n |> line([10, 0], %, \"thing1\")\n |> line([0, -10], %, \"thing2\")\n |> close(%)\n |> extrude(10, %)\n |> fillet({\n radius: 2,\n tags: [getPreviousAdjacentEdge(\"thing2\", %)]\n }, %)" ] }, { @@ -34335,7 +34330,7 @@ "unpublished": false, "deprecated": false, "examples": [ - "startSketchOn(\"YZ\")\n |> startProfileAt([0, 0], %)\n |> line({ to: [5, 0], tag: \"thing\" }, %)\n |> line([5, 5], %)\n |> line([0, lastSegX(%)], %)\n |> close(%)\n |> extrude(5, %)" + "startSketchOn(\"YZ\")\n |> startProfileAt([0, 0], %)\n |> line([5, 0], %, \"thing\")\n |> line([5, 5], %)\n |> line([0, lastSegX(%)], %)\n |> close(%)\n |> extrude(5, %)" ] }, { @@ -35318,7 +35313,7 @@ "unpublished": false, "deprecated": false, "examples": [ - "startSketchOn(\"YZ\")\n |> startProfileAt([0, 0], %)\n |> line({ to: [5, 0], tag: \"thing\" }, %)\n |> line([5, 5], %)\n |> line([0, lastSegY(%)], %)\n |> close(%)\n |> extrude(5, %)" + "startSketchOn(\"YZ\")\n |> startProfileAt([0, 0], %)\n |> line([5, 0], %, \"thing\")\n |> line([5, 5], %)\n |> line([0, lastSegY(%)], %)\n |> close(%)\n |> extrude(5, %)" ] }, { @@ -35448,46 +35443,16 @@ "tags": [], "args": [ { - "name": "data", - "type": "LineData", + "name": "delta", + "type": "[number]", "schema": { - "description": "Data to draw a line.", - "anyOf": [ - { - "description": "A point with a tag.", - "type": "object", - "required": [ - "tag", - "to" - ], - "properties": { - "tag": { - "description": "The tag.", - "type": "string" - }, - "to": { - "description": "The to point.", - "type": "array", - "items": { - "type": "number", - "format": "double" - }, - "maxItems": 2, - "minItems": 2 - } - } - }, - { - "description": "A point.", - "type": "array", - "items": { - "type": "number", - "format": "double" - }, - "maxItems": 2, - "minItems": 2 - } - ] + "type": "array", + "items": { + "type": "number", + "format": "double" + }, + "maxItems": 2, + "minItems": 2 }, "required": true }, @@ -36451,6 +36416,15 @@ } }, "required": true + }, + { + "name": "tag", + "type": "String", + "schema": { + "type": "string", + "nullable": true + }, + "required": false } ], "returnValue": { @@ -37417,7 +37391,7 @@ "unpublished": false, "deprecated": false, "examples": [ - "startSketchOn('-XY')\n |> startProfileAt([0, 0], %)\n |> line([10, 10], %)\n |> line({ to: [20, 10], tag: \"edge1\" }, %)\n |> close(%, \"edge2\")\n |> extrude(10, %)" + "startSketchOn('-XY')\n |> startProfileAt([0, 0], %)\n |> line([10, 10], %)\n |> line([20, 10], %, \"edge1\")\n |> close(%, \"edge2\")\n |> extrude(10, %)" ] }, { @@ -37427,46 +37401,16 @@ "tags": [], "args": [ { - "name": "data", - "type": "LineToData", + "name": "to", + "type": "[number]", "schema": { - "description": "Data to draw a line to a point.", - "anyOf": [ - { - "description": "A point with a tag.", - "type": "object", - "required": [ - "tag", - "to" - ], - "properties": { - "tag": { - "description": "The tag.", - "type": "string" - }, - "to": { - "description": "The to point.", - "type": "array", - "items": { - "type": "number", - "format": "double" - }, - "maxItems": 2, - "minItems": 2 - } - } - }, - { - "description": "A point.", - "type": "array", - "items": { - "type": "number", - "format": "double" - }, - "maxItems": 2, - "minItems": 2 - } - ] + "type": "array", + "items": { + "type": "number", + "format": "double" + }, + "maxItems": 2, + "minItems": 2 }, "required": true }, @@ -38430,6 +38374,15 @@ } }, "required": true + }, + { + "name": "tag", + "type": "String", + "schema": { + "type": "string", + "nullable": true + }, + "required": false } ], "returnValue": { @@ -39396,7 +39349,7 @@ "unpublished": false, "deprecated": false, "examples": [ - "fn rectShape = (pos, w, l) => {\n const rr = startSketchOn('YZ')\n |> startProfileAt([pos[0] - (w / 2), pos[1] - (l / 2)], %)\n |> lineTo({\n to: [pos[0] + w / 2, pos[1] - (l / 2)],\n tag: \"edge1\"\n }, %)\n |> lineTo({\n to: [pos[0] + w / 2, pos[1] + l / 2],\n tag: \"edge2\"\n }, %)\n |> lineTo({\n to: [pos[0] - (w / 2), pos[1] + l / 2],\n tag: \"edge3\"\n }, %)\n |> close(%, \"edge4\")\n return rr\n}\n\n// Create the mounting plate extrusion, holes, and fillets\nconst part = rectShape([0, 0], 20, 20)" + "fn rectShape = (pos, w, l) => {\n const rr = startSketchOn('YZ')\n |> startProfileAt([pos[0] - (w / 2), pos[1] - (l / 2)], %)\n |> lineTo([pos[0] + w / 2, pos[1] - (l / 2)], %, \"edge1\")\n |> lineTo([pos[0] + w / 2, pos[1] + l / 2], %, \"edge2\")\n |> lineTo([pos[0] - (w / 2), pos[1] + l / 2], %, \"edge3\")\n |> close(%, \"edge4\")\n return rr\n}\n\n// Create the mounting plate extrusion, holes, and fillets\nconst part = rectShape([0, 0], 20, 20)" ] }, { @@ -47750,7 +47703,7 @@ "unpublished": false, "deprecated": false, "examples": [ - "const part001 = startSketchOn('XY')\n |> startProfileAt([4.83, 12.56], %)\n |> line([15.1, 2.48], %)\n |> line({ to: [3.15, -9.85], tag: 'seg01' }, %)\n |> line([-15.17, -4.1], %)\n |> angledLine([segAng('seg01', %), 12.35], %)\n |> line([-13.02, 10.03], %)\n |> close(%)\n |> extrude(4, %)" + "const part001 = startSketchOn('XY')\n |> startProfileAt([4.83, 12.56], %)\n |> line([15.1, 2.48], %)\n |> line([3.15, -9.85], %, 'seg01')\n |> line([-15.17, -4.1], %)\n |> angledLine([segAng('seg01', %), 12.35], %)\n |> line([-13.02, 10.03], %)\n |> close(%)\n |> extrude(4, %)" ] }, { @@ -48741,7 +48694,7 @@ "unpublished": false, "deprecated": false, "examples": [ - "startSketchOn(\"YZ\")\n |> startProfileAt([0, 0], %)\n |> line({ to: [5, 0], tag: \"thing\" }, %)\n |> line([5, 5], %)\n |> line([segEndX(\"thing\", %), 5], %)\n |> close(%)\n |> extrude(5, %)" + "startSketchOn(\"YZ\")\n |> startProfileAt([0, 0], %)\n |> line([5, 0], %, \"thing\")\n |> line([5, 5], %)\n |> line([segEndX(\"thing\", %), 5], %)\n |> close(%)\n |> extrude(5, %)" ] }, { @@ -49732,7 +49685,7 @@ "unpublished": false, "deprecated": false, "examples": [ - "startSketchOn(\"YZ\")\n |> startProfileAt([0, 0], %)\n |> line({ to: [5, 0], tag: \"thing\" }, %)\n |> line([5, 5], %)\n |> line([segEndY(\"thing\", %), 5], %)\n |> close(%)\n |> extrude(5, %)" + "startSketchOn(\"YZ\")\n |> startProfileAt([0, 0], %)\n |> line([5, 0], %, \"thing\")\n |> line([5, 5], %)\n |> line([segEndY(\"thing\", %), 5], %)\n |> close(%)\n |> extrude(5, %)" ] }, { @@ -50723,7 +50676,7 @@ "unpublished": false, "deprecated": false, "examples": [ - "startSketchOn(\"YZ\")\n |> startProfileAt([0, 0], %)\n |> line({ to: [5, 0], tag: \"thing\" }, %)\n |> line([5, 5], %)\n |> line([0, segLen(\"thing\", %)], %)\n |> close(%)\n |> extrude(5, %)" + "startSketchOn(\"YZ\")\n |> startProfileAt([0, 0], %)\n |> line([5, 0], %, \"thing\")\n |> line([5, 5], %)\n |> line([0, segLen(\"thing\", %)], %)\n |> close(%)\n |> extrude(5, %)" ] }, { @@ -50795,46 +50748,16 @@ "tags": [], "args": [ { - "name": "data", - "type": "LineData", + "name": "to", + "type": "[number]", "schema": { - "description": "Data to draw a line.", - "anyOf": [ - { - "description": "A point with a tag.", - "type": "object", - "required": [ - "tag", - "to" - ], - "properties": { - "tag": { - "description": "The tag.", - "type": "string" - }, - "to": { - "description": "The to point.", - "type": "array", - "items": { - "type": "number", - "format": "double" - }, - "maxItems": 2, - "minItems": 2 - } - } - }, - { - "description": "A point.", - "type": "array", - "items": { - "type": "number", - "format": "double" - }, - "maxItems": 2, - "minItems": 2 - } - ] + "type": "array", + "items": { + "type": "number", + "format": "double" + }, + "maxItems": 2, + "minItems": 2 }, "required": true }, @@ -51137,6 +51060,15 @@ ] }, "required": true + }, + { + "name": "tag", + "type": "String", + "schema": { + "type": "string", + "nullable": true + }, + "required": false } ], "returnValue": { @@ -52114,45 +52046,15 @@ "args": [ { "name": "data", - "type": "LineData", + "type": "[number]", "schema": { - "description": "Data to draw a line.", - "anyOf": [ - { - "description": "A point with a tag.", - "type": "object", - "required": [ - "tag", - "to" - ], - "properties": { - "tag": { - "description": "The tag.", - "type": "string" - }, - "to": { - "description": "The to point.", - "type": "array", - "items": { - "type": "number", - "format": "double" - }, - "maxItems": 2, - "minItems": 2 - } - } - }, - { - "description": "A point.", - "type": "array", - "items": { - "type": "number", - "format": "double" - }, - "maxItems": 2, - "minItems": 2 - } - ] + "type": "array", + "items": { + "type": "number", + "format": "double" + }, + "maxItems": 2, + "minItems": 2 }, "required": true } @@ -54388,8 +54290,8 @@ "unpublished": false, "deprecated": false, "examples": [ - "startSketchOn('XY')\n |> startProfileAt([0, 0], %)\n |> line([10, 10], %)\n |> line({ to: [20, 10], tag: \"edge1\" }, %)\n |> close(%, \"edge2\")", - "fn cube = (pos, scale) => {\n const sg = startSketchOn('XY')\n |> startProfileAt(pos, %)\n |> line([0, scale], %)\n |> line([scale, 0], %)\n |> line([0, -scale], %)\n |> close(%)\n |> extrude(scale, %)\n\n return sg\n}\n\nconst box = cube([0, 0], 20)\n\nconst part001 = startSketchOn(box, \"start\")\n |> startProfileAt([0, 0], %)\n |> line([10, 10], %)\n |> line({ to: [20, 10], tag: \"edge1\" }, %)\n |> close(%)\n |> extrude(20, %)" + "startSketchOn('XY')\n |> startProfileAt([0, 0], %)\n |> line([10, 10], %)\n |> line([20, 10], %, \"edge1\")\n |> close(%, \"edge2\")", + "fn cube = (pos, scale) => {\n const sg = startSketchOn('XY')\n |> startProfileAt(pos, %)\n |> line([0, scale], %)\n |> line([scale, 0], %)\n |> line([0, -scale], %)\n |> close(%)\n |> extrude(scale, %)\n\n return sg\n}\n\nconst box = cube([0, 0], 20)\n\nconst part001 = startSketchOn(box, \"start\")\n |> startProfileAt([0, 0], %)\n |> line([10, 10], %)\n |> line([20, 10], %, \"edge1\")\n |> close(%)\n |> extrude(20, %)" ] }, { @@ -54454,30 +54356,6 @@ } } }, - { - "description": "A point with a tag.", - "type": "object", - "required": [ - "tag", - "to" - ], - "properties": { - "tag": { - "description": "The tag.", - "type": "string" - }, - "to": { - "description": "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.", - "type": "array", - "items": { - "type": "number", - "format": "double" - }, - "maxItems": 2, - "minItems": 2 - } - } - }, { "description": "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.", "type": "array", @@ -55452,6 +55330,15 @@ } }, "required": true + }, + { + "name": "tag", + "type": "String", + "schema": { + "type": "string", + "nullable": true + }, + "required": false } ], "returnValue": { @@ -56418,7 +56305,7 @@ "unpublished": false, "deprecated": false, "examples": [ - "startSketchOn('-YZ')\n |> startProfileAt([0, 0], %)\n |> line({ to: [10, 10], tag: \"edge0\" }, %)\n |> tangentialArc({ radius: 10, offset: 90, tag: \"edge1\" }, %)\n |> close(%)\n |> extrude(10, %)" + "startSketchOn('-YZ')\n |> startProfileAt([0, 0], %)\n |> line([10, 10], %, \"edge1\")\n |> tangentialArc({ radius: 10, offset: 90 }, %, \"edge1\")\n |> close(%)\n |> extrude(10, %)" ] }, { @@ -58376,7 +58263,7 @@ "unpublished": false, "deprecated": false, "examples": [ - "startSketchOn('-YZ')\n |> startProfileAt([0, 0], %)\n |> line({ to: [10, 10], tag: \"edge0\" }, %)\n |> tangentialArcTo([10, 0], %)\n |> close(%)" + "startSketchOn('-YZ')\n |> startProfileAt([0, 0], %)\n |> line([10, 10], %, \"edge0\")\n |> tangentialArcTo([10, 0], %)\n |> close(%)" ] }, { @@ -58469,36 +58356,11 @@ "tags": [], "args": [ { - "name": "data", - "type": "AxisLineData", + "name": "length", + "type": "number", "schema": { - "description": "Data to draw a line on an axis.", - "anyOf": [ - { - "description": "The length with a tag.", - "type": "object", - "required": [ - "length", - "tag" - ], - "properties": { - "length": { - "description": "The length of the line.", - "type": "number", - "format": "double" - }, - "tag": { - "description": "The tag.", - "type": "string" - } - } - }, - { - "description": "The length.", - "type": "number", - "format": "double" - } - ] + "type": "number", + "format": "double" }, "required": true }, @@ -59462,6 +59324,15 @@ } }, "required": true + }, + { + "name": "tag", + "type": "String", + "schema": { + "type": "string", + "nullable": true + }, + "required": false } ], "returnValue": { @@ -60438,36 +60309,11 @@ "tags": [], "args": [ { - "name": "data", - "type": "AxisLineToData", + "name": "to", + "type": "number", "schema": { - "description": "Data to draw a line to a point on an axis.", - "anyOf": [ - { - "description": "A point with a tag.", - "type": "object", - "required": [ - "tag", - "to" - ], - "properties": { - "tag": { - "description": "The tag.", - "type": "string" - }, - "to": { - "description": "The to point.", - "type": "number", - "format": "double" - } - } - }, - { - "description": "A point.", - "type": "number", - "format": "double" - } - ] + "type": "number", + "format": "double" }, "required": true }, @@ -61431,6 +61277,15 @@ } }, "required": true + }, + { + "name": "tag", + "type": "String", + "schema": { + "type": "string", + "nullable": true + }, + "required": false } ], "returnValue": { @@ -62397,7 +62252,7 @@ "unpublished": false, "deprecated": false, "examples": [ - "startSketchOn('XY')\n |> startProfileAt([0, 0], %)\n |> xLineTo({ to: 10, tag: \"edge1\" }, %)\n |> line([10, 10], %)\n |> close(%, \"edge2\")\n |> extrude(10, %)" + "startSketchOn('XY')\n |> startProfileAt([0, 0], %)\n |> xLineTo(10, %, \"edge1\")\n |> line([10, 10], %)\n |> close(%, \"edge2\")\n |> extrude(10, %)" ] }, { @@ -62407,36 +62262,11 @@ "tags": [], "args": [ { - "name": "data", - "type": "AxisLineData", + "name": "length", + "type": "number", "schema": { - "description": "Data to draw a line on an axis.", - "anyOf": [ - { - "description": "The length with a tag.", - "type": "object", - "required": [ - "length", - "tag" - ], - "properties": { - "length": { - "description": "The length of the line.", - "type": "number", - "format": "double" - }, - "tag": { - "description": "The tag.", - "type": "string" - } - } - }, - { - "description": "The length.", - "type": "number", - "format": "double" - } - ] + "type": "number", + "format": "double" }, "required": true }, @@ -63400,6 +63230,15 @@ } }, "required": true + }, + { + "name": "tag", + "type": "String", + "schema": { + "type": "string", + "nullable": true + }, + "required": false } ], "returnValue": { @@ -64376,36 +64215,11 @@ "tags": [], "args": [ { - "name": "data", - "type": "AxisLineToData", + "name": "to", + "type": "number", "schema": { - "description": "Data to draw a line to a point on an axis.", - "anyOf": [ - { - "description": "A point with a tag.", - "type": "object", - "required": [ - "tag", - "to" - ], - "properties": { - "tag": { - "description": "The tag.", - "type": "string" - }, - "to": { - "description": "The to point.", - "type": "number", - "format": "double" - } - } - }, - { - "description": "A point.", - "type": "number", - "format": "double" - } - ] + "type": "number", + "format": "double" }, "required": true }, @@ -65369,6 +65183,15 @@ } }, "required": true + }, + { + "name": "tag", + "type": "String", + "schema": { + "type": "string", + "nullable": true + }, + "required": false } ], "returnValue": { @@ -66335,7 +66158,7 @@ "unpublished": false, "deprecated": false, "examples": [ - "startSketchOn('XZ')\n |> startProfileAt([0, 0], %)\n |> yLineTo({ to: 10, tag: \"edge1\" }, %)\n |> line([10, 10], %)\n |> close(%, \"edge2\")\n |> extrude(10, %)\n |> fillet({ radius: 2, tags: [\"edge2\"] }, %)" + "startSketchOn('XZ')\n |> startProfileAt([0, 0], %)\n |> yLineTo(10, %, \"edge1\")\n |> line([10, 10], %)\n |> close(%, \"edge2\")\n |> extrude(10, %)\n |> fillet({ radius: 2, tags: [\"edge2\"] }, %)" ] } ] \ No newline at end of file diff --git a/docs/kcl/tangentialArc.md b/docs/kcl/tangentialArc.md index 2c869c8dad..6856988034 100644 --- a/docs/kcl/tangentialArc.md +++ b/docs/kcl/tangentialArc.md @@ -9,7 +9,7 @@ Draw an arc. ```js -tangentialArc(data: TangentialArcData, sketch_group: SketchGroup) -> SketchGroup +tangentialArc(data: TangentialArcData, sketch_group: SketchGroup, tag?: String) -> SketchGroup ``` ### Examples @@ -17,8 +17,8 @@ tangentialArc(data: TangentialArcData, sketch_group: SketchGroup) -> SketchGroup ```js startSketchOn('-YZ') |> startProfileAt([0, 0], %) - |> line({ to: [10, 10], tag: "edge0" }, %) - |> tangentialArc({ radius: 10, offset: 90, tag: "edge1" }, %) + |> line([10, 10], %, "edge1") + |> tangentialArc({ radius: 10, offset: 90 }, %, "edge1") |> close(%) |> extrude(10, %) ``` @@ -33,12 +33,6 @@ startSketchOn('-YZ') // Radius of the arc. Not to be confused with Raiders of the Lost Ark. radius: number, } | -{ - // The tag. - tag: string, - // 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. - to: [number, number], -} | [number, number] ``` * `sketch_group`: `SketchGroup` - A sketch group is a collection of paths. (REQUIRED) @@ -205,6 +199,7 @@ startSketchOn('-YZ') }, } ``` +* `tag`: `String` (OPTIONAL) ### Returns diff --git a/docs/kcl/tangentialArcTo.md b/docs/kcl/tangentialArcTo.md index 5a16b67014..5737a93f7d 100644 --- a/docs/kcl/tangentialArcTo.md +++ b/docs/kcl/tangentialArcTo.md @@ -17,7 +17,7 @@ tangentialArcTo(to: [number], sketch_group: SketchGroup, tag?: String) -> Sketch ```js startSketchOn('-YZ') |> startProfileAt([0, 0], %) - |> line({ to: [10, 10], tag: "edge0" }, %) + |> line([10, 10], %, "edge0") |> tangentialArcTo([10, 0], %) |> close(%) ``` diff --git a/docs/kcl/xLine.md b/docs/kcl/xLine.md index 3653a4031d..2206a9e032 100644 --- a/docs/kcl/xLine.md +++ b/docs/kcl/xLine.md @@ -9,7 +9,7 @@ Draw a line on the x-axis. ```js -xLine(data: AxisLineData, sketch_group: SketchGroup) -> SketchGroup +xLine(length: number, sketch_group: SketchGroup, tag?: String) -> SketchGroup ``` ### Examples @@ -25,16 +25,7 @@ startSketchOn('YZ') ### Arguments -* `data`: `AxisLineData` - Data to draw a line on an axis. (REQUIRED) -```js -{ - // The length of the line. - length: number, - // The tag. - tag: string, -} | -number -``` +* `length`: `number` (REQUIRED) * `sketch_group`: `SketchGroup` - A sketch group is a collection of paths. (REQUIRED) ```js { @@ -199,6 +190,7 @@ number }, } ``` +* `tag`: `String` (OPTIONAL) ### Returns diff --git a/docs/kcl/xLineTo.md b/docs/kcl/xLineTo.md index b1bf0c684d..13008c89ac 100644 --- a/docs/kcl/xLineTo.md +++ b/docs/kcl/xLineTo.md @@ -9,7 +9,7 @@ Draw a line to a point on the x-axis. ```js -xLineTo(data: AxisLineToData, sketch_group: SketchGroup) -> SketchGroup +xLineTo(to: number, sketch_group: SketchGroup, tag?: String) -> SketchGroup ``` ### Examples @@ -17,7 +17,7 @@ xLineTo(data: AxisLineToData, sketch_group: SketchGroup) -> SketchGroup ```js startSketchOn('XY') |> startProfileAt([0, 0], %) - |> xLineTo({ to: 10, tag: "edge1" }, %) + |> xLineTo(10, %, "edge1") |> line([10, 10], %) |> close(%, "edge2") |> extrude(10, %) @@ -25,16 +25,7 @@ startSketchOn('XY') ### Arguments -* `data`: `AxisLineToData` - Data to draw a line to a point on an axis. (REQUIRED) -```js -{ - // The tag. - tag: string, - // The to point. - to: number, -} | -number -``` +* `to`: `number` (REQUIRED) * `sketch_group`: `SketchGroup` - A sketch group is a collection of paths. (REQUIRED) ```js { @@ -199,6 +190,7 @@ number }, } ``` +* `tag`: `String` (OPTIONAL) ### Returns diff --git a/docs/kcl/yLine.md b/docs/kcl/yLine.md index e0e60ada09..bc26b9d601 100644 --- a/docs/kcl/yLine.md +++ b/docs/kcl/yLine.md @@ -9,7 +9,7 @@ Draw a line on the y-axis. ```js -yLine(data: AxisLineData, sketch_group: SketchGroup) -> SketchGroup +yLine(length: number, sketch_group: SketchGroup, tag?: String) -> SketchGroup ``` ### Examples @@ -25,16 +25,7 @@ startSketchOn('XY') ### Arguments -* `data`: `AxisLineData` - Data to draw a line on an axis. (REQUIRED) -```js -{ - // The length of the line. - length: number, - // The tag. - tag: string, -} | -number -``` +* `length`: `number` (REQUIRED) * `sketch_group`: `SketchGroup` - A sketch group is a collection of paths. (REQUIRED) ```js { @@ -199,6 +190,7 @@ number }, } ``` +* `tag`: `String` (OPTIONAL) ### Returns diff --git a/docs/kcl/yLineTo.md b/docs/kcl/yLineTo.md index 409a0277d6..6ef4465cb2 100644 --- a/docs/kcl/yLineTo.md +++ b/docs/kcl/yLineTo.md @@ -9,7 +9,7 @@ Draw a line to a point on the y-axis. ```js -yLineTo(data: AxisLineToData, sketch_group: SketchGroup) -> SketchGroup +yLineTo(to: number, sketch_group: SketchGroup, tag?: String) -> SketchGroup ``` ### Examples @@ -17,7 +17,7 @@ yLineTo(data: AxisLineToData, sketch_group: SketchGroup) -> SketchGroup ```js startSketchOn('XZ') |> startProfileAt([0, 0], %) - |> yLineTo({ to: 10, tag: "edge1" }, %) + |> yLineTo(10, %, "edge1") |> line([10, 10], %) |> close(%, "edge2") |> extrude(10, %) @@ -26,16 +26,7 @@ startSketchOn('XZ') ### Arguments -* `data`: `AxisLineToData` - Data to draw a line to a point on an axis. (REQUIRED) -```js -{ - // The tag. - tag: string, - // The to point. - to: number, -} | -number -``` +* `to`: `number` (REQUIRED) * `sketch_group`: `SketchGroup` - A sketch group is a collection of paths. (REQUIRED) ```js { @@ -200,6 +191,7 @@ number }, } ``` +* `tag`: `String` (OPTIONAL) ### Returns diff --git a/e2e/playwright/flow-tests.spec.ts b/e2e/playwright/flow-tests.spec.ts index 668a1a83cc..dc43f6b365 100644 --- a/e2e/playwright/flow-tests.spec.ts +++ b/e2e/playwright/flow-tests.spec.ts @@ -130,7 +130,7 @@ test('Basic sketch', async ({ page }) => { await expect(page.locator('.cm-content')) .toHaveText(`const part001 = startSketchOn('-XZ') |> startProfileAt(${commonPoints.startAt}, %) - |> line({ to: [${commonPoints.num1}, 0], tag: 'seg01' }, %) + |> line([${commonPoints.num1}, 0], %, 'seg01') |> line([0, ${commonPoints.num1}], %) |> angledLine([180, segLen('seg01', %)], %)`) }) diff --git a/e2e/playwright/snapshot-tests.spec.ts b/e2e/playwright/snapshot-tests.spec.ts index 7e21fe119b..578e11205c 100644 --- a/e2e/playwright/snapshot-tests.spec.ts +++ b/e2e/playwright/snapshot-tests.spec.ts @@ -55,10 +55,9 @@ const part001 = startSketchOn('-XZ') |> angledLineToY({ angle: topAng, to: totalHeightHalf, - tag: 'seg04' - }, %) - |> xLineTo({ to: totalLen, tag: 'seg03' }, %) - |> yLine({ length: -armThick, tag: 'seg01' }, %) + }, %, 'seg04') + |> xLineTo(totalLen, %, 'seg03') + |> yLine(-armThick, %, 'seg01') |> angledLineThatIntersects({ angle: HALF_TURN, offset: -armThick, @@ -68,8 +67,7 @@ const part001 = startSketchOn('-XZ') |> angledLineToY({ angle: -bottomAng, to: -totalHeightHalf - armThick, - tag: 'seg02' - }, %) + }, %, 'seg02') |> xLineTo(segEndX('seg03', %) + 0, %) |> yLine(-segLen('seg01', %), %) |> angledLineThatIntersects({ diff --git a/src/lang/abstractSyntaxTree.test.ts b/src/lang/abstractSyntaxTree.test.ts index 297de89a73..996bc4e980 100644 --- a/src/lang/abstractSyntaxTree.test.ts +++ b/src/lang/abstractSyntaxTree.test.ts @@ -360,7 +360,7 @@ describe('testing pipe operator special', () => { test('pipe operator with sketch', () => { let code = `const mySketch = startSketchAt([0, 0]) |> lineTo([2, 3], %) - |> lineTo({ to: [0, 1], tag: "myPath" }, %) + |> lineTo([0, 1], %, "myPath") |> lineTo([1, 1], %) |> rx(45, %) ` @@ -370,18 +370,18 @@ describe('testing pipe operator special', () => { { type: 'VariableDeclaration', start: 0, - end: 145, + end: 132, kind: 'const', declarations: [ { type: 'VariableDeclarator', start: 6, - end: 145, + end: 132, id: { type: 'Identifier', start: 6, end: 14, name: 'mySketch' }, init: { type: 'PipeExpression', start: 17, - end: 145, + end: 132, body: [ { type: 'CallExpression', @@ -457,7 +457,7 @@ describe('testing pipe operator special', () => { { type: 'CallExpression', start: 67, - end: 107, + end: 94, callee: { type: 'Identifier', start: 67, @@ -466,121 +466,92 @@ describe('testing pipe operator special', () => { }, arguments: [ { - type: 'ObjectExpression', + type: 'ArrayExpression', start: 74, - end: 103, - properties: [ + end: 80, + elements: [ { - type: 'ObjectProperty', - start: 76, - end: 86, - key: { - type: 'Identifier', - start: 76, - end: 78, - name: 'to', - }, - value: { - type: 'ArrayExpression', - start: 80, - end: 86, - elements: [ - { - type: 'Literal', - start: 81, - end: 82, - value: 0, - raw: '0', - }, - { - type: 'Literal', - start: 84, - end: 85, - value: 1, - raw: '1', - }, - ], - }, + type: 'Literal', + start: 75, + end: 76, + value: 0, + raw: '0', }, { - type: 'ObjectProperty', - start: 88, - end: 101, - key: { - type: 'Identifier', - start: 88, - end: 91, - name: 'tag', - }, - value: { - type: 'Literal', - start: 93, - end: 101, - value: 'myPath', - raw: '"myPath"', - }, + type: 'Literal', + start: 78, + end: 79, + value: 1, + raw: '1', }, ], }, - { type: 'PipeSubstitution', start: 105, end: 106 }, + { type: 'PipeSubstitution', start: 82, end: 83 }, + { + type: 'Literal', + start: 85, + end: 93, + value: 'myPath', + raw: '"myPath"', + }, ], optional: false, }, { type: 'CallExpression', - start: 113, - end: 130, + start: 100, + end: 117, callee: { type: 'Identifier', - start: 113, - end: 119, + start: 100, + end: 106, name: 'lineTo', }, arguments: [ { type: 'ArrayExpression', - start: 120, - end: 126, + start: 107, + end: 113, elements: [ { type: 'Literal', - start: 121, - end: 122, + start: 108, + end: 109, value: 1, raw: '1', }, { type: 'Literal', - start: 124, - end: 125, + start: 111, + end: 112, value: 1, raw: '1', }, ], }, - { type: 'PipeSubstitution', start: 128, end: 129 }, + { type: 'PipeSubstitution', start: 115, end: 116 }, ], optional: false, }, { type: 'CallExpression', - start: 136, - end: 145, + start: 123, + end: 132, callee: { type: 'Identifier', - start: 136, - end: 138, + start: 123, + end: 125, name: 'rx', }, arguments: [ { type: 'Literal', - start: 139, - end: 141, + start: 126, + end: 128, value: 45, raw: '45', }, - { type: 'PipeSubstitution', start: 143, end: 144 }, + { type: 'PipeSubstitution', start: 130, end: 131 }, ], optional: false, }, @@ -1502,11 +1473,11 @@ const key = 'c'` }) it('comments nested within a block statement', () => { const code = `const mySketch = startSketchAt([0,0]) - |> lineTo({ to: [0, 1], tag: 'myPath' }, %) + |> lineTo([0, 1], %, 'myPath') |> lineTo([1, 1], %) /* this is a comment spanning a few lines */ - |> lineTo({ to: [1,0], tag: "rightPath" }, %) + |> lineTo([1,0], %, "rightPath") |> close(%) ` @@ -1516,8 +1487,8 @@ const key = 'c'` .nonCodeNodes expect(sketchNonCodeMeta[indexOfSecondLineToExpression][0]).toEqual({ type: 'NonCodeNode', - start: 106, - end: 163, + start: 93, + end: 150, value: { type: 'inlineComment', style: 'block', @@ -1529,7 +1500,7 @@ const key = 'c'` const code = [ 'const mySk1 = startSketchAt([0, 0])', ' |> lineTo([1, 1], %)', - ' |> lineTo({to: [0, 1], tag: "myPath"}, %)', + ' |> lineTo([0, 1], %, "myPath")', ' |> lineTo([1, 1], %)', '// a comment', ' |> rx(90, %)', @@ -1540,8 +1511,8 @@ const key = 'c'` .nonCodeNodes[3][0] expect(sketchNonCodeMeta).toEqual({ type: 'NonCodeNode', - start: 125, - end: 138, + start: 114, + end: 127, value: { type: 'blockComment', value: 'a comment', diff --git a/src/lang/artifact.test.ts b/src/lang/artifact.test.ts index 771a2d7184..26882a55bb 100644 --- a/src/lang/artifact.test.ts +++ b/src/lang/artifact.test.ts @@ -94,7 +94,7 @@ const mySketch001 = startSketchOn('XY') const sk1 = startSketchOn('XY') |> startProfileAt([0, 0], %) |> lineTo([-2.5, 0], %) - |> lineTo({ to: [0, 10], tag: "p" }, %) + |> lineTo([0, 10], %, "p") |> lineTo([2.5, 0], %) // |> rx(45, %) // |> translate([1,0,1], %) @@ -104,7 +104,7 @@ const theExtrude = extrude(2, sk1) const sk2 = startSketchOn('XY') |> startProfileAt([0, 0], %) |> lineTo([-2.5, 0], %) - |> lineTo({ to: [0, 3], tag: "p" }, %) + |> lineTo([0, 3], %, "p") |> lineTo([2.5, 0], %) // |> transform(theTransf, %) |> extrude(2, %) @@ -143,7 +143,7 @@ const sk2 = startSketchOn('XY') xAxis: { x: 1, y: 0, z: 0 }, yAxis: { x: 0, y: 1, z: 0 }, zAxis: { x: 0, y: 0, z: 1 }, - __meta: [{ sourceRange: [356, 381] }], + __meta: [{ sourceRange: [343, 368] }], }, ]) }) diff --git a/src/lang/executor.test.ts b/src/lang/executor.test.ts index 9f08056e3c..3da86f5d22 100644 --- a/src/lang/executor.test.ts +++ b/src/lang/executor.test.ts @@ -43,9 +43,9 @@ const newVar = myVar + 1` it('sketch declaration', async () => { let code = `const mySketch = startSketchOn('XY') |> startProfileAt([0,0], %) - |> lineTo({to: [0,2], tag: "myPath"}, %) + |> lineTo([0,2], %, "myPath") |> lineTo([2,3], %) - |> lineTo({ to: [5,-1], tag: "rightPath" }, %) + |> lineTo([5,-1], %, "rightPath") // |> close(%) ` const { root } = await exe(code) @@ -57,7 +57,7 @@ const newVar = myVar + 1` to: [0, 2], from: [0, 0], __geoMeta: { - sourceRange: [72, 109], + sourceRange: [72, 98], id: expect.any(String), }, name: 'myPath', @@ -68,7 +68,7 @@ const newVar = myVar + 1` from: [0, 2], name: '', __geoMeta: { - sourceRange: [115, 131], + sourceRange: [104, 120], id: expect.any(String), }, }, @@ -77,7 +77,7 @@ const newVar = myVar + 1` to: [5, -1], from: [2, 3], __geoMeta: { - sourceRange: [137, 180], + sourceRange: [126, 156], id: expect.any(String), }, name: 'rightPath', @@ -99,7 +99,7 @@ const newVar = myVar + 1` // const code = [ // 'const mySk1 = startSketchAt([0,0])', // ' |> lineTo([1,1], %)', - // ' |> lineTo({to: [0, 1], tag: "myPath"}, %)', + // ' |> lineTo([0, 1], %, "myPath")', // ' |> lineTo([1, 1], %)', // 'const rotated = rx(90, mySk1)', // ].join('\n') @@ -126,7 +126,7 @@ const newVar = myVar + 1` "const mySk1 = startSketchOn('XY')", ' |> startProfileAt([0,0], %)', ' |> lineTo([1,1], %)', - ' |> lineTo({to: [0, 1], tag: "myPath"}, %)', + ' |> lineTo([0, 1], %, "myPath")', ' |> lineTo([1,1], %)', // ' |> rx(90, %)', ].join('\n') @@ -159,7 +159,7 @@ const newVar = myVar + 1` to: [0, 1], from: [1, 1], __geoMeta: { - sourceRange: [91, 129], + sourceRange: [91, 118], id: expect.any(String), }, name: 'myPath', @@ -170,7 +170,7 @@ const newVar = myVar + 1` from: [0, 1], name: '', __geoMeta: { - sourceRange: [135, 151], + sourceRange: [124, 140], id: expect.any(String), }, }, @@ -341,7 +341,7 @@ describe('testing math operators', () => { `const myVar = 3`, `const part001 = startSketchOn('XY')`, ` |> startProfileAt([0, 0], %)`, - ` |> line({ to: [3, 4], tag: 'seg01' }, %)`, + ` |> line([3, 4], %, 'seg01')`, ` |> line([`, ` min(segLen('seg01', %), myVar),`, ` -legLen(segLen('seg01', %), myVar)`, diff --git a/src/lang/getNodePathFromSourceRange.test.ts b/src/lang/getNodePathFromSourceRange.test.ts index c37cf30044..4c0ac56cf4 100644 --- a/src/lang/getNodePathFromSourceRange.test.ts +++ b/src/lang/getNodePathFromSourceRange.test.ts @@ -9,10 +9,10 @@ describe('testing getNodePathFromSourceRange', () => { const myVar = 5 const sk3 = startSketchAt([0, 0]) |> lineTo([1, 2], %) - |> lineTo({ to: [3, 4], tag: 'yo' }, %) + |> lineTo([3, 4], %, 'yo') |> close(%) ` - const subStr = "lineTo({ to: [3, 4], tag: 'yo' }, %)" + const subStr = "lineTo([3, 4], %, 'yo')" const lineToSubstringIndex = code.indexOf(subStr) const sourceRange: [number, number] = [ lineToSubstringIndex, diff --git a/src/lang/modifyAst.test.ts b/src/lang/modifyAst.test.ts index 5ae8464d67..314e3b1bd6 100644 --- a/src/lang/modifyAst.test.ts +++ b/src/lang/modifyAst.test.ts @@ -152,25 +152,25 @@ describe('Testing giveSketchFnCallTag', () => { code, 'line([0, 0.83], %)' ) - expect(newCode).toContain("line({ to: [0, 0.83], tag: 'seg01' }, %)") + expect(newCode).toContain("line([0, 0.83], %, 'seg01')") expect(tag).toBe('seg01') expect(isTagExisting).toBe(false) }) it('Should create a unique tag if seg01 already exists', () => { let _code = code.replace( 'line([-2.57, -0.13], %)', - "line({ to: [-2.57, -0.13], tag: 'seg01' }, %)" + "line([-2.57, -0.13], %, 'seg01')" ) const { newCode, tag, isTagExisting } = giveSketchFnCallTagTestHelper( _code, 'line([0, 0.83], %)' ) - expect(newCode).toContain("line({ to: [0, 0.83], tag: 'seg02' }, %)") + expect(newCode).toContain("line([0, 0.83], %, 'seg02')") expect(tag).toBe('seg02') expect(isTagExisting).toBe(false) }) it('Should return existing tag if it already exists', () => { - const lineButWithTag = "line({ to: [-2.57, -0.13], tag: 'butts' }, %)" + const lineButWithTag = "line([-2.57, -0.13], %, 'butts')" let _code = code.replace('line([-2.57, -0.13], %)', lineButWithTag) const { newCode, tag, isTagExisting } = giveSketchFnCallTagTestHelper( _code, diff --git a/src/lang/modifyAst.ts b/src/lang/modifyAst.ts index efb8d23167..88f3004743 100644 --- a/src/lang/modifyAst.ts +++ b/src/lang/modifyAst.ts @@ -23,11 +23,7 @@ import { getNodePathFromSourceRange, isNodeSafeToReplace, } from './queryAst' -import { - addTagForSketchOnFace, - getFirstArg, - createFirstArg, -} from './std/sketch' +import { addTagForSketchOnFace } from './std/sketch' import { isLiteralArrayOrStatic } from './std/sketchcombos' import { DefaultPlaneStr } from 'clientSideScene/sceneEntities' import { roundOff } from 'lib/utils' @@ -606,22 +602,25 @@ export function giveSketchFnCallTag( path, 'CallExpression' ) - const firstArg = getFirstArg(primaryCallExp) - const isTagExisting = !!firstArg.tag - const tagValue = (firstArg.tag || - createLiteral(tag || findUniqueName(ast, 'seg', 2))) as Literal - const tagStr = String(tagValue.value) - const newFirstArg = createFirstArg( - primaryCallExp.callee.name as ToolTip, - firstArg.val, - tagValue - ) - primaryCallExp.arguments[0] = newFirstArg - return { - modifiedAst: ast, - tag: tagStr, - isTagExisting, - pathToNode: path, + // Tag is always 3rd expression now, using arg index feels brittle + // but we can come up with a better way to identify tag later. + const thirdArg = primaryCallExp.arguments?.[2] + const tagLiteral = + thirdArg || (createLiteral(tag || findUniqueName(ast, 'seg', 2)) as Literal) + const isTagExisting = !!thirdArg + if (!isTagExisting) { + primaryCallExp.arguments[2] = tagLiteral + } + if ('value' in tagLiteral) { + // Now TypeScript knows tagLiteral has a value property + return { + modifiedAst: ast, + tag: String(tagLiteral.value), + isTagExisting, + pathToNode: path, + } + } else { + throw new Error('Unable to assign tag without value') } } diff --git a/src/lang/queryAst.test.ts b/src/lang/queryAst.test.ts index 7792e4f190..110c24c8a5 100644 --- a/src/lang/queryAst.test.ts +++ b/src/lang/queryAst.test.ts @@ -250,7 +250,7 @@ describe('testing doesPipeHave', () => { it('finds close', () => { const exampleCode = `const length001 = 2 const part001 = startSketchAt([-1.41, 3.46]) - |> line({ to: [19.49, 1.16], tag: 'seg01' }, %) + |> line([19.49, 1.16], %, 'seg01') |> angledLine([-35, length001], %) |> line([-3.22, -7.36], %) |> angledLine([-175, segLen('seg01', %)], %) @@ -267,7 +267,7 @@ const part001 = startSketchAt([-1.41, 3.46]) it('finds extrude', () => { const exampleCode = `const length001 = 2 const part001 = startSketchAt([-1.41, 3.46]) - |> line({ to: [19.49, 1.16], tag: 'seg01' }, %) + |> line([19.49, 1.16], %, 'seg01') |> angledLine([-35, length001], %) |> line([-3.22, -7.36], %) |> angledLine([-175, segLen('seg01', %)], %) @@ -285,7 +285,7 @@ const part001 = startSketchAt([-1.41, 3.46]) it('does NOT find close', () => { const exampleCode = `const length001 = 2 const part001 = startSketchAt([-1.41, 3.46]) - |> line({ to: [19.49, 1.16], tag: 'seg01' }, %) + |> line([19.49, 1.16], %, 'seg01') |> angledLine([-35, length001], %) |> line([-3.22, -7.36], %) |> angledLine([-175, segLen('seg01', %)], %) @@ -314,7 +314,7 @@ describe('testing hasExtrudeSketchGroup', () => { it('find sketch group', async () => { const exampleCode = `const length001 = 2 const part001 = startSketchAt([-1.41, 3.46]) - |> line({ to: [19.49, 1.16], tag: 'seg01' }, %) + |> line([19.49, 1.16], %, 'seg01') |> angledLine([-35, length001], %) |> line([-3.22, -7.36], %) |> angledLine([-175, segLen('seg01', %)], %)` @@ -330,7 +330,7 @@ const part001 = startSketchAt([-1.41, 3.46]) it('find extrude group', async () => { const exampleCode = `const length001 = 2 const part001 = startSketchAt([-1.41, 3.46]) - |> line({ to: [19.49, 1.16], tag: 'seg01' }, %) + |> line([19.49, 1.16], %, 'seg01') |> angledLine([-35, length001], %) |> line([-3.22, -7.36], %) |> angledLine([-175, segLen('seg01', %)], %) diff --git a/src/lang/recast.test.ts b/src/lang/recast.test.ts index 358a6716bb..c924de64f6 100644 --- a/src/lang/recast.test.ts +++ b/src/lang/recast.test.ts @@ -64,9 +64,9 @@ log(5, myVar) }) it('recast sketch declaration', () => { let code = `const mySketch = startSketchAt([0, 0]) - |> lineTo({ to: [0, 1], tag: "myPath" }, %) + |> lineTo([0, 1], %, "myPath") |> lineTo([1, 1], %) - |> lineTo({ to: [1, 0], tag: "rightPath" }, %) + |> lineTo([1, 0], %, "rightPath") |> close(%) ` const { ast } = code2ast(code) @@ -77,7 +77,7 @@ log(5, myVar) const code = [ 'const mySk1 = startSketchAt([0, 0])', ' |> lineTo([1, 1], %)', - ' |> lineTo({ to: [0, 1], tag: "myTag" }, %)', + ' |> lineTo([0, 1], %, "myTag")', ' |> lineTo([1, 1], %)', ' |> rx(90, %)', ].join('\n') @@ -237,7 +237,7 @@ const key = 'c' const code = [ 'const mySk1 = startSketchAt([0, 0])', ' |> lineTo([1, 1], %)', - ' |> lineTo({ to: [0, 1], tag: "myTag" }, %)', + ' |> lineTo([0, 1], %, "myTag")', ' |> lineTo([1, 1], %)', ' // a comment', ' |> rx(90, %)', @@ -253,7 +253,7 @@ const key = 'c' const mySk1 = startSketchAt([0, 0]) |> lineTo([1, 1], %) // comment here - |> lineTo({ to: [0, 1], tag: 'myTag' }, %) + |> lineTo([0, 1], %, 'myTag') |> lineTo([1, 1], %) /* and here */ @@ -275,7 +275,7 @@ const mySk1 = startSketchAt([0, 0]) const mySk1 = startSketchAt([0, 0]) |> lineTo([1, 1], %) // comment here - |> lineTo({ to: [0, 1], tag: 'myTag' }, %) + |> lineTo([0, 1], %, 'myTag') |> lineTo([1, 1], %) /* and here */ // a comment between pipe expression statements @@ -321,7 +321,7 @@ describe('testing call Expressions in BinaryExpressions and UnaryExpressions', ( describe('it recasts wrapped object expressions in pipe bodies with correct indentation', () => { it('with a single line', () => { const code = `const part001 = startSketchAt([-0.01, -0.08]) - |> line({ to: [0.62, 4.15], tag: 'seg01' }, %) + |> line([0.62, 4.15], %, 'seg01') |> line([2.77, -1.24], %) |> angledLineThatIntersects({ angle: 201, diff --git a/src/lang/std/sketch.test.ts b/src/lang/std/sketch.test.ts index dc47ea32b9..dbee9375d9 100644 --- a/src/lang/std/sketch.test.ts +++ b/src/lang/std/sketch.test.ts @@ -206,9 +206,7 @@ describe('testing addTagForSketchOnFace', () => { }, 'lineTo' ) - const expectedCode = genCode( - "lineTo({ to: [-1.59, -1.54], tag: 'seg01' }, %)" - ) + const expectedCode = genCode("lineTo([-1.59, -1.54], %, 'seg01')") expect(recast(modifiedAst)).toBe(expectedCode) }) }) diff --git a/src/lang/std/sketch.ts b/src/lang/std/sketch.ts index c0b1e1b963..48cc3f16af 100644 --- a/src/lang/std/sketch.ts +++ b/src/lang/std/sketch.ts @@ -53,40 +53,34 @@ export function getCoordsFromPaths(skGroup: SketchGroup, index = 0): Coords2d { export function createFirstArg( sketchFn: ToolTip, - val: Value | [Value, Value] | [Value, Value, Value], - tag?: Value + val: Value | [Value, Value] | [Value, Value, Value] ): Value { - if (!tag) { - if (Array.isArray(val)) { - return createArrayExpression(val) - } - return val - } if (Array.isArray(val)) { - if (['line', 'lineTo'].includes(sketchFn)) - return createObjectExpression({ to: createArrayExpression(val), tag }) if ( - ['angledLine', 'angledLineOfXLength', 'angledLineOfYLength'].includes( - sketchFn - ) + [ + 'angledLine', + 'angledLineOfXLength', + 'angledLineOfYLength', + 'angledLineToX', + 'angledLineToY', + 'line', + 'lineTo', + ].includes(sketchFn) ) - return createObjectExpression({ angle: val[0], length: val[1], tag }) - if (['angledLineToX', 'angledLineToY'].includes(sketchFn)) - return createObjectExpression({ angle: val[0], to: val[1], tag }) + return createArrayExpression(val) if (['angledLineThatIntersects'].includes(sketchFn) && val[2]) return createObjectExpression({ angle: val[0], offset: val[1], intersectTag: val[2], - tag, }) } else { - if (['xLine', 'yLine'].includes(sketchFn)) - return createObjectExpression({ length: val, tag }) - if (['xLineTo', 'yLineTo'].includes(sketchFn)) - return createObjectExpression({ to: val, tag }) - if (['startSketchAt'].includes(sketchFn)) - return createObjectExpression({ to: val, tag }) + if ( + ['startSketchAt', 'xLine', 'xLineTo', 'yLine', 'yLineTo'].includes( + sketchFn + ) + ) + return val } throw new Error('all sketch line types should have been covered') } @@ -1190,67 +1184,20 @@ function addTagWithTo( _node, pathToNode ) - const firstArg = callExpression.arguments?.[0] - if (firstArg.type === 'ObjectExpression') { - const existingTagName = firstArg.properties?.find( - (prop) => prop.key.name === 'tag' - ) - if (!existingTagName) { - mutateObjExpProp( - callExpression.arguments?.[0], - createLiteral(tagName), - 'tag' - ) - } else { - tagName = `${(existingTagName.value as Literal).value}` - } - return { - modifiedAst: _node, - tag: tagName, - } - } - if (firstArg.type === 'ArrayExpression') { - const objExp = - argType === 'default' - ? createObjectExpression({ - to: firstArg, - tag: createLiteral(tagName), - }) - : argType === 'angleLength' - ? createObjectExpression({ - angle: firstArg.elements[0], - length: firstArg.elements[1], - tag: createLiteral(tagName), - }) - : createObjectExpression({ - angle: firstArg.elements[0], - to: firstArg.elements[1], - tag: createLiteral(tagName), - }) - callExpression.arguments[0] = objExp + const tagArg = callExpression.arguments?.[2] + if (tagArg) { return { modifiedAst: _node, - tag: tagName, + tag: String(tagArg), } - } - if (firstArg.type === 'Literal') { - const objExp = - argType === 'length' - ? createObjectExpression({ - length: firstArg, - tag: createLiteral(tagName), - }) - : createObjectExpression({ - to: firstArg, - tag: createLiteral(tagName), - }) - callExpression.arguments[0] = objExp + } else { + callExpression.arguments[2] = createLiteral(tagName) + return { modifiedAst: _node, tag: tagName, } } - throw new Error('lineTo must be called with an object or array') } } diff --git a/src/lang/std/sketchConstraints.test.ts b/src/lang/std/sketchConstraints.test.ts index a3d57094d5..b5eb8a09b5 100644 --- a/src/lang/std/sketchConstraints.test.ts +++ b/src/lang/std/sketchConstraints.test.ts @@ -54,29 +54,17 @@ describe('testing swapping out sketch calls with xLine/xLineTo', () => { const bigExampleArr = [ `const part001 = startSketchOn('XY')`, ` |> startProfileAt([0, 0], %)`, - ` |> lineTo({ to: [1, 1], tag: 'abc1' }, %)`, - ` |> line({ to: [-2.04, -0.7], tag: 'abc2' }, %)`, - ` |> angledLine({`, - ` angle: 157,`, - ` length: 1.69,`, - ` tag: 'abc3'`, - ` }, %)`, - ` |> angledLineOfXLength({`, - ` angle: 217,`, - ` length: 0.86,`, - ` tag: 'abc4'`, - ` }, %)`, - ` |> angledLineOfYLength({`, - ` angle: 104,`, - ` length: 1.58,`, - ` tag: 'abc5'`, - ` }, %)`, - ` |> angledLineToX({ angle: 55, to: -2.89, tag: 'abc6' }, %)`, - ` |> angledLineToY({ angle: 330, to: 2.53, tag: 'abc7' }, %)`, - ` |> xLine({ length: 1.47, tag: 'abc8' }, %)`, - ` |> yLine({ length: 1.57, tag: 'abc9' }, %)`, - ` |> xLineTo({ to: 1.49, tag: 'abc10' }, %)`, - ` |> yLineTo({ to: 2.64, tag: 'abc11' }, %)`, + ` |> lineTo([1, 1], %, 'abc1')`, + ` |> line([-2.04, -0.7], %, 'abc2')`, + ` |> angledLine({ angle: 157, length: 1.69 }, %, 'abc3')`, + ` |> angledLineOfXLength({ angle: 217, length: 0.86 }, %, 'abc4')`, + ` |> angledLineOfYLength({ angle: 104, length: 1.58 }, %, 'abc5')`, + ` |> angledLineToX({ angle: 55, to: -2.89 }, %, 'abc6')`, + ` |> angledLineToY({ angle: 330, to: 2.53 }, %, 'abc7')`, + ` |> xLine(1.47, %, 'abc8')`, + ` |> yLine(1.57, %, 'abc9')`, + ` |> xLineTo(1.49, %, 'abc10')`, + ` |> yLineTo(2.64, %, 'abc11')`, ` |> lineTo([2.55, 3.58], %) // lineTo`, ` |> line([0.73, -0.75], %)`, ` |> angledLine([63, 1.38], %) // angledLine`, @@ -91,8 +79,8 @@ describe('testing swapping out sketch calls with xLine/xLineTo', () => { ] const bigExample = bigExampleArr.join('\n') it('line with tag converts to xLine', async () => { - const callToSwap = "line({ to: [-2.04, -0.7], tag: 'abc2' }, %)" - const expectedLine = "xLine({ length: -2.04, tag: 'abc2' }, %)" + const callToSwap = "line([-2.04, -0.7], %, 'abc2')" + const expectedLine = "xLine(-2.04, %, 'abc2')" const { newCode, originalRange } = await testingSwapSketchFnCall({ inputCode: bigExample, callToSwap, @@ -117,10 +105,10 @@ describe('testing swapping out sketch calls with xLine/xLineTo', () => { it('lineTo with tag converts to xLineTo', async () => { const { newCode, originalRange } = await testingSwapSketchFnCall({ inputCode: bigExample, - callToSwap: "lineTo({ to: [1, 1], tag: 'abc1' }, %)", + callToSwap: "lineTo([1, 1], %, 'abc1')", constraintType: 'horizontal', }) - const expectedLine = "xLineTo({ to: 1, tag: 'abc1' }, %)" + const expectedLine = "xLineTo(1, %, 'abc1')" expect(newCode).toContain(expectedLine) // new line should start at the same place as the old line expect(originalRange[0]).toBe(newCode.indexOf(expectedLine)) @@ -139,16 +127,11 @@ describe('testing swapping out sketch calls with xLine/xLineTo', () => { it('angledLine with tag converts to xLine', async () => { const { newCode, originalRange } = await testingSwapSketchFnCall({ inputCode: bigExample, - callToSwap: [ - `angledLine({`, - ` angle: 157,`, - ` length: 1.69,`, - ` tag: 'abc3'`, - ` }, %)`, - ].join('\n'), + callToSwap: "angledLine({ angle: 157, length: 1.69 }, %, 'abc3')", constraintType: 'horizontal', }) - const expectedLine = "xLine({ length: -1.56, tag: 'abc3' }, %)" + const expectedLine = "xLine(-1.56, %, 'abc3')" + console.log(newCode) expect(newCode).toContain(expectedLine) // new line should start at the same place as the old line expect(originalRange[0]).toBe(newCode.indexOf(expectedLine)) @@ -167,16 +150,11 @@ describe('testing swapping out sketch calls with xLine/xLineTo', () => { it('angledLineOfXLength with tag converts to xLine', async () => { const { newCode, originalRange } = await testingSwapSketchFnCall({ inputCode: bigExample, - callToSwap: [ - `angledLineOfXLength({`, - ` angle: 217,`, - ` length: 0.86,`, - ` tag: 'abc4'`, - ` }, %)`, - ].join('\n'), + callToSwap: + "angledLineOfXLength({ angle: 217, length: 0.86 }, %, 'abc4')", constraintType: 'horizontal', }) - const expectedLine = "xLine({ length: -0.86, tag: 'abc4' }, %)" + const expectedLine = "xLine(-0.86, %, 'abc4')" // hmm "-0.86" is correct since the angle is 104, but need to make sure this is compatible `-myVar` expect(newCode).toContain(expectedLine) // new line should start at the same place as the old line @@ -196,16 +174,11 @@ describe('testing swapping out sketch calls with xLine/xLineTo', () => { it('angledLineOfYLength with tag converts to yLine', async () => { const { newCode, originalRange } = await testingSwapSketchFnCall({ inputCode: bigExample, - callToSwap: [ - `angledLineOfYLength({`, - ` angle: 104,`, - ` length: 1.58,`, - ` tag: 'abc5'`, - ` }, %)`, - ].join('\n'), + callToSwap: + "angledLineOfYLength({ angle: 104, length: 1.58 }, %, 'abc5')", constraintType: 'vertical', }) - const expectedLine = "yLine({ length: 1.58, tag: 'abc5' }, %)" + const expectedLine = "yLine(1.58, %, 'abc5')" expect(newCode).toContain(expectedLine) // new line should start at the same place as the old line expect(originalRange[0]).toBe(newCode.indexOf(expectedLine)) @@ -224,10 +197,10 @@ describe('testing swapping out sketch calls with xLine/xLineTo', () => { it('angledLineToX with tag converts to xLineTo', async () => { const { newCode, originalRange } = await testingSwapSketchFnCall({ inputCode: bigExample, - callToSwap: "angledLineToX({ angle: 55, to: -2.89, tag: 'abc6' }, %)", + callToSwap: "angledLineToX({ angle: 55, to: -2.89 }, %, 'abc6')", constraintType: 'horizontal', }) - const expectedLine = "xLineTo({ to: -2.89, tag: 'abc6' }, %)" + const expectedLine = "xLineTo(-2.89, %, 'abc6')" expect(newCode).toContain(expectedLine) // new line should start at the same place as the old line expect(originalRange[0]).toBe(newCode.indexOf(expectedLine)) @@ -246,10 +219,10 @@ describe('testing swapping out sketch calls with xLine/xLineTo', () => { it('angledLineToY with tag converts to yLineTo', async () => { const { newCode, originalRange } = await testingSwapSketchFnCall({ inputCode: bigExample, - callToSwap: "angledLineToY({ angle: 330, to: 2.53, tag: 'abc7' }, %)", + callToSwap: "angledLineToY({ angle: 330, to: 2.53 }, %, 'abc7')", constraintType: 'vertical', }) - const expectedLine = "yLineTo({ to: 2.53, tag: 'abc7' }, %)" + const expectedLine = "yLineTo(2.53, %, 'abc7')" expect(newCode).toContain(expectedLine) // new line should start at the same place as the old line expect(originalRange[0]).toBe(newCode.indexOf(expectedLine)) diff --git a/src/lang/std/sketchcombos.test.ts b/src/lang/std/sketchcombos.test.ts index d9e76124b1..71d9acee8d 100644 --- a/src/lang/std/sketchcombos.test.ts +++ b/src/lang/std/sketchcombos.test.ts @@ -131,7 +131,7 @@ const myAng = 40 const myAng2 = 134 const part001 = startSketchOn('XY') |> startProfileAt([0, 0], %) - |> line({ to: [1, 3.82], tag: 'seg01' }, %) // ln-should-get-tag + |> line([1, 3.82], %, 'seg01') // ln-should-get-tag |> angledLineToX([ -angleToMatchLengthX('seg01', myVar, %), myVar @@ -485,8 +485,7 @@ const part001 = startSketchOn('XY') |> angledLine({ angle: halfArmAngle, length: 2.45, - tag: 'seg01bing' -}, %) // partial +}, %, 'seg01bing') // partial |> xLine(4.4, %) // partial |> yLine(-1, %) // partial |> xLine(-4.2 + 0, %) // full diff --git a/src/lang/std/sketchcombos.ts b/src/lang/std/sketchcombos.ts index efa2727fb5..b1cb6e44e9 100644 --- a/src/lang/std/sketchcombos.ts +++ b/src/lang/std/sketchcombos.ts @@ -60,11 +60,12 @@ function createCallWrapper( tag?: Value, valueUsedInTransform?: number ): ReturnType { + const args = [createFirstArg(a, val), createPipeSubstitution()] + if (tag) { + args.push(tag) + } return { - callExp: createCallExpression(a, [ - createFirstArg(a, val, tag), - createPipeSubstitution(), - ]), + callExp: createCallExpression(a, args), valueUsedInTransform, } } @@ -89,14 +90,15 @@ function intersectCallWrapper({ offset: offsetVal, intersectTag, } + const args: Value[] = [ + createObjectExpression(firstArg), + createPipeSubstitution(), + ] if (tag) { - firstArg['tag'] = tag + args.push(tag) } return { - callExp: createCallExpression(fnName, [ - createObjectExpression(firstArg), - createPipeSubstitution(), - ]), + callExp: createCallExpression(fnName, args), valueUsedInTransform, } } @@ -1419,7 +1421,8 @@ export function transformAstSketchLines({ const callExp = getNode('CallExpression')?.node const varDec = getNode('VariableDeclarator').node - const { val, tag: callBackTag } = getFirstArg(callExp) + const { val } = getFirstArg(callExp) + const callBackTag = callExp.arguments[2] const _referencedSegmentNameVal = callExp.arguments[0]?.type === 'ObjectExpression' && callExp.arguments[0].properties?.find( diff --git a/src/lang/std/std.test.ts b/src/lang/std/std.test.ts index 92d5fabb7f..fcc337d836 100644 --- a/src/lang/std/std.test.ts +++ b/src/lang/std/std.test.ts @@ -7,14 +7,13 @@ describe('testing angledLineThatIntersects', () => { it('angledLineThatIntersects should intersect with another line', async () => { const code = (offset: string) => `const part001 = startSketchOn('XY') |> startProfileAt([0, 0], %) - |> lineTo({to:[2, 2], tag: "yo"}, %) + |> lineTo([2, 2], %, "yo") |> lineTo([3, 1], %) |> angledLineThatIntersects({ angle: 180, intersectTag: 'yo', offset: ${offset}, - tag: "yo2" -}, %) +}, %, "yo2") const intersect = segEndX('yo2', part001)` const { root } = await enginelessExecutor(parse(code('-1'))) expect(root.intersect.value).toBe(1 + Math.sqrt(2)) diff --git a/src/wasm-lib/kcl/src/ast/types.rs b/src/wasm-lib/kcl/src/ast/types.rs index cd112db706..1fb568c0e3 100644 --- a/src/wasm-lib/kcl/src/ast/types.rs +++ b/src/wasm-lib/kcl/src/ast/types.rs @@ -3351,7 +3351,7 @@ const mySk1 = startSketchOn('XY') |> startProfileAt([0, 0], %) |> lineTo([1, 1], %) // comment here - |> lineTo({ to: [0, 1], tag: 'myTag' }, %) + |> lineTo([0, 1], %, 'myTag') |> lineTo([1, 1], %) /* and here @@ -3374,7 +3374,7 @@ const mySk1 = startSketchOn('XY') |> startProfileAt([0, 0], %) |> lineTo([1, 1], %) // comment here - |> lineTo({ to: [0, 1], tag: 'myTag' }, %) + |> lineTo([0, 1], %, 'myTag') |> lineTo([1, 1], %) /* and here */ @@ -3392,7 +3392,7 @@ const mySk1 = startSketchOn('XY') fn test_recast_multiline_object() { let some_program_string = r#"const part001 = startSketchOn('XY') |> startProfileAt([-0.01, -0.08], %) - |> line({ to: [0.62, 4.15], tag: 'seg01' }, %) + |> line([0.62, 4.15], %, 'seg01') |> line([2.77, -1.24], %) |> angledLineThatIntersects({ angle: 201, @@ -3482,7 +3482,7 @@ const myAng = 40 const myAng2 = 134 const part001 = startSketchOn('XY') |> startProfileAt([0, 0], %) - |> line({ to: [1, 3.82], tag: 'seg01' }, %) // ln-should-get-tag + |> line([1, 3.82], %, 'seg01') // ln-should-get-tag |> angledLineToX([ -angleToMatchLengthX('seg01', myVar, %), myVar @@ -3508,7 +3508,7 @@ const myAng = 40 const myAng2 = 134 const part001 = startSketchOn('XY') |> startProfileAt([0, 0], %) - |> line({ to: [1, 3.82], tag: 'seg01' }, %) // ln-should-get-tag + |> line([1, 3.82], %, 'seg01') // ln-should-get-tag |> angledLineToX([ -angleToMatchLengthX('seg01', myVar, %), myVar diff --git a/src/wasm-lib/kcl/src/executor.rs b/src/wasm-lib/kcl/src/executor.rs index edc2a32946..e0d4c94932 100644 --- a/src/wasm-lib/kcl/src/executor.rs +++ b/src/wasm-lib/kcl/src/executor.rs @@ -1323,14 +1323,13 @@ const newVar = myVar + 1"#; format!( r#"const part001 = startSketchOn('XY') |> startProfileAt([0, 0], %) - |> lineTo({{to:[2, 2], tag: "yo"}}, %) + |> lineTo([2, 2], %, "yo") |> lineTo([3, 1], %) |> angledLineThatIntersects({{ angle: 180, intersectTag: 'yo', offset: {}, - tag: "yo2" -}}, %) +}}, %, 'yo2') const intersect = segEndX('yo2', part001)"#, offset ) @@ -1387,7 +1386,7 @@ const yo2 = hmm([identifierGuy + 5])"#; let ast = r#"const myVar = 3 const part001 = startSketchOn('XY') |> startProfileAt([0, 0], %) - |> line({ to: [3, 4], tag: 'seg01' }, %) + |> line([3, 4], %, 'seg01') |> line([ min(segLen('seg01', %), myVar), -legLen(segLen('seg01', %), myVar) @@ -1402,7 +1401,7 @@ const part001 = startSketchOn('XY') let ast = r#"const myVar = 3 const part001 = startSketchOn('XY') |> startProfileAt([0, 0], %) - |> line({ to: [3, 4], tag: 'seg01' }, %) + |> line([3, 4], %, 'seg01') |> line([ min(segLen('seg01', %), myVar), legLen(segLen('seg01', %), myVar) diff --git a/src/wasm-lib/kcl/src/parser/parser_impl.rs b/src/wasm-lib/kcl/src/parser/parser_impl.rs index b823d20cc3..b19ad8ab57 100644 --- a/src/wasm-lib/kcl/src/parser/parser_impl.rs +++ b/src/wasm-lib/kcl/src/parser/parser_impl.rs @@ -2903,9 +2903,9 @@ mod snapshot_tests { snapshot_test!( af, r#"const mySketch = startSketchAt([0,0]) - |> lineTo({ to: [0, 1], tag: 'myPath' }, %) + |> lineTo([0, 1], %, 'myPath') |> lineTo([1, 1], %) - |> lineTo({ to: [1,0], tag: "rightPath" }, %) + |> lineTo([1, 0], %, 'rightPath') |> close(%)"# ); snapshot_test!( diff --git a/src/wasm-lib/kcl/src/parser/snapshots/kcl_lib__parser__parser_impl__snapshot_tests__af.snap b/src/wasm-lib/kcl/src/parser/snapshots/kcl_lib__parser__parser_impl__snapshot_tests__af.snap index 2e06b6fb56..a539ab0f29 100644 --- a/src/wasm-lib/kcl/src/parser/snapshots/kcl_lib__parser__parser_impl__snapshot_tests__af.snap +++ b/src/wasm-lib/kcl/src/parser/snapshots/kcl_lib__parser__parser_impl__snapshot_tests__af.snap @@ -4,18 +4,18 @@ expression: actual --- { "start": 0, - "end": 192, + "end": 167, "body": [ { "type": "VariableDeclaration", "type": "VariableDeclaration", "start": 0, - "end": 192, + "end": 167, "declarations": [ { "type": "VariableDeclarator", "start": 6, - "end": 192, + "end": 167, "id": { "type": "Identifier", "start": 6, @@ -26,7 +26,7 @@ expression: actual "type": "PipeExpression", "type": "PipeExpression", "start": 17, - "end": 192, + "end": 167, "body": [ { "type": "CallExpression", @@ -71,7 +71,7 @@ expression: actual "type": "CallExpression", "type": "CallExpression", "start": 49, - "end": 89, + "end": 76, "callee": { "type": "Identifier", "start": 49, @@ -80,72 +80,42 @@ expression: actual }, "arguments": [ { - "type": "ObjectExpression", - "type": "ObjectExpression", + "type": "ArrayExpression", + "type": "ArrayExpression", "start": 56, - "end": 85, - "properties": [ + "end": 62, + "elements": [ { - "type": "ObjectProperty", - "start": 58, - "end": 68, - "key": { - "type": "Identifier", - "start": 58, - "end": 60, - "name": "to" - }, - "value": { - "type": "ArrayExpression", - "type": "ArrayExpression", - "start": 62, - "end": 68, - "elements": [ - { - "type": "Literal", - "type": "Literal", - "start": 63, - "end": 64, - "value": 0, - "raw": "0" - }, - { - "type": "Literal", - "type": "Literal", - "start": 66, - "end": 67, - "value": 1, - "raw": "1" - } - ] - } + "type": "Literal", + "type": "Literal", + "start": 57, + "end": 58, + "value": 0, + "raw": "0" }, { - "type": "ObjectProperty", - "start": 70, - "end": 83, - "key": { - "type": "Identifier", - "start": 70, - "end": 73, - "name": "tag" - }, - "value": { - "type": "Literal", - "type": "Literal", - "start": 75, - "end": 83, - "value": "myPath", - "raw": "'myPath'" - } + "type": "Literal", + "type": "Literal", + "start": 60, + "end": 61, + "value": 1, + "raw": "1" } ] }, { "type": "PipeSubstitution", "type": "PipeSubstitution", - "start": 87, - "end": 88 + "start": 64, + "end": 65 + }, + { + "type": "Literal", + "type": "Literal", + "start": 67, + "end": 75, + "value": "myPath", + "raw": "'myPath'" } ], "optional": false @@ -153,34 +123,34 @@ expression: actual { "type": "CallExpression", "type": "CallExpression", - "start": 101, - "end": 118, + "start": 88, + "end": 105, "callee": { "type": "Identifier", - "start": 101, - "end": 107, + "start": 88, + "end": 94, "name": "lineTo" }, "arguments": [ { "type": "ArrayExpression", "type": "ArrayExpression", - "start": 108, - "end": 114, + "start": 95, + "end": 101, "elements": [ { "type": "Literal", "type": "Literal", - "start": 109, - "end": 110, + "start": 96, + "end": 97, "value": 1, "raw": "1" }, { "type": "Literal", "type": "Literal", - "start": 112, - "end": 113, + "start": 99, + "end": 100, "value": 1, "raw": "1" } @@ -189,8 +159,8 @@ expression: actual { "type": "PipeSubstitution", "type": "PipeSubstitution", - "start": 116, - "end": 117 + "start": 103, + "end": 104 } ], "optional": false @@ -198,82 +168,52 @@ expression: actual { "type": "CallExpression", "type": "CallExpression", - "start": 130, - "end": 172, + "start": 117, + "end": 147, "callee": { "type": "Identifier", - "start": 130, - "end": 136, + "start": 117, + "end": 123, "name": "lineTo" }, "arguments": [ { - "type": "ObjectExpression", - "type": "ObjectExpression", - "start": 137, - "end": 168, - "properties": [ + "type": "ArrayExpression", + "type": "ArrayExpression", + "start": 124, + "end": 130, + "elements": [ { - "type": "ObjectProperty", - "start": 139, - "end": 148, - "key": { - "type": "Identifier", - "start": 139, - "end": 141, - "name": "to" - }, - "value": { - "type": "ArrayExpression", - "type": "ArrayExpression", - "start": 143, - "end": 148, - "elements": [ - { - "type": "Literal", - "type": "Literal", - "start": 144, - "end": 145, - "value": 1, - "raw": "1" - }, - { - "type": "Literal", - "type": "Literal", - "start": 146, - "end": 147, - "value": 0, - "raw": "0" - } - ] - } + "type": "Literal", + "type": "Literal", + "start": 125, + "end": 126, + "value": 1, + "raw": "1" }, { - "type": "ObjectProperty", - "start": 150, - "end": 166, - "key": { - "type": "Identifier", - "start": 150, - "end": 153, - "name": "tag" - }, - "value": { - "type": "Literal", - "type": "Literal", - "start": 155, - "end": 166, - "value": "rightPath", - "raw": "\"rightPath\"" - } + "type": "Literal", + "type": "Literal", + "start": 128, + "end": 129, + "value": 0, + "raw": "0" } ] }, { "type": "PipeSubstitution", "type": "PipeSubstitution", - "start": 170, - "end": 171 + "start": 132, + "end": 133 + }, + { + "type": "Literal", + "type": "Literal", + "start": 135, + "end": 146, + "value": "rightPath", + "raw": "'rightPath'" } ], "optional": false @@ -281,20 +221,20 @@ expression: actual { "type": "CallExpression", "type": "CallExpression", - "start": 184, - "end": 192, + "start": 159, + "end": 167, "callee": { "type": "Identifier", - "start": 184, - "end": 189, + "start": 159, + "end": 164, "name": "close" }, "arguments": [ { "type": "PipeSubstitution", "type": "PipeSubstitution", - "start": 190, - "end": 191 + "start": 165, + "end": 166 } ], "optional": false diff --git a/src/wasm-lib/kcl/src/std/extrude.rs b/src/wasm-lib/kcl/src/std/extrude.rs index eb798efb3d..d2c19e7035 100644 --- a/src/wasm-lib/kcl/src/std/extrude.rs +++ b/src/wasm-lib/kcl/src/std/extrude.rs @@ -196,7 +196,7 @@ pub async fn get_extrude_wall_transform(args: Args) -> Result startProfileAt([0, 0], %) /// |> line([0, 10], %) /// |> line([10, 0], %) -/// |> line({to: [0, -10], tag: "surface"}, %) +/// |> line([0, -10], %, "surface") /// |> close(%) /// |> extrude(5, %) /// diff --git a/src/wasm-lib/kcl/src/std/fillet.rs b/src/wasm-lib/kcl/src/std/fillet.rs index 9ee3a3ace0..971933d74e 100644 --- a/src/wasm-lib/kcl/src/std/fillet.rs +++ b/src/wasm-lib/kcl/src/std/fillet.rs @@ -48,9 +48,9 @@ pub async fn fillet(args: Args) -> Result { /// ```no_run /// const part001 = startSketchOn('XY') /// |> startProfileAt([0,0], %) -/// |> line({to: [0, 10], tag: "thing"}, %) +/// |> line([0, 10], %, "thing") /// |> line([10, 0], %) -/// |> line({to: [0, -10], tag: "thing2"}, %) +/// |> line([0, -10], %, "thing2") /// |> close(%) /// |> extrude(10, %) /// |> fillet({radius: 2, tags: ["thing", "thing2"]}, %) @@ -130,9 +130,9 @@ pub async fn get_opposite_edge(args: Args) -> Result { /// ```no_run /// const part001 = startSketchOn('XY') /// |> startProfileAt([0,0], %) -/// |> line({to: [0, 10], tag: "thing"}, %) +/// |> line([0, 10], %, "thing") /// |> line([10, 0], %) -/// |> line({to: [0, -10], tag: "thing2"}, %) +/// |> line([0, -10], %, "thing2") /// |> close(%) /// |> extrude(10, %) /// |> fillet({radius: 2, tags: ["thing", getOppositeEdge("thing", %)]}, %) @@ -199,9 +199,9 @@ pub async fn get_next_adjacent_edge(args: Args) -> Result /// ```no_run /// const part001 = startSketchOn('XY') /// |> startProfileAt([0,0], %) -/// |> line({to: [0, 10], tag: "thing"}, %) -/// |> line({to: [10, 0], tag: "thing1"}, %) -/// |> line({to: [0, -10], tag: "thing2"}, %) +/// |> line([0, 10], %, "thing") +/// |> line([10, 0], %, "thing1") +/// |> line([0, -10], %, "thing2") /// |> close(%) /// |> extrude(10, %) /// |> fillet({radius: 2, tags: [getNextAdjacentEdge("thing", %)]}, %) @@ -277,9 +277,9 @@ pub async fn get_previous_adjacent_edge(args: Args) -> Result startProfileAt([0,0], %) -/// |> line({to: [0, 10], tag: "thing"}, %) -/// |> line({to: [10, 0], tag: "thing1"}, %) -/// |> line({to: [0, -10], tag: "thing2"}, %) +/// |> line([0, 10], %, "thing") +/// |> line([10, 0], %, "thing1") +/// |> line([0, -10], %, "thing2") /// |> close(%) /// |> extrude(10, %) /// |> fillet({radius: 2, tags: [getPreviousAdjacentEdge("thing2", %)]}, %) diff --git a/src/wasm-lib/kcl/src/std/mod.rs b/src/wasm-lib/kcl/src/std/mod.rs index 9759f484aa..81fbd9948a 100644 --- a/src/wasm-lib/kcl/src/std/mod.rs +++ b/src/wasm-lib/kcl/src/std/mod.rs @@ -622,7 +622,54 @@ impl Args { Ok((data, sketch_group)) } - fn get_data_and_sketch_surface(&self) -> Result<(T, SketchSurface), KclError> { + fn get_data_and_sketch_group_and_tag( + &self, + ) -> Result<(T, Box, Option), KclError> { + let first_value = self + .args + .first() + .ok_or_else(|| { + KclError::Type(KclErrorDetails { + message: format!("Expected a struct as the first argument, found `{:?}`", self.args), + source_ranges: vec![self.source_range], + }) + })? + .get_json_value()?; + + let data: T = serde_json::from_value(first_value).map_err(|e| { + KclError::Type(KclErrorDetails { + message: format!("Failed to deserialize struct from JSON: {}", e), + source_ranges: vec![self.source_range], + }) + })?; + + let second_value = self.args.get(1).ok_or_else(|| { + KclError::Type(KclErrorDetails { + message: format!("Expected a SketchGroup as the second argument, found `{:?}`", self.args), + source_ranges: vec![self.source_range], + }) + })?; + + let sketch_group = if let MemoryItem::SketchGroup(sg) = second_value { + sg.clone() + } else { + return Err(KclError::Type(KclErrorDetails { + message: format!("Expected a SketchGroup as the second argument, found `{:?}`", self.args), + source_ranges: vec![self.source_range], + })); + }; + let tag = if let Some(tag) = self.args.get(2) { + tag.get_json_opt()? + } else { + None + }; + + Ok((data, sketch_group, tag)) + } + + fn get_data_and_sketch_surface( + &self, + ) -> Result<(T, SketchSurface, Option), KclError> { let first_value = self .args .first() @@ -661,8 +708,13 @@ impl Args { source_ranges: vec![self.source_range], })); }; + let tag = if let Some(tag) = self.args.get(2) { + tag.get_json_opt()? + } else { + None + }; - Ok((data, sketch_surface)) + Ok((data, sketch_surface, tag)) } fn get_data_and_extrude_group(&self) -> Result<(T, Box), KclError> { diff --git a/src/wasm-lib/kcl/src/std/segment.rs b/src/wasm-lib/kcl/src/std/segment.rs index abf260525c..afbcf2b2fa 100644 --- a/src/wasm-lib/kcl/src/std/segment.rs +++ b/src/wasm-lib/kcl/src/std/segment.rs @@ -24,7 +24,7 @@ pub async fn segment_end_x(args: Args) -> Result { /// ```no_run /// startSketchOn("YZ") /// |> startProfileAt([0, 0], %) -/// |> line({ to: [5, 0], tag: "thing" }, %) +/// |> line([5, 0], %, "thing") /// |> line([5, 5], %) /// |> line([segEndX("thing", %), 5], %) /// |> close(%) @@ -60,7 +60,7 @@ pub async fn segment_end_y(args: Args) -> Result { /// ```no_run /// startSketchOn("YZ") /// |> startProfileAt([0, 0], %) -/// |> line({ to: [5, 0], tag: "thing" }, %) +/// |> line([5, 0], %, "thing") /// |> line([5, 5], %) /// |> line([segEndY("thing", %), 5], %) /// |> close(%) @@ -96,7 +96,7 @@ pub async fn last_segment_x(args: Args) -> Result { /// ```no_run /// startSketchOn("YZ") /// |> startProfileAt([0, 0], %) -/// |> line({ to: [5, 0], tag: "thing" }, %) +/// |> line([5, 0], %, "thing") /// |> line([5, 5], %) /// |> line([0, lastSegX(%)], %) /// |> close(%) @@ -136,7 +136,7 @@ pub async fn last_segment_y(args: Args) -> Result { /// ```no_run /// startSketchOn("YZ") /// |> startProfileAt([0, 0], %) -/// |> line({ to: [5, 0], tag: "thing" }, %) +/// |> line([5, 0], %, "thing") /// |> line([5, 5], %) /// |> line([0, lastSegY(%)], %) /// |> close(%) @@ -175,7 +175,7 @@ pub async fn segment_length(args: Args) -> Result { /// ```no_run /// startSketchOn("YZ") /// |> startProfileAt([0, 0], %) -/// |> line({ to: [5, 0], tag: "thing" }, %) +/// |> line([5, 0], %, "thing") /// |> line([5, 5], %) /// |> line([0, segLen("thing", %)], %) /// |> close(%) @@ -215,7 +215,7 @@ pub async fn segment_angle(args: Args) -> Result { /// const part001 = startSketchOn('XY') /// |> startProfileAt([4.83, 12.56], %) /// |> line([15.1, 2.48], %) -/// |> line({ to: [3.15, -9.85], tag: 'seg01' }, %) +/// |> line([3.15, -9.85], %, 'seg01') /// |> line([-15.17, -4.1], %) /// |> angledLine([segAng('seg01', %), 12.35], %) /// |> line([-13.02, 10.03], %) @@ -254,7 +254,7 @@ pub async fn angle_to_match_length_x(args: Args) -> Result /// ```no_run /// const part001 = startSketchOn('XY') /// |> startProfileAt([0, 0], %) -/// |> line({ to: [1, 3.82], tag: 'seg01' }, %) +/// |> line([1, 3.82], %, 'seg01') /// |> angledLineToX([ /// -angleToMatchLengthX('seg01', 10, %), /// 5 @@ -320,7 +320,7 @@ pub async fn angle_to_match_length_y(args: Args) -> Result /// ```no_run /// const part001 = startSketchOn('XY') /// |> startProfileAt([0, 0], %) -/// |> line({ to: [1, 3.82], tag: 'seg01' }, %) +/// |> line([1, 3.82], %, 'seg01') /// |> angledLineToX([ /// -angleToMatchLengthY('seg01', 10, %), /// 5 diff --git a/src/wasm-lib/kcl/src/std/shapes.rs b/src/wasm-lib/kcl/src/std/shapes.rs index 2c1b015c53..6f7902abb7 100644 --- a/src/wasm-lib/kcl/src/std/shapes.rs +++ b/src/wasm-lib/kcl/src/std/shapes.rs @@ -58,12 +58,9 @@ async fn inner_circle( SketchSurfaceOrGroup::SketchSurface(surface) => surface, SketchSurfaceOrGroup::SketchGroup(group) => group.on, }; - let mut sketch_group = crate::std::sketch::inner_start_profile_at( - crate::std::sketch::LineData::Point([center[0] + radius, center[1]]), - sketch_surface, - args.clone(), - ) - .await?; + let mut sketch_group = + crate::std::sketch::inner_start_profile_at([center[0] + radius, center[1]], sketch_surface, None, args.clone()) + .await?; // Call arc. sketch_group = crate::std::sketch::inner_arc( @@ -71,9 +68,9 @@ async fn inner_circle( angle_start: 0.0, angle_end: 360.0, radius, - tag, }, sketch_group, + tag, args.clone(), ) .await?; diff --git a/src/wasm-lib/kcl/src/std/sketch.rs b/src/wasm-lib/kcl/src/std/sketch.rs index 24ff6e5d5a..52f766db7d 100644 --- a/src/wasm-lib/kcl/src/std/sketch.rs +++ b/src/wasm-lib/kcl/src/std/sketch.rs @@ -23,27 +23,12 @@ use crate::{ }, }; -/// Data to draw a line to a point. -#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS, JsonSchema)] -#[ts(export)] -#[serde(rename_all = "camelCase", untagged)] -pub enum LineToData { - /// A point with a tag. - PointWithTag { - /// The to point. - to: [f64; 2], - /// The tag. - tag: String, - }, - /// A point. - Point([f64; 2]), -} - /// Draw a line to a point. pub async fn line_to(args: Args) -> Result { - let (data, sketch_group): (LineToData, Box) = args.get_data_and_sketch_group()?; + let (to, sketch_group, tag): ([f64; 2], Box, Option) = + args.get_data_and_sketch_group_and_tag()?; - let new_sketch_group = inner_line_to(data, sketch_group, args).await?; + let new_sketch_group = inner_line_to(to, sketch_group, tag, args).await?; Ok(MemoryItem::SketchGroup(new_sketch_group)) } @@ -53,18 +38,9 @@ pub async fn line_to(args: Args) -> Result { /// fn rectShape = (pos, w, l) => { /// const rr = startSketchOn('YZ') /// |> startProfileAt([pos[0] - (w / 2), pos[1] - (l / 2)], %) -/// |> lineTo({ -/// to: [pos[0] + w / 2, pos[1] - (l / 2)], -/// tag: "edge1" -/// }, %) -/// |> lineTo({ -/// to: [pos[0] + w / 2, pos[1] + l / 2], -/// tag: "edge2" -/// }, %) -/// |> lineTo({ -/// to: [pos[0] - (w / 2), pos[1] + l / 2], -/// tag: "edge3" -/// }, %) +/// |> lineTo([pos[0] + w / 2, pos[1] - (l / 2)], %, "edge1") +/// |> lineTo([pos[0] + w / 2, pos[1] + l / 2], %, "edge2") +/// |> lineTo([pos[0] - (w / 2), pos[1] + l / 2], %, "edge3") /// |> close(%, "edge4") /// return rr /// } @@ -76,16 +52,12 @@ pub async fn line_to(args: Args) -> Result { name = "lineTo", }] async fn inner_line_to( - data: LineToData, + to: [f64; 2], sketch_group: Box, + tag: Option, args: Args, ) -> Result, KclError> { let from = sketch_group.get_coords_from_paths()?; - let to = match data { - LineToData::PointWithTag { to, .. } => to, - LineToData::Point(to) => to, - }; - let id = uuid::Uuid::new_v4(); args.send_modeling_cmd( @@ -108,11 +80,7 @@ async fn inner_line_to( base: BasePath { from: from.into(), to, - name: if let LineToData::PointWithTag { tag, .. } = data { - tag.to_string() - } else { - "".to_string() - }, + name: tag.unwrap_or("".to_string()), geo_meta: GeoMeta { id, metadata: args.source_range.into(), @@ -126,27 +94,11 @@ async fn inner_line_to( Ok(new_sketch_group) } -/// Data to draw a line to a point on an axis. -#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS, JsonSchema)] -#[ts(export)] -#[serde(rename_all = "camelCase", untagged)] -pub enum AxisLineToData { - /// A point with a tag. - PointWithTag { - /// The to point. - to: f64, - /// The tag. - tag: String, - }, - /// A point. - Point(f64), -} - /// Draw a line to a point on the x-axis. pub async fn x_line_to(args: Args) -> Result { - let (data, sketch_group): (AxisLineToData, Box) = args.get_data_and_sketch_group()?; + let (to, sketch_group, tag): (f64, Box, Option) = args.get_data_and_sketch_group_and_tag()?; - let new_sketch_group = inner_x_line_to(data, sketch_group, args).await?; + let new_sketch_group = inner_x_line_to(to, sketch_group, tag, args).await?; Ok(MemoryItem::SketchGroup(new_sketch_group)) } @@ -155,10 +107,7 @@ pub async fn x_line_to(args: Args) -> Result { /// ```no_run /// startSketchOn('XY') /// |> startProfileAt([0, 0], %) -/// |> xLineTo({ -/// to: 10, -/// tag: "edge1" -/// }, %) +/// |> xLineTo(10, %, "edge1") /// |> line([10, 10], %) /// |> close(%, "edge2") /// |> extrude(10, %) @@ -167,27 +116,23 @@ pub async fn x_line_to(args: Args) -> Result { name = "xLineTo", }] async fn inner_x_line_to( - data: AxisLineToData, + to: f64, sketch_group: Box, + tag: Option, args: Args, ) -> Result, KclError> { let from = sketch_group.get_coords_from_paths()?; - let line_to_data = match data { - AxisLineToData::PointWithTag { to, tag } => LineToData::PointWithTag { to: [to, from.y], tag }, - AxisLineToData::Point(data) => LineToData::Point([data, from.y]), - }; - - let new_sketch_group = inner_line_to(line_to_data, sketch_group, args).await?; + let new_sketch_group = inner_line_to([to, from.y], sketch_group, tag, args).await?; Ok(new_sketch_group) } /// Draw a line to a point on the y-axis. pub async fn y_line_to(args: Args) -> Result { - let (data, sketch_group): (AxisLineToData, Box) = args.get_data_and_sketch_group()?; + let (to, sketch_group, tag): (f64, Box, Option) = args.get_data_and_sketch_group_and_tag()?; - let new_sketch_group = inner_y_line_to(data, sketch_group, args).await?; + let new_sketch_group = inner_y_line_to(to, sketch_group, tag, args).await?; Ok(MemoryItem::SketchGroup(new_sketch_group)) } @@ -196,55 +141,33 @@ pub async fn y_line_to(args: Args) -> Result { /// ```no_run /// startSketchOn('XZ') /// |> startProfileAt([0, 0], %) -/// |> yLineTo({ -/// to: 10, -/// tag: "edge1" -/// }, %) -/// |> line([10, 10], %) -/// |> close(%, "edge2") -/// |> extrude(10, %) -/// |> fillet({radius: 2, tags: ["edge2"]}, %) +/// |> yLineTo(10, %, "edge1") +/// |> line([10, 10], %) +/// |> close(%, "edge2") +/// |> extrude(10, %) +/// |> fillet({radius: 2, tags: ["edge2"]}, %) /// ``` #[stdlib { name = "yLineTo", }] async fn inner_y_line_to( - data: AxisLineToData, + to: f64, sketch_group: Box, + tag: Option, args: Args, ) -> Result, KclError> { let from = sketch_group.get_coords_from_paths()?; - let line_to_data = match data { - AxisLineToData::PointWithTag { to, tag } => LineToData::PointWithTag { to: [from.x, to], tag }, - AxisLineToData::Point(data) => LineToData::Point([from.x, data]), - }; - - let new_sketch_group = inner_line_to(line_to_data, sketch_group, args).await?; + let new_sketch_group = inner_line_to([from.x, to], sketch_group, tag, args).await?; Ok(new_sketch_group) } -/// Data to draw a line. -#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS, JsonSchema)] -#[ts(export)] -#[serde(rename_all = "camelCase", untagged)] -pub enum LineData { - /// A point with a tag. - PointWithTag { - /// The to point. - to: [f64; 2], - /// The tag. - tag: String, - }, - /// A point. - Point([f64; 2]), -} - /// Draw a line. pub async fn line(args: Args) -> Result { - let (data, sketch_group): (LineData, Box) = args.get_data_and_sketch_group()?; + let (delta, sketch_group, tag): ([f64; 2], Box, Option) = + args.get_data_and_sketch_group_and_tag()?; - let new_sketch_group = inner_line(data, sketch_group, args).await?; + let new_sketch_group = inner_line(delta, sketch_group, tag, args).await?; Ok(MemoryItem::SketchGroup(new_sketch_group)) } @@ -254,22 +177,21 @@ pub async fn line(args: Args) -> Result { /// startSketchOn('-XY') /// |> startProfileAt([0, 0], %) /// |> line([10, 10], %) -/// |> line({to: [20, 10], tag: "edge1"}, %) +/// |> line([20, 10], %, "edge1") /// |> close(%, "edge2") /// |> extrude(10, %) /// ``` #[stdlib { name = "line", }] -async fn inner_line(data: LineData, sketch_group: Box, args: Args) -> Result, KclError> { +async fn inner_line( + delta: [f64; 2], + sketch_group: Box, + tag: Option, + args: Args, +) -> Result, KclError> { let from = sketch_group.get_coords_from_paths()?; - let inner_args = match &data { - LineData::PointWithTag { to, .. } => *to, - LineData::Point(to) => *to, - }; - - let delta = inner_args; - let to = [from.x + inner_args[0], from.y + inner_args[1]]; + let to = [from.x + delta[0], from.y + delta[1]]; let id = uuid::Uuid::new_v4(); @@ -293,11 +215,7 @@ async fn inner_line(data: LineData, sketch_group: Box, args: Args) base: BasePath { from: from.into(), to, - name: if let LineData::PointWithTag { tag, .. } = data { - tag.to_string() - } else { - "".to_string() - }, + name: tag.unwrap_or("".to_string()), geo_meta: GeoMeta { id, metadata: args.source_range.into(), @@ -311,27 +229,12 @@ async fn inner_line(data: LineData, sketch_group: Box, args: Args) Ok(new_sketch_group) } -/// Data to draw a line on an axis. -#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS, JsonSchema)] -#[ts(export)] -#[serde(rename_all = "camelCase", untagged)] -pub enum AxisLineData { - /// The length with a tag. - LengthWithTag { - /// The length of the line. - length: f64, - /// The tag. - tag: String, - }, - /// The length. - Length(f64), -} - /// Draw a line on the x-axis. pub async fn x_line(args: Args) -> Result { - let (data, sketch_group): (AxisLineData, Box) = args.get_data_and_sketch_group()?; + let (length, sketch_group, tag): (f64, Box, Option) = + args.get_data_and_sketch_group_and_tag()?; - let new_sketch_group = inner_x_line(data, sketch_group, args).await?; + let new_sketch_group = inner_x_line(length, sketch_group, tag, args).await?; Ok(MemoryItem::SketchGroup(new_sketch_group)) } @@ -349,24 +252,20 @@ pub async fn x_line(args: Args) -> Result { name = "xLine", }] async fn inner_x_line( - data: AxisLineData, + length: f64, sketch_group: Box, + tag: Option, args: Args, ) -> Result, KclError> { - let line_data = match data { - AxisLineData::LengthWithTag { length, tag } => LineData::PointWithTag { to: [length, 0.0], tag }, - AxisLineData::Length(length) => LineData::Point([length, 0.0]), - }; - - let new_sketch_group = inner_line(line_data, sketch_group, args).await?; - Ok(new_sketch_group) + inner_line([length, 0.0], sketch_group, tag, args).await } /// Draw a line on the y-axis. pub async fn y_line(args: Args) -> Result { - let (data, sketch_group): (AxisLineData, Box) = args.get_data_and_sketch_group()?; + let (length, sketch_group, tag): (f64, Box, Option) = + args.get_data_and_sketch_group_and_tag()?; - let new_sketch_group = inner_y_line(data, sketch_group, args).await?; + let new_sketch_group = inner_y_line(length, sketch_group, tag, args).await?; Ok(MemoryItem::SketchGroup(new_sketch_group)) } @@ -384,17 +283,12 @@ pub async fn y_line(args: Args) -> Result { name = "yLine", }] async fn inner_y_line( - data: AxisLineData, + length: f64, sketch_group: Box, + tag: Option, args: Args, ) -> Result, KclError> { - let line_data = match data { - AxisLineData::LengthWithTag { length, tag } => LineData::PointWithTag { to: [0.0, length], tag }, - AxisLineData::Length(length) => LineData::Point([0.0, length]), - }; - - let new_sketch_group = inner_line(line_data, sketch_group, args).await?; - Ok(new_sketch_group) + inner_line([0.0, length], sketch_group, tag, args).await } /// Data to draw an angled line. @@ -402,34 +296,23 @@ async fn inner_y_line( #[ts(export)] #[serde(rename_all = "camelCase", untagged)] pub enum AngledLineData { - /// An angle and length with a tag. - AngleWithTag { + /// An angle and length with explicitly named parameters + AngleAndLengthNamed { /// The angle of the line. angle: f64, /// The length of the line. length: f64, - /// The tag. - tag: String, }, - /// An angle and length. - AngleAndLength([f64; 2]), -} - -impl AngledLineData { - pub fn into_inner_line(self, to: [f64; 2]) -> LineData { - if let AngledLineData::AngleWithTag { tag, .. } = self { - LineData::PointWithTag { to, tag } - } else { - LineData::Point(to) - } - } + /// An angle and length given as a pair + AngleAndLengthPair([f64; 2]), } /// Draw an angled line. pub async fn angled_line(args: Args) -> Result { - let (data, sketch_group): (AngledLineData, Box) = args.get_data_and_sketch_group()?; + let (data, sketch_group, tag): (AngledLineData, Box, Option) = + args.get_data_and_sketch_group_and_tag()?; - let new_sketch_group = inner_angled_line(data, sketch_group, args).await?; + let new_sketch_group = inner_angled_line(data, sketch_group, tag, args).await?; Ok(MemoryItem::SketchGroup(new_sketch_group)) } @@ -437,12 +320,11 @@ pub async fn angled_line(args: Args) -> Result { /// /// ```no_run /// startSketchOn('XY') -/// |> startProfileAt([0, 0], %) -/// |> angledLine({ -/// angle: 45, -/// length: 10, -/// tag: "edge1" -/// }, %) +/// |> startProfileAt([0, 0], %) +/// |> angledLine({ +/// angle: 45, +/// length: 10, +/// }, %, "edge1") /// |> line([10, 10], %) /// |> line([0, 10], %) /// |> close(%, "edge2") @@ -454,12 +336,13 @@ pub async fn angled_line(args: Args) -> Result { async fn inner_angled_line( data: AngledLineData, sketch_group: Box, + tag: Option, args: Args, ) -> Result, KclError> { let from = sketch_group.get_coords_from_paths()?; - let (angle, length) = match &data { - AngledLineData::AngleWithTag { angle, length, .. } => (*angle, *length), - AngledLineData::AngleAndLength(angle_and_length) => (angle_and_length[0], angle_and_length[1]), + let (angle, length) = match data { + AngledLineData::AngleAndLengthNamed { angle, length } => (angle, length), + AngledLineData::AngleAndLengthPair(pair) => (pair[0], pair[1]), }; //double check me on this one - mike @@ -477,11 +360,7 @@ async fn inner_angled_line( base: BasePath { from: from.into(), to, - name: if let AngledLineData::AngleWithTag { tag, .. } = data { - tag.to_string() - } else { - "".to_string() - }, + name: tag.unwrap_or("".to_string()), geo_meta: GeoMeta { id, metadata: args.source_range.into(), @@ -512,9 +391,10 @@ async fn inner_angled_line( /// Draw an angled line of a given x length. pub async fn angled_line_of_x_length(args: Args) -> Result { - let (data, sketch_group): (AngledLineData, Box) = args.get_data_and_sketch_group()?; + let (data, sketch_group, tag): (AngledLineData, Box, Option) = + args.get_data_and_sketch_group_and_tag()?; - let new_sketch_group = inner_angled_line_of_x_length(data, sketch_group, args).await?; + let new_sketch_group = inner_angled_line_of_x_length(data, sketch_group, tag, args).await?; Ok(MemoryItem::SketchGroup(new_sketch_group)) } @@ -522,16 +402,15 @@ pub async fn angled_line_of_x_length(args: Args) -> Result /// /// ```no_run /// startSketchOn('XZ') -/// |> startProfileAt([0, 0], %) -/// |> angledLineOfXLength({ -/// angle: 45, -/// length: 10, -/// tag: "edge1" -/// }, %) -/// |> line([10, 10], %) -/// |> line([0, 10], %) -/// |> close(%, "edge2") -/// |> extrude(10, %) +/// |> startProfileAt([0, 0], %) +/// |> angledLineOfXLength({ +/// angle: 45, +/// length: 10, +/// }, %, "edge1") +/// |> line([10, 10], %) +/// |> line([0, 10], %) +/// |> close(%, "edge2") +/// |> extrude(10, %) /// ``` #[stdlib { name = "angledLineOfXLength", @@ -539,16 +418,17 @@ pub async fn angled_line_of_x_length(args: Args) -> Result async fn inner_angled_line_of_x_length( data: AngledLineData, sketch_group: Box, + tag: Option, args: Args, ) -> Result, KclError> { - let (angle, length) = match &data { - AngledLineData::AngleWithTag { angle, length, .. } => (*angle, *length), - AngledLineData::AngleAndLength(angle_and_length) => (angle_and_length[0], angle_and_length[1]), + let (angle, length) = match data { + AngledLineData::AngleAndLengthNamed { angle, length } => (angle, length), + AngledLineData::AngleAndLengthPair(pair) => (pair[0], pair[1]), }; let to = get_y_component(Angle::from_degrees(angle), length); - let new_sketch_group = inner_line(data.into_inner_line(to.into()), sketch_group, args).await?; + let new_sketch_group = inner_line(to.into(), sketch_group, tag, args).await?; Ok(new_sketch_group) } @@ -556,36 +436,20 @@ async fn inner_angled_line_of_x_length( /// Data to draw an angled line to a point. #[derive(Debug, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS, JsonSchema)] #[ts(export)] -#[serde(rename_all = "camelCase", untagged)] -pub enum AngledLineToData { - /// An angle and point with a tag. - AngleWithTag { - /// The angle of the line. - angle: f64, - /// The point to draw to. - to: f64, - /// The tag. - tag: String, - }, - /// An angle and point to draw to. - AngleAndPoint([f64; 2]), -} - -impl AngledLineToData { - pub fn into_inner_line(self, x_to: f64, y_to: f64) -> LineToData { - if let AngledLineToData::AngleWithTag { tag, .. } = self { - LineToData::PointWithTag { to: [x_to, y_to], tag } - } else { - LineToData::Point([x_to, y_to]) - } - } +#[serde(rename_all = "camelCase")] +pub struct AngledLineToData { + /// The angle of the line. + angle: f64, + /// The point to draw to. + to: f64, } /// Draw an angled line to a given x coordinate. pub async fn angled_line_to_x(args: Args) -> Result { - let (data, sketch_group): (AngledLineToData, Box) = args.get_data_and_sketch_group()?; + let (data, sketch_group, tag): (AngledLineToData, Box, Option) = + args.get_data_and_sketch_group_and_tag()?; - let new_sketch_group = inner_angled_line_to_x(data, sketch_group, args).await?; + let new_sketch_group = inner_angled_line_to_x(data, sketch_group, tag, args).await?; Ok(MemoryItem::SketchGroup(new_sketch_group)) } @@ -593,17 +457,16 @@ pub async fn angled_line_to_x(args: Args) -> Result { /// /// ```no_run /// startSketchOn('XY') -/// |> startProfileAt([0, 0], %) -/// |> angledLineToX({ -/// angle: 45, -/// to: 10, -/// tag: "edge1" -/// }, %) -/// |> line([10, 10], %) -/// |> line([0, 10], %) -/// |> close(%, "edge2") -/// |> extrude(10, %) -/// |> fillet({radius: 2, tags: ["edge1"]}, %) +/// |> startProfileAt([0, 0], %) +/// |> angledLineToX({ +/// angle: 45, +/// to: 10, +/// }, %, "edge1") +/// |> line([10, 10], %) +/// |> line([0, 10], %) +/// |> close(%, "edge2") +/// |> extrude(10, %) +/// |> fillet({radius: 2, tags: ["edge1"]}, %) /// ``` #[stdlib { name = "angledLineToX", @@ -611,27 +474,26 @@ pub async fn angled_line_to_x(args: Args) -> Result { async fn inner_angled_line_to_x( data: AngledLineToData, sketch_group: Box, + tag: Option, args: Args, ) -> Result, KclError> { let from = sketch_group.get_coords_from_paths()?; - let (angle, x_to) = match &data { - AngledLineToData::AngleWithTag { angle, to, .. } => (*angle, *to), - AngledLineToData::AngleAndPoint(angle_and_to) => (angle_and_to[0], angle_and_to[1]), - }; + let AngledLineToData { angle, to: x_to } = data; let x_component = x_to - from.x; let y_component = x_component * f64::tan(angle.to_radians()); let y_to = from.y + y_component; - let new_sketch_group = inner_line_to(data.into_inner_line(x_to, y_to), sketch_group, args).await?; + let new_sketch_group = inner_line_to([x_to, y_to], sketch_group, tag, args).await?; Ok(new_sketch_group) } /// Draw an angled line of a given y length. pub async fn angled_line_of_y_length(args: Args) -> Result { - let (data, sketch_group): (AngledLineData, Box) = args.get_data_and_sketch_group()?; + let (data, sketch_group, tag): (AngledLineData, Box, Option) = + args.get_data_and_sketch_group_and_tag()?; - let new_sketch_group = inner_angled_line_of_y_length(data, sketch_group, args).await?; + let new_sketch_group = inner_angled_line_of_y_length(data, sketch_group, tag, args).await?; Ok(MemoryItem::SketchGroup(new_sketch_group)) } @@ -640,12 +502,11 @@ pub async fn angled_line_of_y_length(args: Args) -> Result /// /// ```no_run /// startSketchOn('YZ') -/// |> startProfileAt([0, 0], %) -/// |> angledLineOfYLength({ -/// angle: 45, -/// length: 10, -/// tag: "edge1" -/// }, %) +/// |> startProfileAt([0, 0], %) +/// |> angledLineOfYLength({ +/// angle: 45, +/// length: 10, +/// }, %, "edge1") /// |> line([10, 10], %) /// |> line([0, 10], %) /// |> close(%, "edge2") @@ -658,25 +519,27 @@ pub async fn angled_line_of_y_length(args: Args) -> Result async fn inner_angled_line_of_y_length( data: AngledLineData, sketch_group: Box, + tag: Option, args: Args, ) -> Result, KclError> { - let (angle, length) = match &data { - AngledLineData::AngleWithTag { angle, length, .. } => (*angle, *length), - AngledLineData::AngleAndLength(angle_and_length) => (angle_and_length[0], angle_and_length[1]), + let (angle, length) = match data { + AngledLineData::AngleAndLengthNamed { angle, length } => (angle, length), + AngledLineData::AngleAndLengthPair(pair) => (pair[0], pair[1]), }; let to = get_x_component(Angle::from_degrees(angle), length); - let new_sketch_group = inner_line(data.into_inner_line(to.into()), sketch_group, args).await?; + let new_sketch_group = inner_line(to.into(), sketch_group, tag, args).await?; Ok(new_sketch_group) } /// Draw an angled line to a given y coordinate. pub async fn angled_line_to_y(args: Args) -> Result { - let (data, sketch_group): (AngledLineToData, Box) = args.get_data_and_sketch_group()?; + let (data, sketch_group, tag): (AngledLineToData, Box, Option) = + args.get_data_and_sketch_group_and_tag()?; - let new_sketch_group = inner_angled_line_to_y(data, sketch_group, args).await?; + let new_sketch_group = inner_angled_line_to_y(data, sketch_group, tag, args).await?; Ok(MemoryItem::SketchGroup(new_sketch_group)) } @@ -684,16 +547,15 @@ pub async fn angled_line_to_y(args: Args) -> Result { /// /// ```no_run /// startSketchOn('XY') -/// |> startProfileAt([0, 0], %) -/// |> angledLineToY({ -/// angle: 45, -/// to: 10, -/// tag: "edge1" -/// }, %) -/// |> line([10, 10], %) -/// |> line([0, 10], %) -/// |> close(%, "edge2") -/// |> extrude(10, %) +/// |> startProfileAt([0, 0], %) +/// |> angledLineToY({ +/// angle: 45, +/// to: 10, +/// }, %, "edge1") +/// |> line([10, 10], %) +/// |> line([0, 10], %) +/// |> close(%, "edge2") +/// |> extrude(10, %) /// ``` #[stdlib { name = "angledLineToY", @@ -701,19 +563,17 @@ pub async fn angled_line_to_y(args: Args) -> Result { async fn inner_angled_line_to_y( data: AngledLineToData, sketch_group: Box, + tag: Option, args: Args, ) -> Result, KclError> { let from = sketch_group.get_coords_from_paths()?; - let (angle, y_to) = match &data { - AngledLineToData::AngleWithTag { angle, to, .. } => (*angle, *to), - AngledLineToData::AngleAndPoint(angle_and_to) => (angle_and_to[0], angle_and_to[1]), - }; + let AngledLineToData { angle, to: y_to } = data; let y_component = y_to - from.y; let x_component = y_component / f64::tan(angle.to_radians()); let x_to = from.x + x_component; - let new_sketch_group = inner_line_to(data.into_inner_line(x_to, y_to), sketch_group, args).await?; + let new_sketch_group = inner_line_to([x_to, y_to], sketch_group, tag, args).await?; Ok(new_sketch_group) } @@ -729,14 +589,13 @@ pub struct AngledLineThatIntersectsData { pub intersect_tag: String, /// The offset from the intersecting line. pub offset: Option, - /// The tag. - pub tag: Option, } /// Draw an angled line that intersects with a given line. pub async fn angled_line_that_intersects(args: Args) -> Result { - let (data, sketch_group): (AngledLineThatIntersectsData, Box) = args.get_data_and_sketch_group()?; - let new_sketch_group = inner_angled_line_that_intersects(data, sketch_group, args).await?; + let (data, sketch_group, tag): (AngledLineThatIntersectsData, Box, Option) = + args.get_data_and_sketch_group_and_tag()?; + let new_sketch_group = inner_angled_line_that_intersects(data, sketch_group, tag, args).await?; Ok(MemoryItem::SketchGroup(new_sketch_group)) } @@ -744,18 +603,17 @@ pub async fn angled_line_that_intersects(args: Args) -> Result startProfileAt([0, 0], %) -/// |> lineTo({to:[2, 2], tag: "yo"}, %) -/// |> lineTo([3, 1], %) -/// |> angledLineThatIntersects({ -/// angle: 180, -/// intersectTag: 'yo', -/// offset: 12, -/// tag: "yo2" -/// }, %) -/// |> line([4, 0], %) -/// |> close(%, "yo3") -/// |> extrude(10, %) +/// |> startProfileAt([0, 0], %) +/// |> lineTo([2, 2], %, "yo") +/// |> lineTo([3, 1], %) +/// |> angledLineThatIntersects({ +/// angle: 180, +/// intersectTag: 'yo', +/// offset: 12, +/// }, %, "yo2") +/// |> line([4, 0], %) +/// |> close(%, "yo3") +/// |> extrude(10, %) /// ``` #[stdlib { name = "angledLineThatIntersects", @@ -763,6 +621,7 @@ pub async fn angled_line_that_intersects(args: Args) -> Result, + tag: Option, args: Args, ) -> Result, KclError> { let intersect_path = sketch_group @@ -786,19 +645,13 @@ async fn inner_angled_line_that_intersects( from, ); - let line_to_data = if let Some(tag) = data.tag { - LineToData::PointWithTag { to: to.into(), tag } - } else { - LineToData::Point(to.into()) - }; - - let new_sketch_group = inner_line_to(line_to_data, sketch_group, args).await?; + let new_sketch_group = inner_line_to(to.into(), sketch_group, tag, args).await?; Ok(new_sketch_group) } /// Start a sketch at a given point. pub async fn start_sketch_at(args: Args) -> Result { - let data: LineData = args.get_data()?; + let data: [f64; 2] = args.get_data()?; let sketch_group = inner_start_sketch_at(data, args).await?; Ok(MemoryItem::SketchGroup(sketch_group)) @@ -813,11 +666,11 @@ pub async fn start_sketch_at(args: Args) -> Result { #[stdlib { name = "startSketchAt", }] -async fn inner_start_sketch_at(data: LineData, args: Args) -> Result, KclError> { +async fn inner_start_sketch_at(data: [f64; 2], args: Args) -> Result, KclError> { // Let's assume it's the XY plane for now, this is just for backwards compatibility. let xy_plane = PlaneData::XY; let sketch_surface = inner_start_sketch_on(SketchData::Plane(xy_plane), None, args.clone()).await?; - let sketch_group = inner_start_profile_at(data, sketch_surface, args).await?; + let sketch_group = inner_start_profile_at(data, sketch_surface, None, args).await?; Ok(sketch_group) } @@ -959,7 +812,7 @@ pub async fn start_sketch_on(args: Args) -> Result { /// startSketchOn('XY') /// |> startProfileAt([0, 0], %) /// |> line([10, 10], %) -/// |> line({to: [20, 10], tag: "edge1"}, %) +/// |> line([20, 10], %, "edge1") /// |> close(%, "edge2") /// ``` /// @@ -981,7 +834,7 @@ pub async fn start_sketch_on(args: Args) -> Result { /// const part001 = startSketchOn(box, "start") /// |> startProfileAt([0, 0], %) /// |> line([10, 10], %) -/// |> line({to: [20, 10], tag: "edge1"}, %) +/// |> line([20, 10], %, "edge1") /// |> close(%) /// |> extrude(20, %) /// ``` @@ -1204,9 +1057,9 @@ async fn start_sketch_on_plane(data: PlaneData, args: Args) -> Result /// Start a profile at a given point. pub async fn start_profile_at(args: Args) -> Result { - let (data, sketch_surface): (LineData, SketchSurface) = args.get_data_and_sketch_surface()?; + let (start, sketch_surface, tag): ([f64; 2], SketchSurface, Option) = args.get_data_and_sketch_surface()?; - let sketch_group = inner_start_profile_at(data, sketch_surface, args).await?; + let sketch_group = inner_start_profile_at(start, sketch_surface, tag, args).await?; Ok(MemoryItem::SketchGroup(sketch_group)) } @@ -1221,15 +1074,11 @@ pub async fn start_profile_at(args: Args) -> Result { name = "startProfileAt", }] pub(crate) async fn inner_start_profile_at( - data: LineData, + to: [f64; 2], sketch_surface: SketchSurface, + tag: Option, args: Args, ) -> Result, KclError> { - let to = match &data { - LineData::PointWithTag { to, .. } => *to, - LineData::Point(to) => *to, - }; - let id = uuid::Uuid::new_v4(); let path_id = uuid::Uuid::new_v4(); @@ -1250,11 +1099,7 @@ pub(crate) async fn inner_start_profile_at( let current_path = BasePath { from: to, to, - name: if let LineData::PointWithTag { tag, .. } = data { - tag.to_string() - } else { - "".to_string() - }, + name: tag.unwrap_or("".to_string()), geo_meta: GeoMeta { id, metadata: args.source_range.into(), @@ -1360,9 +1205,6 @@ pub enum ArcData { angle_end: f64, /// The radius. radius: f64, - /// The tag. - #[serde(default)] - tag: Option, }, /// Center, to and radius with an optional tag. CenterToRadius { @@ -1372,17 +1214,15 @@ pub enum ArcData { to: [f64; 2], /// The radius. radius: f64, - /// The tag. - #[serde(default)] - tag: Option, }, } /// Draw an arc. pub async fn arc(args: Args) -> Result { - let (data, sketch_group): (ArcData, Box) = args.get_data_and_sketch_group()?; + let (data, sketch_group, tag): (ArcData, Box, Option) = + args.get_data_and_sketch_group_and_tag()?; - let new_sketch_group = inner_arc(data, sketch_group, args).await?; + let new_sketch_group = inner_arc(data, sketch_group, tag, args).await?; Ok(MemoryItem::SketchGroup(new_sketch_group)) } @@ -1392,11 +1232,10 @@ pub async fn arc(args: Args) -> Result { /// startSketchOn('-YZ') /// |> startProfileAt([0, 0], %) /// |> arc({ -/// angle_start: 0, -/// angle_end: 360, -/// radius: 10, -/// tag: "edge1" -/// }, %) +/// angle_start: 0, +/// angle_end: 360, +/// radius: 10, +/// }, %, "edge1") /// |> extrude(10, %) /// ``` #[stdlib { @@ -1405,6 +1244,7 @@ pub async fn arc(args: Args) -> Result { pub(crate) async fn inner_arc( data: ArcData, sketch_group: Box, + tag: Option, args: Args, ) -> Result, KclError> { let from: Point2d = sketch_group.get_coords_from_paths()?; @@ -1414,14 +1254,13 @@ pub(crate) async fn inner_arc( angle_start, angle_end, radius, - .. } => { let a_start = Angle::from_degrees(*angle_start); let a_end = Angle::from_degrees(*angle_end); let (center, end) = arc_center_and_end(from, a_start, a_end, *radius); (center, a_start, a_end, *radius, end) } - ArcData::CenterToRadius { center, to, radius, .. } => { + ArcData::CenterToRadius { center, to, radius } => { let (angle_start, angle_end) = arc_angles(from, center.into(), to.into(), *radius, args.source_range)?; (center.into(), angle_start, angle_end, *radius, to.into()) } @@ -1448,10 +1287,7 @@ pub(crate) async fn inner_arc( base: BasePath { from: from.into(), to: end.into(), - name: match data { - ArcData::AnglesAndRadius { tag, .. } => tag.unwrap_or_default().to_string(), - ArcData::CenterToRadius { tag, .. } => tag.unwrap_or_default().to_string(), - }, + name: tag.unwrap_or("".to_string()), geo_meta: GeoMeta { id, metadata: args.source_range.into(), @@ -1477,22 +1313,16 @@ pub enum TangentialArcData { /// Offset of the arc, in degrees. offset: f64, }, - /// A point with a tag. - PointWithTag { - /// 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. - to: [f64; 2], - /// The tag. - tag: String, - }, /// 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. pub async fn tangential_arc(args: Args) -> Result { - let (data, sketch_group): (TangentialArcData, Box) = args.get_data_and_sketch_group()?; + let (data, sketch_group, tag): (TangentialArcData, Box, Option) = + args.get_data_and_sketch_group_and_tag()?; - let new_sketch_group = inner_tangential_arc(data, sketch_group, args).await?; + let new_sketch_group = inner_tangential_arc(data, sketch_group, tag, args).await?; Ok(MemoryItem::SketchGroup(new_sketch_group)) } @@ -1500,13 +1330,12 @@ pub async fn tangential_arc(args: Args) -> Result { /// /// ```no_run /// startSketchOn('-YZ') -/// |> startProfileAt([0, 0], %) -/// |> line({to: [10, 10], tag: "edge0"}, %) -/// |> tangentialArc({ -/// radius: 10, -/// offset: 90, -/// tag: "edge1" -/// }, %) +/// |> startProfileAt([0, 0], %) +/// |> line([10, 10], %, "edge1") +/// |> tangentialArc({ +/// radius: 10, +/// offset: 90, +/// }, %, "edge1") /// |> close(%) /// |> extrude(10, %) /// ``` @@ -1516,6 +1345,7 @@ pub async fn tangential_arc(args: Args) -> Result { async fn inner_tangential_arc( data: TangentialArcData, sketch_group: Box, + tag: Option, args: Args, ) -> Result, KclError> { let from: Point2d = sketch_group.get_coords_from_paths()?; @@ -1545,11 +1375,6 @@ async fn inner_tangential_arc( .await?; to.into() } - TangentialArcData::PointWithTag { to, .. } => { - args.send_modeling_cmd(id, tan_arc_to(&sketch_group, to)).await?; - - *to - } TangentialArcData::Point(to) => { args.send_modeling_cmd(id, tan_arc_to(&sketch_group, to)).await?; @@ -1563,10 +1388,7 @@ async fn inner_tangential_arc( base: BasePath { from: from.into(), to, - name: match data { - TangentialArcData::PointWithTag { tag, .. } => tag.to_string(), - TangentialArcData::Point(_) | TangentialArcData::RadiusAndOffset { .. } => "".to_string(), - }, + name: tag.unwrap_or("".to_string()), geo_meta: GeoMeta { id, metadata: args.source_range.into(), @@ -1628,7 +1450,7 @@ pub async fn tangential_arc_to(args: Args) -> Result { /// ```no_run /// startSketchOn('-YZ') /// |> startProfileAt([0, 0], %) -/// |> line({to: [10, 10], tag: "edge0"}, %) +/// |> line([10, 10], %, "edge0") /// |> tangentialArcTo([10, 0], %) /// |> close(%) /// ``` @@ -1691,15 +1513,14 @@ pub struct BezierData { control1: [f64; 2], /// The second control point. control2: [f64; 2], - /// The tag. - tag: Option, } /// Draw a bezier curve. pub async fn bezier_curve(args: Args) -> Result { - let (data, sketch_group): (BezierData, Box) = args.get_data_and_sketch_group()?; + let (data, sketch_group, tag): (BezierData, Box, Option) = + args.get_data_and_sketch_group_and_tag()?; - let new_sketch_group = inner_bezier_curve(data, sketch_group, args).await?; + let new_sketch_group = inner_bezier_curve(data, sketch_group, tag, args).await?; Ok(MemoryItem::SketchGroup(new_sketch_group)) } @@ -1709,11 +1530,10 @@ pub async fn bezier_curve(args: Args) -> Result { /// startSketchOn('XY') /// |> startProfileAt([0, 0], %) /// |> bezierCurve({ -/// to: [10, 10], -/// control1: [5, 0], -/// control2: [5, 10], -/// tag: "edge1" -/// }, %) +/// to: [10, 10], +/// control1: [5, 0], +/// control2: [5, 10], +/// }, %, "edge1") /// |> close(%) /// |> extrude(10, %) /// ``` @@ -1723,6 +1543,7 @@ pub async fn bezier_curve(args: Args) -> Result { async fn inner_bezier_curve( data: BezierData, sketch_group: Box, + tag: Option, args: Args, ) -> Result, KclError> { let from = sketch_group.get_coords_from_paths()?; @@ -1763,7 +1584,7 @@ async fn inner_bezier_curve( base: BasePath { from: from.into(), to, - name: data.tag.unwrap_or_default().to_string(), + name: tag.unwrap_or_default().to_string(), geo_meta: GeoMeta { id, metadata: args.source_range.into(), @@ -1863,28 +1684,7 @@ mod tests { use pretty_assertions::assert_eq; - use crate::std::sketch::{LineData, PlaneData}; - - #[test] - fn test_deserialize_line_data() { - let data = LineData::Point([0.0, 1.0]); - let mut str_json = serde_json::to_string(&data).unwrap(); - assert_eq!(str_json, "[0.0,1.0]"); - - str_json = "[0, 1]".to_string(); - let data: LineData = serde_json::from_str(&str_json).unwrap(); - assert_eq!(data, LineData::Point([0.0, 1.0])); - - str_json = "{ \"to\": [0.0, 1.0], \"tag\": \"thing\" }".to_string(); - let data: LineData = serde_json::from_str(&str_json).unwrap(); - assert_eq!( - data, - LineData::PointWithTag { - to: [0.0, 1.0], - tag: "thing".to_string() - } - ); - } + use crate::std::sketch::PlaneData; #[test] fn test_deserialize_plane_data() { diff --git a/src/wasm-lib/tests/executor/main.rs b/src/wasm-lib/tests/executor/main.rs index 026c67039b..002aea3532 100644 --- a/src/wasm-lib/tests/executor/main.rs +++ b/src/wasm-lib/tests/executor/main.rs @@ -87,7 +87,7 @@ async fn execute_and_snapshot(code: &str, units: kittycad::types::UnitLength) -> async fn serial_test_sketch_on_face() { let code = r#"const part001 = startSketchOn('XY') |> startProfileAt([11.19, 28.35], %) - |> line({to: [28.67, -13.25], tag: "here"}, %) + |> line([28.67, -13.25], %, "here") |> line([-4.12, -22.81], %) |> line([-33.24, 14.55], %) |> close(%) @@ -206,9 +206,9 @@ const part002 = startSketchOn(part001, "END") async fn serial_test_fillet_duplicate_tags() { let code = r#"const part001 = startSketchOn('XY') |> startProfileAt([0,0], %) - |> line({to: [0, 10], tag: "thing"}, %) + |> line([0, 10], %, "thing") |> line([10, 0], %) - |> line({to: [0, -10], tag: "thing2"}, %) + |> line([0, -10], %, "thing2") |> close(%) |> extrude(10, %) |> fillet({radius: 0.5, tags: ["thing", "thing"]}, %) @@ -218,7 +218,7 @@ async fn serial_test_fillet_duplicate_tags() { assert!(result.is_err()); assert_eq!( result.err().unwrap().to_string(), - r#"type: KclErrorDetails { source_ranges: [SourceRange([227, 277])], message: "Duplicate tags are not allowed." }"#, + r#"type: KclErrorDetails { source_ranges: [SourceRange([205, 255])], message: "Duplicate tags are not allowed." }"#, ); } @@ -226,9 +226,9 @@ async fn serial_test_fillet_duplicate_tags() { async fn serial_test_basic_fillet_cube_start() { let code = r#"const part001 = startSketchOn('XY') |> startProfileAt([0,0], %) - |> line({to: [0, 10], tag: "thing"}, %) + |> line([0, 10], %, "thing") |> line([10, 0], %) - |> line({to: [0, -10], tag: "thing2"}, %) + |> line([0, -10], %, "thing2") |> close(%) |> extrude(10, %) |> fillet({radius: 2, tags: ["thing", "thing2"]}, %) @@ -244,9 +244,9 @@ async fn serial_test_basic_fillet_cube_start() { async fn serial_test_basic_fillet_cube_end() { let code = r#"const part001 = startSketchOn('XY') |> startProfileAt([0,0], %) - |> line({to: [0, 10], tag: "thing"}, %) + |> line([0, 10], %, "thing") |> line([10, 0], %) - |> line({to: [0, -10], tag: "thing2"}, %) + |> line([0, -10], %, "thing2") |> close(%) |> extrude(10, %) |> fillet({radius: 2, tags: ["thing", getOppositeEdge("thing", %)]}, %) @@ -263,9 +263,9 @@ async fn serial_test_basic_fillet_cube_end() { async fn serial_test_basic_fillet_cube_close_opposite() { let code = r#"const part001 = startSketchOn('XY') |> startProfileAt([0,0], %) - |> line({to: [0, 10], tag: "thing"}, %) + |> line([0, 10], %, "thing") |> line([10, 0], %) - |> line({to: [0, -10], tag: "thing2"}, %) + |> line([0, -10], %, "thing2") |> close(%, "thing3") |> extrude(10, %) |> fillet({radius: 2, tags: ["thing3", getOppositeEdge("thing3", %)]}, %) @@ -286,9 +286,9 @@ async fn serial_test_basic_fillet_cube_close_opposite() { async fn serial_test_basic_fillet_cube_next_adjacent() { let code = r#"const part001 = startSketchOn('XY') |> startProfileAt([0,0], %) - |> line({to: [0, 10], tag: "thing"}, %) - |> line({to: [10, 0], tag: "thing1"}, %) - |> line({to: [0, -10], tag: "thing2"}, %) + |> line([0, 10], %, "thing") + |> line([10, 0], %, "thing1") + |> line([0, -10], %, "thing2") |> close(%) |> extrude(10, %) |> fillet({radius: 2, tags: [getNextAdjacentEdge("thing", %)]}, %) @@ -308,9 +308,9 @@ async fn serial_test_basic_fillet_cube_next_adjacent() { async fn serial_test_basic_fillet_cube_previous_adjacent() { let code = r#"const part001 = startSketchOn('XY') |> startProfileAt([0,0], %) - |> line({to: [0, 10], tag: "thing"}, %) - |> line({to: [10, 0], tag: "thing1"}, %) - |> line({to: [0, -10], tag: "thing2"}, %) + |> line([0, 10], %, "thing") + |> line([10, 0], %, "thing1") + |> line([0, -10], %, "thing2") |> close(%) |> extrude(10, %) |> fillet({radius: 2, tags: [getPreviousAdjacentEdge("thing2", %)]}, %) @@ -380,7 +380,7 @@ async fn serial_test_execute_with_angled_line() { let code = r#"const part001 = startSketchOn('XY') |> startProfileAt([4.83, 12.56], %) |> line([15.1, 2.48], %) - |> line({ to: [3.15, -9.85], tag: 'seg01' }, %) + |> line([3.15, -9.85], %, 'seg01') |> line([-15.17, -4.1], %) |> angledLine([segAng('seg01', %), 12.35], %) |> line([-13.02, 10.03], %) @@ -1177,7 +1177,7 @@ async fn serial_test_error_sketch_on_arc_face() { let code = r#"fn cube = (pos, scale) => { const sg = startSketchOn('XY') |> startProfileAt(pos, %) - |> tangentialArc({ to: [0, scale], tag: "here" }, %) + |> tangentialArc([0, scale], %, "here") |> line([scale, 0], %) |> line([0, -scale], %) @@ -1201,7 +1201,7 @@ const part002 = startSketchOn(part001, "here") assert!(result.is_err()); assert_eq!( result.err().unwrap().to_string(), - r#"type: KclErrorDetails { source_ranges: [SourceRange([294, 324])], message: "Cannot sketch on a non-planar surface: `here`" }"# + r#"type: KclErrorDetails { source_ranges: [SourceRange([281, 311])], message: "Cannot sketch on a non-planar surface: `here`" }"# ); } @@ -1325,18 +1325,9 @@ async fn serial_test_stdlib_kcl_error_circle() { fn rectShape = (pos, w, l) => { const rr = startSketchOn('XY') |> startProfileAt([pos[0] - (w / 2), pos[1] - (l / 2)], %) - |> lineTo({ - to: [pos[0] + w / 2, pos[1] - (l / 2)], - tag: "edge1" - }, %) - |> lineTo({ - to: [pos[0] + w / 2, pos[1] + l / 2], - tag: "edge2" - }, %) - |> lineTo({ - to: [pos[0] - (w / 2), pos[1] + l / 2], - tag: "edge3" - }, %) + |> lineTo([pos[0] + w / 2, pos[1] - (l / 2)], %, "edge1") + |> lineTo([pos[0] + w / 2, pos[1] + l / 2], %, "edge2") + |> lineTo([pos[0] - (w / 2), pos[1] + l / 2], %, "edge3") |> close(%, "edge4") return rr } @@ -1367,6 +1358,6 @@ const part = rectShape([0, 0], 20, 20) assert!(result.is_err()); assert_eq!( result.err().unwrap().to_string(), - r#"type: KclErrorDetails { source_ranges: [SourceRange([987, 1036])], message: "Expected a [number, number] as the first argument, found `[UserVal(UserVal { value: String(\"XY\"), meta: [Metadata { source_range: SourceRange([994, 998]) }] }), UserVal(UserVal { value: Array [Number(-6.0), Number(6)], meta: [Metadata { source_range: SourceRange([1000, 1023]) }] }), UserVal(UserVal { value: Number(1), meta: [Metadata { source_range: SourceRange([856, 857]) }] })]`" }"# + r#"type: KclErrorDetails { source_ranges: [SourceRange([891, 940])], message: "Expected a [number, number] as the first argument, found `[UserVal(UserVal { value: String(\"XY\"), meta: [Metadata { source_range: SourceRange([898, 902]) }] }), UserVal(UserVal { value: Array [Number(-6.0), Number(6)], meta: [Metadata { source_range: SourceRange([904, 927]) }] }), UserVal(UserVal { value: Number(1), meta: [Metadata { source_range: SourceRange([760, 761]) }] })]`" }"# ); }