diff --git a/docs/kcl/abs.md b/docs/kcl/abs.md index 49e0cd1e1..98c63cbc7 100644 --- a/docs/kcl/abs.md +++ b/docs/kcl/abs.md @@ -9,7 +9,7 @@ Compute the absolute value of a number. ```js -abs(num: number): number +abs(input: number): number ``` ### Tags @@ -21,7 +21,7 @@ abs(num: number): number | Name | Type | Description | Required | |----------|------|-------------|----------| -| `num` | [`number`](/docs/kcl/types/number) | | Yes | +| `input` | [`number`](/docs/kcl/types/number) | The number to compute the absolute value of. | Yes | ### Returns diff --git a/docs/kcl/acos.md b/docs/kcl/acos.md index 300415b8f..0b7ab648f 100644 --- a/docs/kcl/acos.md +++ b/docs/kcl/acos.md @@ -9,7 +9,7 @@ Compute the arccosine of a number (in radians). ```js -acos(num: number): number +acos(input: number): number ``` ### Tags @@ -21,7 +21,7 @@ acos(num: number): number | Name | Type | Description | Required | |----------|------|-------------|----------| -| `num` | [`number`](/docs/kcl/types/number) | | Yes | +| `input` | [`number`](/docs/kcl/types/number) | The number to compute arccosine of. | Yes | ### Returns diff --git a/docs/kcl/asin.md b/docs/kcl/asin.md index f33607297..0ed6c680c 100644 --- a/docs/kcl/asin.md +++ b/docs/kcl/asin.md @@ -9,7 +9,7 @@ Compute the arcsine of a number (in radians). ```js -asin(num: number): number +asin(input: number): number ``` ### Tags @@ -21,7 +21,7 @@ asin(num: number): number | Name | Type | Description | Required | |----------|------|-------------|----------| -| `num` | [`number`](/docs/kcl/types/number) | | Yes | +| `input` | [`number`](/docs/kcl/types/number) | The number to compute arcsine of. | Yes | ### Returns diff --git a/docs/kcl/atan.md b/docs/kcl/atan.md index cc8a9234b..77821336b 100644 --- a/docs/kcl/atan.md +++ b/docs/kcl/atan.md @@ -6,10 +6,10 @@ layout: manual Compute the arctangent of a number (in radians). - +Consider using `atan2()` instead for the true inverse of tangent. ```js -atan(num: number): number +atan(input: number): number ``` ### Tags @@ -21,7 +21,7 @@ atan(num: number): number | Name | Type | Description | Required | |----------|------|-------------|----------| -| `num` | [`number`](/docs/kcl/types/number) | | Yes | +| `input` | [`number`](/docs/kcl/types/number) | The number to compute arctangent of. | Yes | ### Returns diff --git a/docs/kcl/ceil.md b/docs/kcl/ceil.md index 47807dae5..6c3355de4 100644 --- a/docs/kcl/ceil.md +++ b/docs/kcl/ceil.md @@ -9,7 +9,7 @@ Compute the smallest integer greater than or equal to a number. ```js -ceil(num: number): number +ceil(input: number): number ``` ### Tags @@ -21,7 +21,7 @@ ceil(num: number): number | Name | Type | Description | Required | |----------|------|-------------|----------| -| `num` | [`number`](/docs/kcl/types/number) | | Yes | +| `input` | [`number`](/docs/kcl/types/number) | The number to round. | Yes | ### Returns diff --git a/docs/kcl/floor.md b/docs/kcl/floor.md index 07224d361..58caed645 100644 --- a/docs/kcl/floor.md +++ b/docs/kcl/floor.md @@ -9,7 +9,7 @@ Compute the largest integer less than or equal to a number. ```js -floor(num: number): number +floor(input: number): number ``` ### Tags @@ -21,7 +21,7 @@ floor(num: number): number | Name | Type | Description | Required | |----------|------|-------------|----------| -| `num` | [`number`](/docs/kcl/types/number) | | Yes | +| `input` | [`number`](/docs/kcl/types/number) | The number to round. | Yes | ### Returns diff --git a/docs/kcl/ln.md b/docs/kcl/ln.md index 8b5f917bc..b4735d09d 100644 --- a/docs/kcl/ln.md +++ b/docs/kcl/ln.md @@ -9,7 +9,7 @@ Compute the natural logarithm of the number. ```js -ln(num: number): number +ln(input: number): number ``` ### Tags @@ -21,7 +21,7 @@ ln(num: number): number | Name | Type | Description | Required | |----------|------|-------------|----------| -| `num` | [`number`](/docs/kcl/types/number) | | Yes | +| `input` | [`number`](/docs/kcl/types/number) | The number to compute the logarithm of. | Yes | ### Returns diff --git a/docs/kcl/log.md b/docs/kcl/log.md index d0a45c6a4..b46938b0b 100644 --- a/docs/kcl/log.md +++ b/docs/kcl/log.md @@ -10,7 +10,7 @@ The result might not be correctly rounded owing to implementation details; `log2 ```js log( - num: number, + input: number, base: number, ): number ``` @@ -24,8 +24,8 @@ log( | Name | Type | Description | Required | |----------|------|-------------|----------| -| `num` | [`number`](/docs/kcl/types/number) | | Yes | -| `base` | [`number`](/docs/kcl/types/number) | | Yes | +| `input` | [`number`](/docs/kcl/types/number) | The number to compute the logarithm of. | Yes | +| `base` | [`number`](/docs/kcl/types/number) | The base of the logarithm. | Yes | ### Returns @@ -37,7 +37,7 @@ log( ```js exampleSketch = startSketchOn(XZ) |> startProfile(at = [0, 0]) - |> line(end = [log(100, 5), 0]) + |> line(end = [log(100, base = 5), 0]) |> line(end = [5, 8]) |> line(end = [-10, 0]) |> close() diff --git a/docs/kcl/log2.md b/docs/kcl/log2.md index 7178c02bb..509a2456c 100644 --- a/docs/kcl/log2.md +++ b/docs/kcl/log2.md @@ -9,7 +9,7 @@ Compute the base 2 logarithm of the number. ```js -log2(num: number): number +log2(input: number): number ``` ### Tags @@ -21,7 +21,7 @@ log2(num: number): number | Name | Type | Description | Required | |----------|------|-------------|----------| -| `num` | [`number`](/docs/kcl/types/number) | | Yes | +| `input` | [`number`](/docs/kcl/types/number) | The number to compute the logarithm of. | Yes | ### Returns diff --git a/docs/kcl/max.md b/docs/kcl/max.md index 990aa09aa..70c9664de 100644 --- a/docs/kcl/max.md +++ b/docs/kcl/max.md @@ -9,7 +9,7 @@ Compute the maximum of the given arguments. ```js -max(args: [number]): number +max(input: [number]): number ``` ### Tags @@ -21,7 +21,7 @@ max(args: [number]): number | Name | Type | Description | Required | |----------|------|-------------|----------| -| `args` | [`[number]`](/docs/kcl/types/number) | | Yes | +| `input` | [`[number]`](/docs/kcl/types/number) | An array of numbers to compute the maximum of. | Yes | ### Returns @@ -33,7 +33,7 @@ max(args: [number]): number ```js exampleSketch = startSketchOn(XZ) |> startProfile(at = [0, 0]) - |> angledLine(angle = 70, length = max(15, 31, 4, 13, 22)) + |> angledLine(angle = 70, length = max([15, 31, 4, 13, 22])) |> line(end = [20, 0]) |> close() diff --git a/docs/kcl/min.md b/docs/kcl/min.md index 2a32b4605..50a1741cc 100644 --- a/docs/kcl/min.md +++ b/docs/kcl/min.md @@ -9,7 +9,7 @@ Compute the minimum of the given arguments. ```js -min(args: [number]): number +min(input: [number]): number ``` ### Tags @@ -21,7 +21,7 @@ min(args: [number]): number | Name | Type | Description | Required | |----------|------|-------------|----------| -| `args` | [`[number]`](/docs/kcl/types/number) | | Yes | +| `input` | [`[number]`](/docs/kcl/types/number) | An array of numbers to compute the minimum of. | Yes | ### Returns @@ -33,7 +33,7 @@ min(args: [number]): number ```js exampleSketch = startSketchOn(XZ) |> startProfile(at = [0, 0]) - |> angledLine(angle = 70, length = min(15, 31, 4, 13, 22)) + |> angledLine(angle = 70, length = min([15, 31, 4, 13, 22])) |> line(end = [20, 0]) |> close() diff --git a/docs/kcl/patternTransform.md b/docs/kcl/patternTransform.md index ca9f60c89..8339680e2 100644 --- a/docs/kcl/patternTransform.md +++ b/docs/kcl/patternTransform.md @@ -117,7 +117,11 @@ fn transform(i) { // Move down each time. translate = [0, 0, -i * width], // Make the cube longer, wider and flatter each time. - scale = [pow(1.1, i), pow(1.1, i), pow(0.9, i)], + scale = [ + pow(1.1, exp = i), + pow(1.1, exp = i), + pow(0.9, exp = i) + ], // Turn by 15 degrees each time. rotation = { angle = 15 * i, origin = "local" } } diff --git a/docs/kcl/pow.md b/docs/kcl/pow.md index 262afdf9c..1862b0d55 100644 --- a/docs/kcl/pow.md +++ b/docs/kcl/pow.md @@ -10,8 +10,8 @@ Compute the number to a power. ```js pow( - num: number, - pow: number, + input: number, + exp: number, ): number ``` @@ -24,8 +24,8 @@ pow( | Name | Type | Description | Required | |----------|------|-------------|----------| -| `num` | [`number`](/docs/kcl/types/number) | | Yes | -| `pow` | [`number`](/docs/kcl/types/number) | | Yes | +| `input` | [`number`](/docs/kcl/types/number) | The number to raise. | Yes | +| `exp` | [`number`](/docs/kcl/types/number) | The power to raise to. | Yes | ### Returns @@ -37,7 +37,7 @@ pow( ```js exampleSketch = startSketchOn(XZ) |> startProfile(at = [0, 0]) - |> angledLine(angle = 50, length = pow(5, 2)) + |> angledLine(angle = 50, length = pow(5, exp = 2)) |> yLine(endAbsolute = 0) |> close() diff --git a/docs/kcl/round.md b/docs/kcl/round.md index 9d7a6f9c9..e6c9f3fc1 100644 --- a/docs/kcl/round.md +++ b/docs/kcl/round.md @@ -9,7 +9,7 @@ Round a number to the nearest integer. ```js -round(num: number): number +round(input: number): number ``` ### Tags @@ -21,7 +21,7 @@ round(num: number): number | Name | Type | Description | Required | |----------|------|-------------|----------| -| `num` | [`number`](/docs/kcl/types/number) | | Yes | +| `input` | [`number`](/docs/kcl/types/number) | The number to round. | Yes | ### Returns diff --git a/docs/kcl/sqrt.md b/docs/kcl/sqrt.md index 8bba0f94a..c0642ee33 100644 --- a/docs/kcl/sqrt.md +++ b/docs/kcl/sqrt.md @@ -9,7 +9,7 @@ Compute the square root of a number. ```js -sqrt(num: number): number +sqrt(input: number): number ``` ### Tags @@ -21,7 +21,7 @@ sqrt(num: number): number | Name | Type | Description | Required | |----------|------|-------------|----------| -| `num` | [`number`](/docs/kcl/types/number) | | Yes | +| `input` | [`number`](/docs/kcl/types/number) | The number to compute the square root of. | Yes | ### Returns diff --git a/docs/kcl/std.json b/docs/kcl/std.json index 405eb146d..25934738a 100644 --- a/docs/kcl/std.json +++ b/docs/kcl/std.json @@ -6,10 +6,10 @@ "tags": [ "math" ], - "keywordArguments": false, + "keywordArguments": true, "args": [ { - "name": "num", + "name": "input", "type": "number", "schema": { "$schema": "https://spec.openapis.org/oas/3.0/schema/2019-04-02#/definitions/Schema", @@ -19,7 +19,8 @@ }, "required": true, "includeInSnippet": true, - "labelRequired": true + "description": "The number to compute the absolute value of.", + "labelRequired": false } ], "returnValue": { @@ -48,10 +49,10 @@ "tags": [ "math" ], - "keywordArguments": false, + "keywordArguments": true, "args": [ { - "name": "num", + "name": "input", "type": "number", "schema": { "$schema": "https://spec.openapis.org/oas/3.0/schema/2019-04-02#/definitions/Schema", @@ -61,7 +62,8 @@ }, "required": true, "includeInSnippet": true, - "labelRequired": true + "description": "The number to compute arccosine of.", + "labelRequired": false } ], "returnValue": { @@ -45605,10 +45607,10 @@ "tags": [ "math" ], - "keywordArguments": false, + "keywordArguments": true, "args": [ { - "name": "num", + "name": "input", "type": "number", "schema": { "$schema": "https://spec.openapis.org/oas/3.0/schema/2019-04-02#/definitions/Schema", @@ -45618,7 +45620,8 @@ }, "required": true, "includeInSnippet": true, - "labelRequired": true + "description": "The number to compute arcsine of.", + "labelRequired": false } ], "returnValue": { @@ -45893,14 +45896,14 @@ { "name": "atan", "summary": "Compute the arctangent of a number (in radians).", - "description": "", + "description": "Consider using `atan2()` instead for the true inverse of tangent.", "tags": [ "math" ], - "keywordArguments": false, + "keywordArguments": true, "args": [ { - "name": "num", + "name": "input", "type": "number", "schema": { "$schema": "https://spec.openapis.org/oas/3.0/schema/2019-04-02#/definitions/Schema", @@ -45910,7 +45913,8 @@ }, "required": true, "includeInSnippet": true, - "labelRequired": true + "description": "The number to compute arctangent of.", + "labelRequired": false } ], "returnValue": { @@ -55774,10 +55778,10 @@ "tags": [ "math" ], - "keywordArguments": false, + "keywordArguments": true, "args": [ { - "name": "num", + "name": "input", "type": "number", "schema": { "$schema": "https://spec.openapis.org/oas/3.0/schema/2019-04-02#/definitions/Schema", @@ -55787,7 +55791,8 @@ }, "required": true, "includeInSnippet": true, - "labelRequired": true + "description": "The number to round.", + "labelRequired": false } ], "returnValue": { @@ -103470,10 +103475,10 @@ "tags": [ "math" ], - "keywordArguments": false, + "keywordArguments": true, "args": [ { - "name": "num", + "name": "input", "type": "number", "schema": { "$schema": "https://spec.openapis.org/oas/3.0/schema/2019-04-02#/definitions/Schema", @@ -103483,7 +103488,8 @@ }, "required": true, "includeInSnippet": true, - "labelRequired": true + "description": "The number to round.", + "labelRequired": false } ], "returnValue": { @@ -136915,10 +136921,10 @@ "tags": [ "math" ], - "keywordArguments": false, + "keywordArguments": true, "args": [ { - "name": "num", + "name": "input", "type": "number", "schema": { "$schema": "https://spec.openapis.org/oas/3.0/schema/2019-04-02#/definitions/Schema", @@ -136928,7 +136934,8 @@ }, "required": true, "includeInSnippet": true, - "labelRequired": true + "description": "The number to compute the logarithm of.", + "labelRequired": false } ], "returnValue": { @@ -149898,10 +149905,10 @@ "tags": [ "math" ], - "keywordArguments": false, + "keywordArguments": true, "args": [ { - "name": "num", + "name": "input", "type": "number", "schema": { "$schema": "https://spec.openapis.org/oas/3.0/schema/2019-04-02#/definitions/Schema", @@ -149911,7 +149918,8 @@ }, "required": true, "includeInSnippet": true, - "labelRequired": true + "description": "The number to compute the logarithm of.", + "labelRequired": false }, { "name": "base", @@ -149924,6 +149932,7 @@ }, "required": true, "includeInSnippet": true, + "description": "The base of the logarithm.", "labelRequired": true } ], @@ -149943,7 +149952,7 @@ "unpublished": false, "deprecated": false, "examples": [ - "exampleSketch = startSketchOn(XZ)\n |> startProfile(at = [0, 0])\n |> line(end = [log(100, 5), 0])\n |> line(end = [5, 8])\n |> line(end = [-10, 0])\n |> close()\n\nexample = extrude(exampleSketch, length = 5)" + "exampleSketch = startSketchOn(XZ)\n |> startProfile(at = [0, 0])\n |> line(end = [log(100, base = 5), 0])\n |> line(end = [5, 8])\n |> line(end = [-10, 0])\n |> close()\n\nexample = extrude(exampleSketch, length = 5)" ] }, { @@ -149995,10 +150004,10 @@ "tags": [ "math" ], - "keywordArguments": false, + "keywordArguments": true, "args": [ { - "name": "num", + "name": "input", "type": "number", "schema": { "$schema": "https://spec.openapis.org/oas/3.0/schema/2019-04-02#/definitions/Schema", @@ -150008,7 +150017,8 @@ }, "required": true, "includeInSnippet": true, - "labelRequired": true + "description": "The number to compute the logarithm of.", + "labelRequired": false } ], "returnValue": { @@ -157497,10 +157507,10 @@ "tags": [ "math" ], - "keywordArguments": false, + "keywordArguments": true, "args": [ { - "name": "args", + "name": "input", "type": "[number]", "schema": { "$schema": "https://spec.openapis.org/oas/3.0/schema/2019-04-02#/definitions/Schema", @@ -157513,7 +157523,8 @@ }, "required": true, "includeInSnippet": true, - "labelRequired": true + "description": "An array of numbers to compute the maximum of.", + "labelRequired": false } ], "returnValue": { @@ -157532,7 +157543,7 @@ "unpublished": false, "deprecated": false, "examples": [ - "exampleSketch = startSketchOn(XZ)\n |> startProfile(at = [0, 0])\n |> angledLine(angle = 70, length = max(15, 31, 4, 13, 22))\n |> line(end = [20, 0])\n |> close()\n\nexample = extrude(exampleSketch, length = 5)" + "exampleSketch = startSketchOn(XZ)\n |> startProfile(at = [0, 0])\n |> angledLine(angle = 70, length = max([15, 31, 4, 13, 22]))\n |> line(end = [20, 0])\n |> close()\n\nexample = extrude(exampleSketch, length = 5)" ] }, { @@ -157542,10 +157553,10 @@ "tags": [ "math" ], - "keywordArguments": false, + "keywordArguments": true, "args": [ { - "name": "args", + "name": "input", "type": "[number]", "schema": { "$schema": "https://spec.openapis.org/oas/3.0/schema/2019-04-02#/definitions/Schema", @@ -157558,7 +157569,8 @@ }, "required": true, "includeInSnippet": true, - "labelRequired": true + "description": "An array of numbers to compute the minimum of.", + "labelRequired": false } ], "returnValue": { @@ -157577,7 +157589,7 @@ "unpublished": false, "deprecated": false, "examples": [ - "exampleSketch = startSketchOn(XZ)\n |> startProfile(at = [0, 0])\n |> angledLine(angle = 70, length = min(15, 31, 4, 13, 22))\n |> line(end = [20, 0])\n |> close()\n\nexample = extrude(exampleSketch, length = 5)" + "exampleSketch = startSketchOn(XZ)\n |> startProfile(at = [0, 0])\n |> angledLine(angle = 70, length = min([15, 31, 4, 13, 22]))\n |> line(end = [20, 0])\n |> close()\n\nexample = extrude(exampleSketch, length = 5)" ] }, { @@ -209044,7 +209056,7 @@ "examples": [ "// Each instance will be shifted along the X axis.\nfn transform(id) {\n return { translate = [4 * id, 0, 0] }\n}\n\n// Sketch 4 cylinders.\nsketch001 = startSketchOn(XZ)\n |> circle(center = [0, 0], radius = 2)\n |> extrude(length = 5)\n |> patternTransform(instances = 4, transform = transform)", "// Each instance will be shifted along the X axis,\n// with a gap between the original (at x = 0) and the first replica\n// (at x = 8). This is because `id` starts at 1.\nfn transform(id) {\n return { translate = [4 * (1 + id), 0, 0] }\n}\n\nsketch001 = startSketchOn(XZ)\n |> circle(center = [0, 0], radius = 2)\n |> extrude(length = 5)\n |> patternTransform(instances = 4, transform = transform)", - "fn cube(length, center) {\n l = length / 2\n x = center[0]\n y = center[1]\n p0 = [-l + x, -l + y]\n p1 = [-l + x, l + y]\n p2 = [l + x, l + y]\n p3 = [l + x, -l + y]\n\n return startSketchOn(XY)\n |> startProfile(at = p0)\n |> line(endAbsolute = p1)\n |> line(endAbsolute = p2)\n |> line(endAbsolute = p3)\n |> line(endAbsolute = p0)\n |> close()\n |> extrude(length = length)\n}\n\nwidth = 20\nfn transform(i) {\n return {\n // Move down each time.\n translate = [0, 0, -i * width],\n // Make the cube longer, wider and flatter each time.\n scale = [pow(1.1, i), pow(1.1, i), pow(0.9, i)],\n // Turn by 15 degrees each time.\n rotation = { angle = 15 * i, origin = \"local\" }\n }\n}\n\nmyCubes = cube(width, [100, 0])\n |> patternTransform(instances = 25, transform = transform)", + "fn cube(length, center) {\n l = length / 2\n x = center[0]\n y = center[1]\n p0 = [-l + x, -l + y]\n p1 = [-l + x, l + y]\n p2 = [l + x, l + y]\n p3 = [l + x, -l + y]\n\n return startSketchOn(XY)\n |> startProfile(at = p0)\n |> line(endAbsolute = p1)\n |> line(endAbsolute = p2)\n |> line(endAbsolute = p3)\n |> line(endAbsolute = p0)\n |> close()\n |> extrude(length = length)\n}\n\nwidth = 20\nfn transform(i) {\n return {\n // Move down each time.\n translate = [0, 0, -i * width],\n // Make the cube longer, wider and flatter each time.\n scale = [\n pow(1.1, exp = i),\n pow(1.1, exp = i),\n pow(0.9, exp = i)\n ],\n // Turn by 15 degrees each time.\n rotation = { angle = 15 * i, origin = \"local\" }\n }\n}\n\nmyCubes = cube(width, [100, 0])\n |> patternTransform(instances = 25, transform = transform)", "fn cube(length, center) {\n l = length / 2\n x = center[0]\n y = center[1]\n p0 = [-l + x, -l + y]\n p1 = [-l + x, l + y]\n p2 = [l + x, l + y]\n p3 = [l + x, -l + y]\n\n return startSketchOn(XY)\n |> startProfile(at = p0)\n |> line(endAbsolute = p1)\n |> line(endAbsolute = p2)\n |> line(endAbsolute = p3)\n |> line(endAbsolute = p0)\n |> close()\n |> extrude(length = length)\n}\n\nwidth = 20\nfn transform(i) {\n return {\n translate = [0, 0, -i * width],\n rotation = {\n angle = 90 * i,\n // Rotate around the overall scene's origin.\n origin = \"global\"\n }\n }\n}\nmyCubes = cube(width, [100, 100])\n |> patternTransform(instances = 4, transform = transform)", "// Parameters\nr = 50 // base radius\nh = 10 // layer height\nt = 0.005 // taper factor [0-1)\n// Defines how to modify each layer of the vase.\n// Each replica is shifted up the Z axis, and has a smoothly-varying radius\nfn transform(replicaId) {\n scale = r * abs(1 - (t * replicaId)) * (5 + cos(replicaId / 8: number(rad)))\n return {\n translate = [0, 0, replicaId * 10],\n scale = [scale, scale, 0]\n }\n}\n// Each layer is just a pretty thin cylinder.\nfn layer() {\n return startSketchOn(XY)\n // or some other plane idk\n |> circle(center = [0, 0], radius = 1, tag = $tag1)\n |> extrude(length = h)\n}\n// The vase is 100 layers tall.\n// The 100 layers are replica of each other, with a slight transformation applied to each.\nvase = layer()\n |> patternTransform(instances = 100, transform = transform)", "fn transform(i) {\n // Transform functions can return multiple transforms. They'll be applied in order.\n return [\n { translate = [30 * i, 0, 0] },\n { rotation = { angle = 45 * i } }\n ]\n}\nstartSketchOn(XY)\n |> startProfile(at = [0, 0])\n |> polygon(\n radius = 10,\n numSides = 4,\n center = [0, 0],\n inscribed = false,\n )\n |> extrude(length = 4)\n |> patternTransform(instances = 3, transform = transform)" @@ -232200,10 +232212,10 @@ "tags": [ "math" ], - "keywordArguments": false, + "keywordArguments": true, "args": [ { - "name": "num", + "name": "input", "type": "number", "schema": { "$schema": "https://spec.openapis.org/oas/3.0/schema/2019-04-02#/definitions/Schema", @@ -232213,10 +232225,11 @@ }, "required": true, "includeInSnippet": true, - "labelRequired": true + "description": "The number to raise.", + "labelRequired": false }, { - "name": "pow", + "name": "exp", "type": "number", "schema": { "$schema": "https://spec.openapis.org/oas/3.0/schema/2019-04-02#/definitions/Schema", @@ -232226,6 +232239,7 @@ }, "required": true, "includeInSnippet": true, + "description": "The power to raise to.", "labelRequired": true } ], @@ -232245,7 +232259,7 @@ "unpublished": false, "deprecated": false, "examples": [ - "exampleSketch = startSketchOn(XZ)\n |> startProfile(at = [0, 0])\n |> angledLine(angle = 50, length = pow(5, 2))\n |> yLine(endAbsolute = 0)\n |> close()\n\nexample = extrude(exampleSketch, length = 5)" + "exampleSketch = startSketchOn(XZ)\n |> startProfile(at = [0, 0])\n |> angledLine(angle = 50, length = pow(5, exp = 2))\n |> yLine(endAbsolute = 0)\n |> close()\n\nexample = extrude(exampleSketch, length = 5)" ] }, { @@ -269324,10 +269338,10 @@ "tags": [ "math" ], - "keywordArguments": false, + "keywordArguments": true, "args": [ { - "name": "num", + "name": "input", "type": "number", "schema": { "$schema": "https://spec.openapis.org/oas/3.0/schema/2019-04-02#/definitions/Schema", @@ -269337,7 +269351,8 @@ }, "required": true, "includeInSnippet": true, - "labelRequired": true + "description": "The number to round.", + "labelRequired": false } ], "returnValue": { @@ -286036,10 +286051,10 @@ "tags": [ "math" ], - "keywordArguments": false, + "keywordArguments": true, "args": [ { - "name": "num", + "name": "input", "type": "number", "schema": { "$schema": "https://spec.openapis.org/oas/3.0/schema/2019-04-02#/definitions/Schema", @@ -286049,7 +286064,8 @@ }, "required": true, "includeInSnippet": true, - "labelRequired": true + "description": "The number to compute the square root of.", + "labelRequired": false } ], "returnValue": { diff --git a/public/kcl-samples/food-service-spatula/main.kcl b/public/kcl-samples/food-service-spatula/main.kcl index 3be1ab72f..31a1659ba 100644 --- a/public/kcl-samples/food-service-spatula/main.kcl +++ b/public/kcl-samples/food-service-spatula/main.kcl @@ -31,7 +31,7 @@ fn slot(sketch1, start, end, width) { toDegrees( atan((end[1] - start[1]) / (end[0] - start[0]))) } } - dist = sqrt(pow(end[1] - start[1], 2) + pow(end[0] - start[0], 2)) + dist = sqrt(pow(end[1] - start[1], exp = 2) + pow(end[0] - start[0], exp = 2)) xstart = width / 2 * cos(toRadians(angle - 90)) + start[0] ystart = width / 2 * sin(toRadians(angle - 90)) + start[1] slotSketch = startProfile(sketch1, at = [xstart, ystart]) diff --git a/rust/kcl-lib/e2e/executor/inputs/lsystem.kcl b/rust/kcl-lib/e2e/executor/inputs/lsystem.kcl index da1662393..1477559df 100644 --- a/rust/kcl-lib/e2e/executor/inputs/lsystem.kcl +++ b/rust/kcl-lib/e2e/executor/inputs/lsystem.kcl @@ -5,7 +5,7 @@ fn cond = (bools) => { return (a, b) => { - x = min(max(-1, a-b), 1) + 1 + x = min([max([-1, a-b]), 1]) + 1 return bools[x] } } diff --git a/rust/kcl-lib/src/execution/mod.rs b/rust/kcl-lib/src/execution/mod.rs index bf42c8d40..cc472d1ce 100644 --- a/rust/kcl-lib/src/execution/mod.rs +++ b/rust/kcl-lib/src/execution/mod.rs @@ -1315,7 +1315,7 @@ const part001 = startSketchOn(XY) |> startProfile(at = [0, 0]) |> line(end = [3, 4], tag = $seg01) |> line(end = [ - min(segLen(seg01), myVar), + min([segLen(seg01), myVar]), -legLen(hypotenuse = segLen(seg01), leg = myVar) ]) "#; @@ -1330,7 +1330,7 @@ const part001 = startSketchOn(XY) |> startProfile(at = [0, 0]) |> line(end = [3, 4], tag = $seg01) |> line(end = [ - min(segLen(seg01), myVar), + min([segLen(seg01), myVar]), legLen(hypotenuse = segLen(seg01), leg = myVar) ]) "#; @@ -1723,7 +1723,7 @@ let shape = layer() |> patternTransform(instances = 10, transform = transform) #[tokio::test(flavor = "multi_thread")] async fn test_math_execute_with_functions() { - let ast = r#"const myVar = 2 + min(100, -1 + legLen(hypotenuse = 5, leg = 3))"#; + let ast = r#"myVar = 2 + min([100, -1 + legLen(hypotenuse = 5, leg = 3)])"#; let result = parse_execute(ast).await.unwrap(); assert_eq!( 5.0, diff --git a/rust/kcl-lib/src/execution/types.rs b/rust/kcl-lib/src/execution/types.rs index c00585793..71d608948 100644 --- a/rust/kcl-lib/src/execution/types.rs +++ b/rust/kcl-lib/src/execution/types.rs @@ -2054,10 +2054,10 @@ o = 3mm / 3 p = 3_ / 4 q = 4inch / 2_ -r = min(0, 3, 42) -s = min(0, 3mm, -42) -t = min(100, 3in, 142mm) -u = min(3rad, 4in) +r = min([0, 3, 42]) +s = min([0, 3mm, -42]) +t = min([100, 3in, 142mm]) +u = min([3rad, 4in]) "#; let result = parse_execute(program).await.unwrap(); diff --git a/rust/kcl-lib/src/parsing/ast/types/mod.rs b/rust/kcl-lib/src/parsing/ast/types/mod.rs index dd070bc7f..b550b2f28 100644 --- a/rust/kcl-lib/src/parsing/ast/types/mod.rs +++ b/rust/kcl-lib/src/parsing/ast/types/mod.rs @@ -3683,7 +3683,7 @@ fn ghi = (x) => { #[test] fn test_ast_in_comment() { - let some_program_string = r#"const r = 20 / pow(pi(), 1 / 3) + let some_program_string = r#"r = 20 / pow(pi(), exp = 1 / 3) const h = 30 // st @@ -3703,7 +3703,7 @@ const cylinder = startSketchOn('-XZ') #[test] fn test_ast_in_comment_pipe() { - let some_program_string = r#"const r = 20 / pow(pi(), 1 / 3) + let some_program_string = r#"r = 20 / pow(pi(), exp = 1 / 3) const h = 30 // st diff --git a/rust/kcl-lib/src/std/args.rs b/rust/kcl-lib/src/std/args.rs index e16f25fd3..d70857ec9 100644 --- a/rust/kcl-lib/src/std/args.rs +++ b/rust/kcl-lib/src/std/args.rs @@ -598,23 +598,6 @@ impl Args { Ok(TyF64::from_kcl_val(&arg.value).unwrap().n) } - pub(crate) fn get_number_array_with_types(&self) -> Result, KclError> { - let numbers = self - .args - .iter() - .map(|arg| { - let Some(num) = ::from_kcl_val(&arg.value) else { - return Err(KclError::Semantic(KclErrorDetails { - source_ranges: arg.source_ranges(), - message: format!("Expected a number but found {}", arg.value.human_friendly_type()), - })); - }; - Ok(num) - }) - .collect::>()?; - Ok(numbers) - } - pub(crate) async fn get_adjacent_face_to_tag( &self, exec_state: &mut ExecState, @@ -1159,6 +1142,7 @@ impl_from_kcl_for_vec!(crate::execution::EdgeCut); impl_from_kcl_for_vec!(crate::execution::Metadata); impl_from_kcl_for_vec!(super::fillet::EdgeReference); impl_from_kcl_for_vec!(ExtrudeSurface); +impl_from_kcl_for_vec!(TyF64); impl<'a> FromKclValue<'a> for SourceRange { fn from_kcl_val(arg: &'a KclValue) -> Option { diff --git a/rust/kcl-lib/src/std/math.rs b/rust/kcl-lib/src/std/math.rs index 16adde1f8..886fc5107 100644 --- a/rust/kcl-lib/src/std/math.rs +++ b/rust/kcl-lib/src/std/math.rs @@ -4,9 +4,9 @@ use anyhow::Result; use kcl_derive_docs::stdlib; use crate::{ - errors::{KclError, KclErrorDetails}, + errors::KclError, execution::{ - types::{NumericType, RuntimeType, UnitAngle, UnitType}, + types::{ArrayLen, NumericType, RuntimeType, UnitAngle, UnitType}, ExecState, KclValue, }, std::args::{Args, TyF64}, @@ -147,8 +147,8 @@ fn inner_pi() -> Result { /// Compute the square root of a number. pub async fn sqrt(exec_state: &mut ExecState, args: Args) -> Result { - let num = args.get_number_with_type()?; - let result = inner_sqrt(num.n)?; + let input: TyF64 = args.get_unlabeled_kw_arg_typed("input", &RuntimeType::num_any(), exec_state)?; + let result = inner_sqrt(input.n); Ok(args.make_user_val_from_f64_with_type(TyF64::new(result, exec_state.current_default_units()))) } @@ -170,17 +170,22 @@ pub async fn sqrt(exec_state: &mut ExecState, args: Args) -> Result Result { - Ok(num.sqrt()) +fn inner_sqrt(input: f64) -> f64 { + input.sqrt() } /// Compute the absolute value of a number. -pub async fn abs(_exec_state: &mut ExecState, args: Args) -> Result { - let num = args.get_number_with_type()?; - let result = inner_abs(num.n)?; +pub async fn abs(exec_state: &mut ExecState, args: Args) -> Result { + let input: TyF64 = args.get_unlabeled_kw_arg_typed("input", &RuntimeType::num_any(), exec_state)?; + let result = inner_abs(input.n); - Ok(args.make_user_val_from_f64_with_type(num.map_value(result))) + Ok(args.make_user_val_from_f64_with_type(input.map_value(result))) } /// Compute the absolute value of a number. @@ -207,17 +212,22 @@ pub async fn abs(_exec_state: &mut ExecState, args: Args) -> Result Result { - Ok(num.abs()) +fn inner_abs(input: f64) -> f64 { + input.abs() } /// Round a number to the nearest integer. -pub async fn round(_exec_state: &mut ExecState, args: Args) -> Result { - let num = args.get_number_with_type()?; - let result = inner_round(num.n)?; +pub async fn round(exec_state: &mut ExecState, args: Args) -> Result { + let input: TyF64 = args.get_unlabeled_kw_arg_typed("input", &RuntimeType::num_any(), exec_state)?; + let result = inner_round(input.n); - Ok(args.make_user_val_from_f64_with_type(num.map_value(result))) + Ok(args.make_user_val_from_f64_with_type(input.map_value(result))) } /// Round a number to the nearest integer. @@ -235,17 +245,22 @@ pub async fn round(_exec_state: &mut ExecState, args: Args) -> Result Result { - Ok(num.round()) +fn inner_round(input: f64) -> f64 { + input.round() } /// Compute the largest integer less than or equal to a number. -pub async fn floor(_exec_state: &mut ExecState, args: Args) -> Result { - let num = args.get_number_with_type()?; - let result = inner_floor(num.n)?; +pub async fn floor(exec_state: &mut ExecState, args: Args) -> Result { + let input: TyF64 = args.get_unlabeled_kw_arg_typed("input", &RuntimeType::num_any(), exec_state)?; + let result = inner_floor(input.n); - Ok(args.make_user_val_from_f64_with_type(num.map_value(result))) + Ok(args.make_user_val_from_f64_with_type(input.map_value(result))) } /// Compute the largest integer less than or equal to a number. @@ -263,17 +278,22 @@ pub async fn floor(_exec_state: &mut ExecState, args: Args) -> Result Result { - Ok(num.floor()) +fn inner_floor(input: f64) -> f64 { + input.floor() } /// Compute the smallest integer greater than or equal to a number. -pub async fn ceil(_exec_state: &mut ExecState, args: Args) -> Result { - let num = args.get_number_with_type()?; - let result = inner_ceil(num.n)?; +pub async fn ceil(exec_state: &mut ExecState, args: Args) -> Result { + let input: TyF64 = args.get_unlabeled_kw_arg_typed("input", &RuntimeType::num_any(), exec_state)?; + let result = inner_ceil(input.n); - Ok(args.make_user_val_from_f64_with_type(num.map_value(result))) + Ok(args.make_user_val_from_f64_with_type(input.map_value(result))) } /// Compute the smallest integer greater than or equal to a number. @@ -291,14 +311,23 @@ pub async fn ceil(_exec_state: &mut ExecState, args: Args) -> Result Result { - Ok(num.ceil()) +fn inner_ceil(input: f64) -> f64 { + input.ceil() } /// Compute the minimum of the given arguments. pub async fn min(exec_state: &mut ExecState, args: Args) -> Result { - let nums = args.get_number_array_with_types()?; + let nums: Vec = args.get_unlabeled_kw_arg_typed( + "input", + &RuntimeType::Array(Box::new(RuntimeType::num_any()), ArrayLen::None), + exec_state, + )?; let (nums, ty) = NumericType::combine_eq_array(&nums); if ty == NumericType::Unknown { exec_state.warn(CompilationError::err( @@ -318,7 +347,7 @@ pub async fn min(exec_state: &mut ExecState, args: Args) -> Result startProfile(at = [0, 0]) /// |> angledLine( /// angle = 70, -/// length = min(15, 31, 4, 13, 22) +/// length = min([15, 31, 4, 13, 22]) /// ) /// |> line(end = [20, 0]) /// |> close() @@ -328,12 +357,17 @@ pub async fn min(exec_state: &mut ExecState, args: Args) -> Result) -> f64 { +fn inner_min(input: Vec) -> f64 { let mut min = f64::MAX; - for arg in args.iter() { - if *arg < min { - min = *arg; + for num in input.iter() { + if *num < min { + min = *num; } } @@ -342,7 +376,11 @@ fn inner_min(args: Vec) -> f64 { /// Compute the maximum of the given arguments. pub async fn max(exec_state: &mut ExecState, args: Args) -> Result { - let nums = args.get_number_array_with_types()?; + let nums: Vec = args.get_unlabeled_kw_arg_typed( + "input", + &RuntimeType::Array(Box::new(RuntimeType::num_any()), ArrayLen::None), + exec_state, + )?; let (nums, ty) = NumericType::combine_eq_array(&nums); if ty == NumericType::Unknown { exec_state.warn(CompilationError::err( @@ -362,7 +400,7 @@ pub async fn max(exec_state: &mut ExecState, args: Args) -> Result startProfile(at = [0, 0]) /// |> angledLine( /// angle = 70, -/// length = max(15, 31, 4, 13, 22) +/// length = max([15, 31, 4, 13, 22]) /// ) /// |> line(end = [20, 0]) /// |> close() @@ -372,12 +410,17 @@ pub async fn max(exec_state: &mut ExecState, args: Args) -> Result) -> f64 { +fn inner_max(input: Vec) -> f64 { let mut max = f64::MIN; - for arg in args.iter() { - if *arg > max { - max = *arg; + for num in input.iter() { + if *num > max { + max = *num; } } @@ -386,22 +429,9 @@ fn inner_max(args: Vec) -> f64 { /// Compute the number to a power. pub async fn pow(exec_state: &mut ExecState, args: Args) -> Result { - let nums = args.get_number_array_with_types()?; - if nums.len() > 2 { - return Err(KclError::Type(KclErrorDetails { - message: format!("expected 2 arguments, got {}", nums.len()), - source_ranges: vec![args.source_range], - })); - } - - if nums.len() <= 1 { - return Err(KclError::Type(KclErrorDetails { - message: format!("expected 2 arguments, got {}", nums.len()), - source_ranges: vec![args.source_range], - })); - } - - let result = inner_pow(nums[0].n, nums[1].n)?; + let input: TyF64 = args.get_unlabeled_kw_arg_typed("input", &RuntimeType::num_any(), exec_state)?; + let exp: TyF64 = args.get_kw_arg_typed("exp", &RuntimeType::count(), exec_state)?; + let result = inner_pow(input.n, exp.n); Ok(args.make_user_val_from_f64_with_type(TyF64::new(result, exec_state.current_default_units()))) } @@ -413,7 +443,7 @@ pub async fn pow(exec_state: &mut ExecState, args: Args) -> Result startProfile(at = [0, 0]) /// |> angledLine( /// angle = 50, -/// length = pow(5, 2), +/// length = pow(5, exp = 2), /// ) /// |> yLine(endAbsolute = 0) /// |> close() @@ -423,27 +453,21 @@ pub async fn pow(exec_state: &mut ExecState, args: Args) -> Result Result { - Ok(num.powf(pow)) +fn inner_pow(input: f64, exp: f64) -> f64 { + input.powf(exp) } /// Compute the arccosine of a number (in radians). pub async fn acos(exec_state: &mut ExecState, args: Args) -> Result { - let num = args.get_number_with_type()?; - if matches!( - num.ty, - NumericType::Default { - angle: UnitAngle::Degrees, - .. - } - ) { - exec_state.warn(CompilationError::err( - args.source_range, - "`acos` requires its input in radians, but the input is assumed to be in degrees. You can use a numeric suffix (e.g., `0rad`) or type ascription (e.g., `(1/2): number(rad)`) to show the number is in radians, or `toRadians` to convert from degrees to radians", - )); - } - let result = inner_acos(num.n)?; + let input: TyF64 = args.get_unlabeled_kw_arg_typed("input", &RuntimeType::count(), exec_state)?; + let result = inner_acos(input.n); Ok(args.make_user_val_from_f64_with_type(TyF64::new(result, NumericType::radians()))) } @@ -466,27 +490,20 @@ pub async fn acos(exec_state: &mut ExecState, args: Args) -> Result Result { - Ok(num.acos()) +fn inner_acos(input: f64) -> f64 { + input.acos() } /// Compute the arcsine of a number (in radians). pub async fn asin(exec_state: &mut ExecState, args: Args) -> Result { - let num = args.get_number_with_type()?; - if matches!( - num.ty, - NumericType::Default { - angle: UnitAngle::Degrees, - .. - } - ) { - exec_state.warn(CompilationError::err( - args.source_range, - "`asin` requires its input in radians, but the input is assumed to be in degrees. You can use a numeric suffix (e.g., `0rad`) or type ascription (e.g., `(1/2): number(rad)`) to show the number is in radians, or `toRadians` to convert from degrees to radians", - )); - } - let result = inner_asin(num.n)?; + let input: TyF64 = args.get_unlabeled_kw_arg_typed("input", &RuntimeType::count(), exec_state)?; + let result = inner_asin(input.n); Ok(args.make_user_val_from_f64_with_type(TyF64::new(result, NumericType::radians()))) } @@ -508,33 +525,28 @@ pub async fn asin(exec_state: &mut ExecState, args: Args) -> Result Result { - Ok(num.asin()) +fn inner_asin(input: f64) -> f64 { + input.asin() } /// Compute the arctangent of a number (in radians). pub async fn atan(exec_state: &mut ExecState, args: Args) -> Result { - let num = args.get_number_with_type()?; - if matches!( - num.ty, - NumericType::Default { - angle: UnitAngle::Degrees, - .. - } - ) { - exec_state.warn(CompilationError::err( - args.source_range, - "`atan` requires its input in radians, but the input is assumed to be in degrees. You can use a numeric suffix (e.g., `0rad`) or type ascription (e.g., `(1/2): number(rad)`) to show the number is in radians, or `toRadians` to convert from degrees to radians", - )); - } - let result = inner_atan(num.n)?; + let input: TyF64 = args.get_unlabeled_kw_arg_typed("input", &RuntimeType::count(), exec_state)?; + let result = inner_atan(input.n); Ok(args.make_user_val_from_f64_with_type(TyF64::new(result, NumericType::radians()))) } /// Compute the arctangent of a number (in radians). /// +/// Consider using `atan2()` instead for the true inverse of tangent. +/// /// ```no_run /// sketch001 = startSketchOn('XZ') /// |> startProfile(at = [0, 0]) @@ -550,9 +562,14 @@ pub async fn atan(exec_state: &mut ExecState, args: Args) -> Result Result { - Ok(num.atan()) +fn inner_atan(input: f64) -> f64 { + input.atan() } /// Compute the four quadrant arctangent of Y and X (in radians). @@ -560,7 +577,7 @@ pub async fn atan2(exec_state: &mut ExecState, args: Args) -> Result Result Result { - Ok(y.atan2(x)) +fn inner_atan2(y: f64, x: f64) -> f64 { + y.atan2(x) } /// Compute the logarithm of the number with respect to an arbitrary base. @@ -599,21 +616,9 @@ fn inner_atan2(y: f64, x: f64) -> Result { /// details; `log2()` can produce more accurate results for base 2, /// and `log10()` can produce more accurate results for base 10. pub async fn log(exec_state: &mut ExecState, args: Args) -> Result { - let nums = args.get_number_array_with_types()?; - if nums.len() > 2 { - return Err(KclError::Type(KclErrorDetails { - message: format!("expected 2 arguments, got {}", nums.len()), - source_ranges: vec![args.source_range], - })); - } - - if nums.len() <= 1 { - return Err(KclError::Type(KclErrorDetails { - message: format!("expected 2 arguments, got {}", nums.len()), - source_ranges: vec![args.source_range], - })); - } - let result = inner_log(nums[0].n, nums[1].n)?; + let input: TyF64 = args.get_unlabeled_kw_arg_typed("input", &RuntimeType::num_any(), exec_state)?; + let base: TyF64 = args.get_kw_arg_typed("base", &RuntimeType::count(), exec_state)?; + let result = inner_log(input.n, base.n); Ok(args.make_user_val_from_f64_with_type(TyF64::new(result, exec_state.current_default_units()))) } @@ -627,7 +632,7 @@ pub async fn log(exec_state: &mut ExecState, args: Args) -> Result startProfile(at = [0, 0]) -/// |> line(end = [log(100, 5), 0]) +/// |> line(end = [log(100, base = 5), 0]) /// |> line(end = [5, 8]) /// |> line(end = [-10, 0]) /// |> close() @@ -637,15 +642,21 @@ pub async fn log(exec_state: &mut ExecState, args: Args) -> Result Result { - Ok(num.log(base)) +fn inner_log(input: f64, base: f64) -> f64 { + input.log(base) } /// Compute the base 2 logarithm of the number. pub async fn log2(exec_state: &mut ExecState, args: Args) -> Result { - let num = args.get_number_with_type()?; - let result = inner_log2(num.n)?; + let input: TyF64 = args.get_unlabeled_kw_arg_typed("input", &RuntimeType::num_any(), exec_state)?; + let result = inner_log2(input.n); Ok(args.make_user_val_from_f64_with_type(TyF64::new(result, exec_state.current_default_units()))) } @@ -665,15 +676,20 @@ pub async fn log2(exec_state: &mut ExecState, args: Args) -> Result Result { - Ok(num.log2()) +fn inner_log2(input: f64) -> f64 { + input.log2() } /// Compute the base 10 logarithm of the number. pub async fn log10(exec_state: &mut ExecState, args: Args) -> Result { - let num = args.get_number_with_type()?; - let result = inner_log10(num.n)?; + let input: TyF64 = args.get_unlabeled_kw_arg_typed("input", &RuntimeType::num_any(), exec_state)?; + let result = inner_log10(input.n); Ok(args.make_user_val_from_f64_with_type(TyF64::new(result, exec_state.current_default_units()))) } @@ -694,14 +710,14 @@ pub async fn log10(exec_state: &mut ExecState, args: Args) -> Result Result { - Ok(num.log10()) +fn inner_log10(num: f64) -> f64 { + num.log10() } /// Compute the natural logarithm of the number. pub async fn ln(exec_state: &mut ExecState, args: Args) -> Result { - let num = args.get_number_with_type()?; - let result = inner_ln(num.n)?; + let input: TyF64 = args.get_unlabeled_kw_arg_typed("input", &RuntimeType::num_any(), exec_state)?; + let result = inner_ln(input.n); Ok(args.make_user_val_from_f64_with_type(TyF64::new(result, exec_state.current_default_units()))) } @@ -721,9 +737,14 @@ pub async fn ln(exec_state: &mut ExecState, args: Args) -> Result Result { - Ok(num.ln()) +fn inner_ln(input: f64) -> f64 { + input.ln() } /// Return the value of Euler’s number `e`. diff --git a/rust/kcl-lib/src/std/patterns.rs b/rust/kcl-lib/src/std/patterns.rs index 45f39773a..23941fab4 100644 --- a/rust/kcl-lib/src/std/patterns.rs +++ b/rust/kcl-lib/src/std/patterns.rs @@ -162,7 +162,7 @@ pub async fn pattern_transform_2d(exec_state: &mut ExecState, args: Args) -> Res /// // Move down each time. /// translate = [0, 0, -i * width], /// // Make the cube longer, wider and flatter each time. -/// scale = [pow(1.1, i), pow(1.1, i), pow(0.9, i)], +/// scale = [pow(1.1, exp = i), pow(1.1, exp = i), pow(0.9, exp = i)], /// // Turn by 15 degrees each time. /// rotation = { /// angle = 15 * i, diff --git a/rust/kcl-lib/tests/kcl_samples/food-service-spatula/artifact_graph_flowchart.snap.md b/rust/kcl-lib/tests/kcl_samples/food-service-spatula/artifact_graph_flowchart.snap.md index b185b1b02..8479e289f 100644 --- a/rust/kcl-lib/tests/kcl_samples/food-service-spatula/artifact_graph_flowchart.snap.md +++ b/rust/kcl-lib/tests/kcl_samples/food-service-spatula/artifact_graph_flowchart.snap.md @@ -1,76 +1,76 @@ ```mermaid flowchart LR subgraph path2 [Path] - 2["Path
[1448, 1505, 0]"] - 3["Segment
[1511, 1543, 0]"] - 4["Segment
[1549, 1586, 0]"] - 5["Segment
[1592, 1625, 0]"] - 6["Segment
[1631, 1698, 0]"] - 7["Segment
[1704, 1711, 0]"] + 2["Path
[1460, 1517, 0]"] + 3["Segment
[1523, 1555, 0]"] + 4["Segment
[1561, 1598, 0]"] + 5["Segment
[1604, 1637, 0]"] + 6["Segment
[1643, 1710, 0]"] + 7["Segment
[1716, 1723, 0]"] 8[Solid2d] end subgraph path9 [Path] - 9["Path
[1001, 1045, 0]"] - 10["Segment
[1053, 1093, 0]"] - 11["Segment
[1101, 1147, 0]"] - 12["Segment
[1155, 1196, 0]"] - 13["Segment
[1204, 1269, 0]"] - 14["Segment
[1277, 1284, 0]"] + 9["Path
[1013, 1057, 0]"] + 10["Segment
[1065, 1105, 0]"] + 11["Segment
[1113, 1159, 0]"] + 12["Segment
[1167, 1208, 0]"] + 13["Segment
[1216, 1281, 0]"] + 14["Segment
[1289, 1296, 0]"] 15[Solid2d] end subgraph path16 [Path] - 16["Path
[1001, 1045, 0]"] - 17["Segment
[1053, 1093, 0]"] - 18["Segment
[1101, 1147, 0]"] - 19["Segment
[1155, 1196, 0]"] - 20["Segment
[1204, 1269, 0]"] - 21["Segment
[1277, 1284, 0]"] + 16["Path
[1013, 1057, 0]"] + 17["Segment
[1065, 1105, 0]"] + 18["Segment
[1113, 1159, 0]"] + 19["Segment
[1167, 1208, 0]"] + 20["Segment
[1216, 1281, 0]"] + 21["Segment
[1289, 1296, 0]"] 22[Solid2d] end subgraph path23 [Path] - 23["Path
[1001, 1045, 0]"] - 24["Segment
[1053, 1093, 0]"] - 25["Segment
[1101, 1147, 0]"] - 26["Segment
[1155, 1196, 0]"] - 27["Segment
[1204, 1269, 0]"] - 28["Segment
[1277, 1284, 0]"] + 23["Path
[1013, 1057, 0]"] + 24["Segment
[1065, 1105, 0]"] + 25["Segment
[1113, 1159, 0]"] + 26["Segment
[1167, 1208, 0]"] + 27["Segment
[1216, 1281, 0]"] + 28["Segment
[1289, 1296, 0]"] 29[Solid2d] end subgraph path44 [Path] - 44["Path
[2744, 2800, 0]"] - 45["Segment
[2806, 2865, 0]"] - 46["Segment
[2871, 2906, 0]"] - 47["Segment
[2912, 2945, 0]"] - 48["Segment
[2951, 3010, 0]"] - 49["Segment
[3016, 3052, 0]"] - 50["Segment
[3058, 3082, 0]"] - 51["Segment
[3088, 3095, 0]"] + 44["Path
[2756, 2812, 0]"] + 45["Segment
[2818, 2877, 0]"] + 46["Segment
[2883, 2918, 0]"] + 47["Segment
[2924, 2957, 0]"] + 48["Segment
[2963, 3022, 0]"] + 49["Segment
[3028, 3064, 0]"] + 50["Segment
[3070, 3094, 0]"] + 51["Segment
[3100, 3107, 0]"] 52[Solid2d] end subgraph path71 [Path] - 71["Path
[3690, 3740, 0]"] - 72["Segment
[3746, 3796, 0]"] - 73["Segment
[3802, 3868, 0]"] - 74["Segment
[3874, 3925, 0]"] - 75["Segment
[3931, 3996, 0]"] - 76["Segment
[4002, 4055, 0]"] - 77["Segment
[4061, 4128, 0]"] - 78["Segment
[4134, 4208, 0]"] - 79["Segment
[4214, 4282, 0]"] - 80["Segment
[4288, 4295, 0]"] + 71["Path
[3702, 3752, 0]"] + 72["Segment
[3758, 3808, 0]"] + 73["Segment
[3814, 3880, 0]"] + 74["Segment
[3886, 3937, 0]"] + 75["Segment
[3943, 4008, 0]"] + 76["Segment
[4014, 4067, 0]"] + 77["Segment
[4073, 4140, 0]"] + 78["Segment
[4146, 4220, 0]"] + 79["Segment
[4226, 4294, 0]"] + 80["Segment
[4300, 4307, 0]"] 81[Solid2d] end subgraph path100 [Path] - 100["Path
[1001, 1045, 0]"] - 101["Segment
[1053, 1093, 0]"] - 102["Segment
[1101, 1147, 0]"] - 103["Segment
[1155, 1196, 0]"] - 104["Segment
[1204, 1269, 0]"] - 105["Segment
[1277, 1284, 0]"] + 100["Path
[1013, 1057, 0]"] + 101["Segment
[1065, 1105, 0]"] + 102["Segment
[1113, 1159, 0]"] + 103["Segment
[1167, 1208, 0]"] + 104["Segment
[1216, 1281, 0]"] + 105["Segment
[1289, 1296, 0]"] 106[Solid2d] end - 1["Plane
[1377, 1394, 0]"] - 30["Sweep Extrusion
[2316, 2366, 0]"] + 1["Plane
[1389, 1406, 0]"] + 30["Sweep Extrusion
[2328, 2378, 0]"] 31[Wall] 32[Wall] 33[Wall] @@ -83,8 +83,8 @@ flowchart LR 40["SweepEdge Opposite"] 41["SweepEdge Opposite"] 42["SweepEdge Adjacent"] - 43["Plane
[2641, 2683, 0]"] - 53["Sweep Extrusion
[3129, 3173, 0]"] + 43["Plane
[2653, 2695, 0]"] + 53["Sweep Extrusion
[3141, 3185, 0]"] 54[Wall] 55[Wall] 56[Wall] @@ -101,8 +101,8 @@ flowchart LR 67["SweepEdge Opposite"] 68["SweepEdge Opposite"] 69["SweepEdge Adjacent"] - 70["Plane
[3616, 3642, 0]"] - 82["Sweep Extrusion
[4351, 4393, 0]"] + 70["Plane
[3628, 3654, 0]"] + 82["Sweep Extrusion
[4363, 4405, 0]"] 83[Wall] 84[Wall] 85[Wall] @@ -120,7 +120,7 @@ flowchart LR 97["SweepEdge Opposite"] 98["SweepEdge Opposite"] 99["SweepEdge Opposite"] - 107["Sweep Extrusion
[4628, 4678, 0]"] + 107["Sweep Extrusion
[4640, 4690, 0]"] 108[Wall] 109[Wall] 110[Wall] @@ -128,12 +128,12 @@ flowchart LR 112["SweepEdge Opposite"] 113["SweepEdge Opposite"] 114["SweepEdge Opposite"] - 115["EdgeCut Fillet
[2403, 2544, 0]"] - 116["EdgeCut Fillet
[2403, 2544, 0]"] - 117["EdgeCut Fillet
[3216, 3347, 0]"] - 118["EdgeCut Fillet
[3216, 3347, 0]"] - 119["StartSketchOnPlane
[2627, 2684, 0]"] - 120["StartSketchOnFace
[4452, 4491, 0]"] + 115["EdgeCut Fillet
[2415, 2556, 0]"] + 116["EdgeCut Fillet
[2415, 2556, 0]"] + 117["EdgeCut Fillet
[3228, 3359, 0]"] + 118["EdgeCut Fillet
[3228, 3359, 0]"] + 119["StartSketchOnPlane
[2639, 2696, 0]"] + 120["StartSketchOnFace
[4464, 4503, 0]"] 1 --- 2 1 --- 9 1 --- 16 diff --git a/rust/kcl-lib/tests/kcl_samples/food-service-spatula/ast.snap b/rust/kcl-lib/tests/kcl_samples/food-service-spatula/ast.snap index fd8371014..48324381d 100644 --- a/rust/kcl-lib/tests/kcl_samples/food-service-spatula/ast.snap +++ b/rust/kcl-lib/tests/kcl_samples/food-service-spatula/ast.snap @@ -1109,79 +1109,25 @@ description: Result of parsing food-service-spatula.kcl "left": { "arguments": [ { - "commentStart": 0, - "end": 0, - "left": { + "type": "LabeledArg", + "label": { "commentStart": 0, - "computed": false, "end": 0, - "object": { - "commentStart": 0, - "end": 0, - "name": "end", - "start": 0, - "type": "Identifier", - "type": "Identifier" - }, - "property": { - "commentStart": 0, - "end": 0, - "raw": "1", - "start": 0, - "type": "Literal", - "type": "Literal", - "value": { - "value": 1.0, - "suffix": "None" - } - }, + "name": "exp", "start": 0, - "type": "MemberExpression", - "type": "MemberExpression" + "type": "Identifier" }, - "operator": "-", - "right": { + "arg": { "commentStart": 0, - "computed": false, "end": 0, - "object": { - "commentStart": 0, - "end": 0, - "name": "start", - "start": 0, - "type": "Identifier", - "type": "Identifier" - }, - "property": { - "commentStart": 0, - "end": 0, - "raw": "1", - "start": 0, - "type": "Literal", - "type": "Literal", - "value": { - "value": 1.0, - "suffix": "None" - } - }, + "raw": "2", "start": 0, - "type": "MemberExpression", - "type": "MemberExpression" - }, - "start": 0, - "type": "BinaryExpression", - "type": "BinaryExpression" - }, - { - "commentStart": 0, - "end": 0, - "raw": "2", - "start": 0, - "type": "Literal", - "type": "Literal", - "value": { - "value": 2.0, - "suffix": "None" + "type": "Literal", + "type": "Literal", + "value": { + "value": 2.0, + "suffix": "None" + } } } ], @@ -1203,86 +1149,96 @@ description: Result of parsing food-service-spatula.kcl "commentStart": 0, "end": 0, "start": 0, - "type": "CallExpression", - "type": "CallExpression" + "type": "CallExpressionKw", + "type": "CallExpressionKw", + "unlabeled": { + "commentStart": 0, + "end": 0, + "left": { + "commentStart": 0, + "computed": false, + "end": 0, + "object": { + "commentStart": 0, + "end": 0, + "name": "end", + "start": 0, + "type": "Identifier", + "type": "Identifier" + }, + "property": { + "commentStart": 0, + "end": 0, + "raw": "1", + "start": 0, + "type": "Literal", + "type": "Literal", + "value": { + "value": 1.0, + "suffix": "None" + } + }, + "start": 0, + "type": "MemberExpression", + "type": "MemberExpression" + }, + "operator": "-", + "right": { + "commentStart": 0, + "computed": false, + "end": 0, + "object": { + "commentStart": 0, + "end": 0, + "name": "start", + "start": 0, + "type": "Identifier", + "type": "Identifier" + }, + "property": { + "commentStart": 0, + "end": 0, + "raw": "1", + "start": 0, + "type": "Literal", + "type": "Literal", + "value": { + "value": 1.0, + "suffix": "None" + } + }, + "start": 0, + "type": "MemberExpression", + "type": "MemberExpression" + }, + "start": 0, + "type": "BinaryExpression", + "type": "BinaryExpression" + } }, "operator": "+", "right": { "arguments": [ { - "commentStart": 0, - "end": 0, - "left": { + "type": "LabeledArg", + "label": { "commentStart": 0, - "computed": false, "end": 0, - "object": { - "commentStart": 0, - "end": 0, - "name": "end", - "start": 0, - "type": "Identifier", - "type": "Identifier" - }, - "property": { - "commentStart": 0, - "end": 0, - "raw": "0", - "start": 0, - "type": "Literal", - "type": "Literal", - "value": { - "value": 0.0, - "suffix": "None" - } - }, + "name": "exp", "start": 0, - "type": "MemberExpression", - "type": "MemberExpression" + "type": "Identifier" }, - "operator": "-", - "right": { + "arg": { "commentStart": 0, - "computed": false, "end": 0, - "object": { - "commentStart": 0, - "end": 0, - "name": "start", - "start": 0, - "type": "Identifier", - "type": "Identifier" - }, - "property": { - "commentStart": 0, - "end": 0, - "raw": "0", - "start": 0, - "type": "Literal", - "type": "Literal", - "value": { - "value": 0.0, - "suffix": "None" - } - }, + "raw": "2", "start": 0, - "type": "MemberExpression", - "type": "MemberExpression" - }, - "start": 0, - "type": "BinaryExpression", - "type": "BinaryExpression" - }, - { - "commentStart": 0, - "end": 0, - "raw": "2", - "start": 0, - "type": "Literal", - "type": "Literal", - "value": { - "value": 2.0, - "suffix": "None" + "type": "Literal", + "type": "Literal", + "value": { + "value": 2.0, + "suffix": "None" + } } } ], @@ -1304,8 +1260,72 @@ description: Result of parsing food-service-spatula.kcl "commentStart": 0, "end": 0, "start": 0, - "type": "CallExpression", - "type": "CallExpression" + "type": "CallExpressionKw", + "type": "CallExpressionKw", + "unlabeled": { + "commentStart": 0, + "end": 0, + "left": { + "commentStart": 0, + "computed": false, + "end": 0, + "object": { + "commentStart": 0, + "end": 0, + "name": "end", + "start": 0, + "type": "Identifier", + "type": "Identifier" + }, + "property": { + "commentStart": 0, + "end": 0, + "raw": "0", + "start": 0, + "type": "Literal", + "type": "Literal", + "value": { + "value": 0.0, + "suffix": "None" + } + }, + "start": 0, + "type": "MemberExpression", + "type": "MemberExpression" + }, + "operator": "-", + "right": { + "commentStart": 0, + "computed": false, + "end": 0, + "object": { + "commentStart": 0, + "end": 0, + "name": "start", + "start": 0, + "type": "Identifier", + "type": "Identifier" + }, + "property": { + "commentStart": 0, + "end": 0, + "raw": "0", + "start": 0, + "type": "Literal", + "type": "Literal", + "value": { + "value": 0.0, + "suffix": "None" + } + }, + "start": 0, + "type": "MemberExpression", + "type": "MemberExpression" + }, + "start": 0, + "type": "BinaryExpression", + "type": "BinaryExpression" + } }, "start": 0, "type": "BinaryExpression", diff --git a/rust/kcl-lib/tests/kcl_samples/food-service-spatula/ops.snap b/rust/kcl-lib/tests/kcl_samples/food-service-spatula/ops.snap index 2898ce8d4..d86b1e1c0 100644 --- a/rust/kcl-lib/tests/kcl_samples/food-service-spatula/ops.snap +++ b/rust/kcl-lib/tests/kcl_samples/food-service-spatula/ops.snap @@ -25,7 +25,7 @@ description: Operations executed food-service-spatula.kcl "name": "slot", "functionSourceRange": [ 462, - 1306, + 1318, 0 ], "unlabeledArg": null, @@ -133,7 +133,7 @@ description: Operations executed food-service-spatula.kcl "name": "slot", "functionSourceRange": [ 462, - 1306, + 1318, 0 ], "unlabeledArg": null, @@ -241,7 +241,7 @@ description: Operations executed food-service-spatula.kcl "name": "slot", "functionSourceRange": [ 462, - 1306, + 1318, 0 ], "unlabeledArg": null, @@ -877,7 +877,7 @@ description: Operations executed food-service-spatula.kcl "name": "slot", "functionSourceRange": [ 462, - 1306, + 1318, 0 ], "unlabeledArg": null, diff --git a/rust/kcl-lib/tests/kcl_samples/food-service-spatula/program_memory.snap b/rust/kcl-lib/tests/kcl_samples/food-service-spatula/program_memory.snap index 301d74e0b..899fa8b8e 100644 --- a/rust/kcl-lib/tests/kcl_samples/food-service-spatula/program_memory.snap +++ b/rust/kcl-lib/tests/kcl_samples/food-service-spatula/program_memory.snap @@ -27,9 +27,9 @@ description: Variables in memory after executing food-service-spatula.kcl "id": "[uuid]", "sourceRange": [], "tag": { - "commentStart": 1576, - "end": 1585, - "start": 1576, + "commentStart": 1588, + "end": 1597, + "start": 1588, "type": "TagDeclarator", "value": "backEdge" }, @@ -90,9 +90,9 @@ description: Variables in memory after executing food-service-spatula.kcl -30.0 ], "tag": { - "commentStart": 1576, - "end": 1585, - "start": 1576, + "commentStart": 1588, + "end": 1597, + "start": 1588, "type": "TagDeclarator", "value": "backEdge" }, @@ -299,9 +299,9 @@ description: Variables in memory after executing food-service-spatula.kcl -30.0 ], "tag": { - "commentStart": 1576, - "end": 1585, - "start": 1576, + "commentStart": 1588, + "end": 1597, + "start": 1588, "type": "TagDeclarator", "value": "backEdge" }, @@ -551,9 +551,9 @@ description: Variables in memory after executing food-service-spatula.kcl "id": "[uuid]", "sourceRange": [], "tag": { - "commentStart": 4195, - "end": 4207, - "start": 4195, + "commentStart": 4207, + "end": 4219, + "start": 4207, "type": "TagDeclarator", "value": "gripEdgeTop" }, @@ -713,9 +713,9 @@ description: Variables in memory after executing food-service-spatula.kcl 7.0 ], "tag": { - "commentStart": 4195, - "end": 4207, - "start": 4195, + "commentStart": 4207, + "end": 4219, + "start": 4207, "type": "TagDeclarator", "value": "gripEdgeTop" }, @@ -1058,9 +1058,9 @@ description: Variables in memory after executing food-service-spatula.kcl "id": "[uuid]", "sourceRange": [], "tag": { - "commentStart": 4195, - "end": 4207, - "start": 4195, + "commentStart": 4207, + "end": 4219, + "start": 4207, "type": "TagDeclarator", "value": "gripEdgeTop" }, @@ -1220,9 +1220,9 @@ description: Variables in memory after executing food-service-spatula.kcl 7.0 ], "tag": { - "commentStart": 4195, - "end": 4207, - "start": 4195, + "commentStart": 4207, + "end": 4219, + "start": 4207, "type": "TagDeclarator", "value": "gripEdgeTop" }, @@ -1538,9 +1538,9 @@ description: Variables in memory after executing food-service-spatula.kcl 7.0 ], "tag": { - "commentStart": 4195, - "end": 4207, - "start": 4195, + "commentStart": 4207, + "end": 4219, + "start": 4207, "type": "TagDeclarator", "value": "gripEdgeTop" }, @@ -1729,9 +1729,9 @@ description: Variables in memory after executing food-service-spatula.kcl "id": "[uuid]", "sourceRange": [], "tag": { - "commentStart": 2847, - "end": 2864, - "start": 2847, + "commentStart": 2859, + "end": 2876, + "start": 2859, "type": "TagDeclarator", "value": "handleBottomEdge" }, @@ -1756,9 +1756,9 @@ description: Variables in memory after executing food-service-spatula.kcl "id": "[uuid]", "sourceRange": [], "tag": { - "commentStart": 2995, - "end": 3009, - "start": 2995, + "commentStart": 3007, + "end": 3021, + "start": 3007, "type": "TagDeclarator", "value": "handleTopEdge" }, @@ -1800,9 +1800,9 @@ description: Variables in memory after executing food-service-spatula.kcl 3.5 ], "tag": { - "commentStart": 2847, - "end": 2864, - "start": 2847, + "commentStart": 2859, + "end": 2876, + "start": 2859, "type": "TagDeclarator", "value": "handleBottomEdge" }, @@ -1863,9 +1863,9 @@ description: Variables in memory after executing food-service-spatula.kcl 91.3213 ], "tag": { - "commentStart": 2995, - "end": 3009, - "start": 2995, + "commentStart": 3007, + "end": 3021, + "start": 3007, "type": "TagDeclarator", "value": "handleTopEdge" }, @@ -2211,9 +2211,9 @@ description: Variables in memory after executing food-service-spatula.kcl 3.5 ], "tag": { - "commentStart": 2847, - "end": 2864, - "start": 2847, + "commentStart": 2859, + "end": 2876, + "start": 2859, "type": "TagDeclarator", "value": "handleBottomEdge" }, @@ -2274,9 +2274,9 @@ description: Variables in memory after executing food-service-spatula.kcl 91.3213 ], "tag": { - "commentStart": 2995, - "end": 3009, - "start": 2995, + "commentStart": 3007, + "end": 3021, + "start": 3007, "type": "TagDeclarator", "value": "handleTopEdge" }, @@ -2536,9 +2536,9 @@ description: Variables in memory after executing food-service-spatula.kcl "id": "[uuid]", "sourceRange": [], "tag": { - "commentStart": 4195, - "end": 4207, - "start": 4195, + "commentStart": 4207, + "end": 4219, + "start": 4207, "type": "TagDeclarator", "value": "gripEdgeTop" }, @@ -2698,9 +2698,9 @@ description: Variables in memory after executing food-service-spatula.kcl 7.0 ], "tag": { - "commentStart": 4195, - "end": 4207, - "start": 4195, + "commentStart": 4207, + "end": 4219, + "start": 4207, "type": "TagDeclarator", "value": "gripEdgeTop" }, @@ -3370,9 +3370,9 @@ description: Variables in memory after executing food-service-spatula.kcl -30.0 ], "tag": { - "commentStart": 1576, - "end": 1585, - "start": 1576, + "commentStart": 1588, + "end": 1597, + "start": 1588, "type": "TagDeclarator", "value": "backEdge" }, diff --git a/src/lang/executor.test.ts b/src/lang/executor.test.ts index c40027150..2bb7e2efa 100644 --- a/src/lang/executor.test.ts +++ b/src/lang/executor.test.ts @@ -352,28 +352,28 @@ describe('testing math operators', () => { expect(mem['myVar']?.value).toBe(12.5) }) it('with callExpression at start', async () => { - const code = 'const myVar = min(4, 100) + 2' + const code = 'myVar = min([4, 100]) + 2' const mem = await exe(code) expect(mem['myVar']?.value).toBe(6) }) it('with callExpression at end', async () => { - const code = 'const myVar = 2 + min(4, 100)' + const code = 'myVar = 2 + min([4, 100])' const mem = await exe(code) expect(mem['myVar']?.value).toBe(6) }) it('with nested callExpression', async () => { - const code = 'myVar = 2 + min(100, legLen(hypotenuse = 5, leg = 3))' + const code = 'myVar = 2 + min([100, legLen(hypotenuse = 5, leg = 3)])' const mem = await exe(code) expect(mem['myVar']?.value).toBe(6) }) it('with unaryExpression', async () => { - const code = 'const myVar = -min(100, 3)' + const code = 'myVar = -min([100, 3])' const mem = await exe(code) expect(mem['myVar']?.value).toBe(-3) }) it('with unaryExpression in callExpression', async () => { - const code = 'const myVar = min(-legLen(hypotenuse = 5, leg = 4), 5)' - const code2 = 'const myVar = min(5 , -legLen(hypotenuse = 5, leg = 4))' + const code = 'myVar = min([-legLen(hypotenuse = 5, leg = 4), 5])' + const code2 = 'myVar = min([5 , -legLen(hypotenuse = 5, leg = 4)])' const mem = await exe(code) const mem2 = await exe(code2) expect(mem['myVar']?.value).toBe(-3) @@ -399,11 +399,11 @@ describe('testing math operators', () => { const code = [ 'part001 = startSketchOn(XY)', ' |> startProfile(at = [0, 0])', - '|> line(end = [-2.21, -legLen(hypotenuse = 5, leg = min(3, 999))])', + '|> line(end = [-2.21, -legLen(hypotenuse = 5, leg = min([3, 999]))])', ].join('\n') const mem = await exe(code) const sketch = sketchFromKclValue(mem['part001'], 'part001') - // result of `-legLen(5, min(3, 999))` should be -4 + // result of `-legLen(5, min([3, 999]))` should be -4 const yVal = (sketch as Sketch).paths?.[0]?.to?.[1] expect(yVal).toBe(-4) }) @@ -414,7 +414,7 @@ describe('testing math operators', () => { ` |> startProfile(at = [0, 0])`, ` |> line(end = [3, 4], tag = $seg01)`, ` |> line(end = [`, - ` min(segLen(seg01), myVar),`, + ` min([segLen(seg01), myVar]),`, ` -legLen(hypotenuse = segLen(seg01), leg = myVar)`, `])`, ``, @@ -438,8 +438,7 @@ describe('testing math operators', () => { expect((removedUnaryExpMemSketch as Sketch).paths?.[1]?.to).toEqual([6, 8]) }) it('with nested callExpression and binaryExpression', async () => { - const code = - 'const myVar = 2 + min(100, -1 + legLen(hypotenuse = 5, leg = 3))' + const code = 'myVar = 2 + min([100, -1 + legLen(hypotenuse = 5, leg = 3)])' const mem = await exe(code) expect(mem['myVar']?.value).toBe(5) }) diff --git a/src/lang/recast.test.ts b/src/lang/recast.test.ts index 916e8937a..055d06187 100644 --- a/src/lang/recast.test.ts +++ b/src/lang/recast.test.ts @@ -298,21 +298,21 @@ mySk1 = startSketchOn(XY) describe('testing call Expressions in BinaryExpressions and UnaryExpressions', () => { it('nested callExpression in binaryExpression', () => { - const code = 'myVar = 2 + min(100, legLen(hypotenuse = 5, leg = 3))' + const code = 'myVar = 2 + min([100, legLen(hypotenuse = 5, leg = 3)])' const { ast } = code2ast(code) const recasted = recast(ast) if (err(recasted)) throw recasted expect(recasted.trim()).toBe(code) }) it('nested callExpression in unaryExpression', () => { - const code = 'myVar = -min(100, legLen(hypotenuse = 5, leg = 3))' + const code = 'myVar = -min([100, legLen(hypotenuse = 5, leg = 3)])' const { ast } = code2ast(code) const recasted = recast(ast) if (err(recasted)) throw recasted expect(recasted.trim()).toBe(code) }) it('with unaryExpression in callExpression', () => { - const code = 'myVar = min(5, -legLen(hypotenuse = 5, leg = 4))' + const code = 'myVar = min([5, -legLen(hypotenuse = 5, leg = 4)])' const { ast } = code2ast(code) const recasted = recast(ast) if (err(recasted)) throw recasted @@ -322,7 +322,7 @@ describe('testing call Expressions in BinaryExpressions and UnaryExpressions', ( const code = [ 'part001 = startSketchOn(XY)', ' |> startProfile(at = [0, 0])', - ' |> line(end = [\n -2.21,\n -legLen(hypotenuse = 5, leg = min(3, 999))\n ])', + ' |> line(end = [\n -2.21,\n -legLen(hypotenuse = 5, leg = min([3, 999]))\n ])', ].join('\n') const { ast } = code2ast(code) const recasted = recast(ast) diff --git a/src/lang/std/sketchcombos.test.ts b/src/lang/std/sketchcombos.test.ts index c45a21b16..132ca93b8 100644 --- a/src/lang/std/sketchcombos.test.ts +++ b/src/lang/std/sketchcombos.test.ts @@ -307,31 +307,31 @@ part001 = startSketchOn(XY) |> angledLine(angle = 135, length = segLen(seg01)) // ln-angledLineToY-free should become angledLine |> angledLine(angle = myAng2, length = segLen(seg01)) // ln-angledLineToY-angle should become angledLine |> line(end = [ - min(segLen(seg01), myVar), + min([segLen(seg01), myVar]), legLen(hypotenuse = segLen(seg01), leg = myVar) ]) // ln-should use legLen for y |> line(end = [ - min(segLen(seg01), myVar), + min([segLen(seg01), myVar]), -legLen(hypotenuse = segLen(seg01), leg = myVar) ]) // ln-legLen but negative |> angledLine(angle = -112, length = segLen(seg01)) // ln-should become angledLine |> angledLine(angle = myVar, length = segLen(seg01)) // ln-use segLen for second arg |> angledLine(angle = 45, length = segLen(seg01)) // ln-segLen again |> angledLine(angle = 54, length = segLen(seg01)) // ln-should be transformed to angledLine - |> angledLine(angle = legAngX(segLen(seg01), myVar), lengthX = min(segLen(seg01), myVar)) // ln-should use legAngX to calculate angle - |> angledLine(angle = 180 + legAngX(segLen(seg01), myVar), lengthX = min(segLen(seg01), myVar)) // ln-same as above but should have + 180 to match original quadrant + |> angledLine(angle = legAngX(segLen(seg01), myVar), lengthX = min([segLen(seg01), myVar])) // ln-should use legAngX to calculate angle + |> angledLine(angle = 180 + legAngX(segLen(seg01), myVar), lengthX = min([segLen(seg01), myVar])) // ln-same as above but should have + 180 to match original quadrant |> line(end = [ legLen(hypotenuse = segLen(seg01), leg = myVar), - min(segLen(seg01), myVar) + min([segLen(seg01), myVar]) ]) // ln-legLen again but yRelative |> line(end = [ -legLen(hypotenuse = segLen(seg01), leg = myVar), - min(segLen(seg01), myVar) + min([segLen(seg01), myVar]) ]) // ln-negative legLen yRelative |> angledLine(angle = 58, length = segLen(seg01)) // ln-angledLineOfYLength-free should become angledLine |> angledLine(angle = myAng, length = segLen(seg01)) // ln-angledLineOfYLength-angle should become angledLine - |> angledLine(angle = legAngY(segLen(seg01), myVar), lengthX = min(segLen(seg01), myVar)) // ln-angledLineOfYLength-yRelative use legAngY - |> angledLine(angle = 270 + legAngY(segLen(seg01), myVar), lengthX = min(segLen(seg01), myVar)) // ln-angledLineOfYLength-yRelative with angle > 90 use binExp + |> angledLine(angle = legAngY(segLen(seg01), myVar), lengthX = min([segLen(seg01), myVar])) // ln-angledLineOfYLength-yRelative use legAngY + |> angledLine(angle = 270 + legAngY(segLen(seg01), myVar), lengthX = min([segLen(seg01), myVar])) // ln-angledLineOfYLength-yRelative with angle > 90 use binExp |> xLine(length = segLen(seg01)) // ln-xLine-free should sub in segLen |> yLine(length = segLen(seg01)) // ln-yLine-free should sub in segLen |> xLine(length = segLen(seg01)) // ln-xLineTo-free should convert to xLine diff --git a/src/lang/std/sketchcombos.ts b/src/lang/std/sketchcombos.ts index 0d8d71772..74bf743db 100644 --- a/src/lang/std/sketchcombos.ts +++ b/src/lang/std/sketchcombos.ts @@ -452,7 +452,11 @@ const getMinAndSegLenVals = ( ): [Expr, BinaryPart] => { const segLenVal = createSegLen(referenceSegName) return [ - createCallExpression('min', [segLenVal, varVal]), + createCallExpressionStdLibKw( + 'min', + createArrayExpression([segLenVal, varVal]), + [] + ), createCallExpressionStdLibKw('legLen', null, [ createLabeledArg('hypotenuse', segLenVal), createLabeledArg('leg', varVal), @@ -465,10 +469,11 @@ const getMinAndSegAngVals = ( varVal: Expr, fnName: 'legAngX' | 'legAngY' = 'legAngX' ): [Expr, BinaryPart] => { - const minVal = createCallExpression('min', [ - createSegLen(referenceSegName), - varVal, - ]) + const minVal = createCallExpressionStdLibKw( + 'min', + createArrayExpression([createSegLen(referenceSegName), varVal]), + [] + ) const legAngle = createCallExpression(fnName, [ createSegLen(referenceSegName), varVal,