BREAKING: Migrate math functions to keyword args (#6491)

This commit is contained in:
Jonathan Tran
2025-04-26 19:33:41 -04:00
committed by GitHub
parent d7e80b3cc7
commit 0f88598dc0
32 changed files with 586 additions and 537 deletions

View File

@ -9,7 +9,7 @@ Compute the absolute value of a number.
```js ```js
abs(num: number): number abs(input: number): number
``` ```
### Tags ### Tags
@ -21,7 +21,7 @@ abs(num: number): number
| Name | Type | Description | Required | | 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 ### Returns

View File

@ -9,7 +9,7 @@ Compute the arccosine of a number (in radians).
```js ```js
acos(num: number): number acos(input: number): number
``` ```
### Tags ### Tags
@ -21,7 +21,7 @@ acos(num: number): number
| Name | Type | Description | Required | | 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 ### Returns

View File

@ -9,7 +9,7 @@ Compute the arcsine of a number (in radians).
```js ```js
asin(num: number): number asin(input: number): number
``` ```
### Tags ### Tags
@ -21,7 +21,7 @@ asin(num: number): number
| Name | Type | Description | Required | | 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 ### Returns

View File

@ -6,10 +6,10 @@ layout: manual
Compute the arctangent of a number (in radians). Compute the arctangent of a number (in radians).
Consider using `atan2()` instead for the true inverse of tangent.
```js ```js
atan(num: number): number atan(input: number): number
``` ```
### Tags ### Tags
@ -21,7 +21,7 @@ atan(num: number): number
| Name | Type | Description | Required | | 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 ### Returns

View File

@ -9,7 +9,7 @@ Compute the smallest integer greater than or equal to a number.
```js ```js
ceil(num: number): number ceil(input: number): number
``` ```
### Tags ### Tags
@ -21,7 +21,7 @@ ceil(num: number): number
| Name | Type | Description | Required | | Name | Type | Description | Required |
|----------|------|-------------|----------| |----------|------|-------------|----------|
| `num` | [`number`](/docs/kcl/types/number) | | Yes | | `input` | [`number`](/docs/kcl/types/number) | The number to round. | Yes |
### Returns ### Returns

View File

@ -9,7 +9,7 @@ Compute the largest integer less than or equal to a number.
```js ```js
floor(num: number): number floor(input: number): number
``` ```
### Tags ### Tags
@ -21,7 +21,7 @@ floor(num: number): number
| Name | Type | Description | Required | | Name | Type | Description | Required |
|----------|------|-------------|----------| |----------|------|-------------|----------|
| `num` | [`number`](/docs/kcl/types/number) | | Yes | | `input` | [`number`](/docs/kcl/types/number) | The number to round. | Yes |
### Returns ### Returns

View File

@ -9,7 +9,7 @@ Compute the natural logarithm of the number.
```js ```js
ln(num: number): number ln(input: number): number
``` ```
### Tags ### Tags
@ -21,7 +21,7 @@ ln(num: number): number
| Name | Type | Description | Required | | 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 ### Returns

View File

@ -10,7 +10,7 @@ The result might not be correctly rounded owing to implementation details; `log2
```js ```js
log( log(
num: number, input: number,
base: number, base: number,
): number ): number
``` ```
@ -24,8 +24,8 @@ log(
| Name | Type | Description | Required | | 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 |
| `base` | [`number`](/docs/kcl/types/number) | | Yes | | `base` | [`number`](/docs/kcl/types/number) | The base of the logarithm. | Yes |
### Returns ### Returns
@ -37,7 +37,7 @@ log(
```js ```js
exampleSketch = startSketchOn(XZ) exampleSketch = startSketchOn(XZ)
|> startProfile(at = [0, 0]) |> startProfile(at = [0, 0])
|> line(end = [log(100, 5), 0]) |> line(end = [log(100, base = 5), 0])
|> line(end = [5, 8]) |> line(end = [5, 8])
|> line(end = [-10, 0]) |> line(end = [-10, 0])
|> close() |> close()

View File

@ -9,7 +9,7 @@ Compute the base 2 logarithm of the number.
```js ```js
log2(num: number): number log2(input: number): number
``` ```
### Tags ### Tags
@ -21,7 +21,7 @@ log2(num: number): number
| Name | Type | Description | Required | | 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 ### Returns

View File

@ -9,7 +9,7 @@ Compute the maximum of the given arguments.
```js ```js
max(args: [number]): number max(input: [number]): number
``` ```
### Tags ### Tags
@ -21,7 +21,7 @@ max(args: [number]): number
| Name | Type | Description | Required | | 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 ### Returns
@ -33,7 +33,7 @@ max(args: [number]): number
```js ```js
exampleSketch = startSketchOn(XZ) exampleSketch = startSketchOn(XZ)
|> startProfile(at = [0, 0]) |> 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]) |> line(end = [20, 0])
|> close() |> close()

View File

@ -9,7 +9,7 @@ Compute the minimum of the given arguments.
```js ```js
min(args: [number]): number min(input: [number]): number
``` ```
### Tags ### Tags
@ -21,7 +21,7 @@ min(args: [number]): number
| Name | Type | Description | Required | | 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 ### Returns
@ -33,7 +33,7 @@ min(args: [number]): number
```js ```js
exampleSketch = startSketchOn(XZ) exampleSketch = startSketchOn(XZ)
|> startProfile(at = [0, 0]) |> 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]) |> line(end = [20, 0])
|> close() |> close()

View File

@ -117,7 +117,11 @@ fn transform(i) {
// Move down each time. // Move down each time.
translate = [0, 0, -i * width], translate = [0, 0, -i * width],
// Make the cube longer, wider and flatter each time. // 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. // Turn by 15 degrees each time.
rotation = { angle = 15 * i, origin = "local" } rotation = { angle = 15 * i, origin = "local" }
} }

View File

@ -10,8 +10,8 @@ Compute the number to a power.
```js ```js
pow( pow(
num: number, input: number,
pow: number, exp: number,
): number ): number
``` ```
@ -24,8 +24,8 @@ pow(
| Name | Type | Description | Required | | Name | Type | Description | Required |
|----------|------|-------------|----------| |----------|------|-------------|----------|
| `num` | [`number`](/docs/kcl/types/number) | | Yes | | `input` | [`number`](/docs/kcl/types/number) | The number to raise. | Yes |
| `pow` | [`number`](/docs/kcl/types/number) | | Yes | | `exp` | [`number`](/docs/kcl/types/number) | The power to raise to. | Yes |
### Returns ### Returns
@ -37,7 +37,7 @@ pow(
```js ```js
exampleSketch = startSketchOn(XZ) exampleSketch = startSketchOn(XZ)
|> startProfile(at = [0, 0]) |> startProfile(at = [0, 0])
|> angledLine(angle = 50, length = pow(5, 2)) |> angledLine(angle = 50, length = pow(5, exp = 2))
|> yLine(endAbsolute = 0) |> yLine(endAbsolute = 0)
|> close() |> close()

View File

@ -9,7 +9,7 @@ Round a number to the nearest integer.
```js ```js
round(num: number): number round(input: number): number
``` ```
### Tags ### Tags
@ -21,7 +21,7 @@ round(num: number): number
| Name | Type | Description | Required | | Name | Type | Description | Required |
|----------|------|-------------|----------| |----------|------|-------------|----------|
| `num` | [`number`](/docs/kcl/types/number) | | Yes | | `input` | [`number`](/docs/kcl/types/number) | The number to round. | Yes |
### Returns ### Returns

View File

@ -9,7 +9,7 @@ Compute the square root of a number.
```js ```js
sqrt(num: number): number sqrt(input: number): number
``` ```
### Tags ### Tags
@ -21,7 +21,7 @@ sqrt(num: number): number
| Name | Type | Description | Required | | 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 ### Returns

View File

@ -6,10 +6,10 @@
"tags": [ "tags": [
"math" "math"
], ],
"keywordArguments": false, "keywordArguments": true,
"args": [ "args": [
{ {
"name": "num", "name": "input",
"type": "number", "type": "number",
"schema": { "schema": {
"$schema": "https://spec.openapis.org/oas/3.0/schema/2019-04-02#/definitions/Schema", "$schema": "https://spec.openapis.org/oas/3.0/schema/2019-04-02#/definitions/Schema",
@ -19,7 +19,8 @@
}, },
"required": true, "required": true,
"includeInSnippet": true, "includeInSnippet": true,
"labelRequired": true "description": "The number to compute the absolute value of.",
"labelRequired": false
} }
], ],
"returnValue": { "returnValue": {
@ -48,10 +49,10 @@
"tags": [ "tags": [
"math" "math"
], ],
"keywordArguments": false, "keywordArguments": true,
"args": [ "args": [
{ {
"name": "num", "name": "input",
"type": "number", "type": "number",
"schema": { "schema": {
"$schema": "https://spec.openapis.org/oas/3.0/schema/2019-04-02#/definitions/Schema", "$schema": "https://spec.openapis.org/oas/3.0/schema/2019-04-02#/definitions/Schema",
@ -61,7 +62,8 @@
}, },
"required": true, "required": true,
"includeInSnippet": true, "includeInSnippet": true,
"labelRequired": true "description": "The number to compute arccosine of.",
"labelRequired": false
} }
], ],
"returnValue": { "returnValue": {
@ -45605,10 +45607,10 @@
"tags": [ "tags": [
"math" "math"
], ],
"keywordArguments": false, "keywordArguments": true,
"args": [ "args": [
{ {
"name": "num", "name": "input",
"type": "number", "type": "number",
"schema": { "schema": {
"$schema": "https://spec.openapis.org/oas/3.0/schema/2019-04-02#/definitions/Schema", "$schema": "https://spec.openapis.org/oas/3.0/schema/2019-04-02#/definitions/Schema",
@ -45618,7 +45620,8 @@
}, },
"required": true, "required": true,
"includeInSnippet": true, "includeInSnippet": true,
"labelRequired": true "description": "The number to compute arcsine of.",
"labelRequired": false
} }
], ],
"returnValue": { "returnValue": {
@ -45893,14 +45896,14 @@
{ {
"name": "atan", "name": "atan",
"summary": "Compute the arctangent of a number (in radians).", "summary": "Compute the arctangent of a number (in radians).",
"description": "", "description": "Consider using `atan2()` instead for the true inverse of tangent.",
"tags": [ "tags": [
"math" "math"
], ],
"keywordArguments": false, "keywordArguments": true,
"args": [ "args": [
{ {
"name": "num", "name": "input",
"type": "number", "type": "number",
"schema": { "schema": {
"$schema": "https://spec.openapis.org/oas/3.0/schema/2019-04-02#/definitions/Schema", "$schema": "https://spec.openapis.org/oas/3.0/schema/2019-04-02#/definitions/Schema",
@ -45910,7 +45913,8 @@
}, },
"required": true, "required": true,
"includeInSnippet": true, "includeInSnippet": true,
"labelRequired": true "description": "The number to compute arctangent of.",
"labelRequired": false
} }
], ],
"returnValue": { "returnValue": {
@ -55774,10 +55778,10 @@
"tags": [ "tags": [
"math" "math"
], ],
"keywordArguments": false, "keywordArguments": true,
"args": [ "args": [
{ {
"name": "num", "name": "input",
"type": "number", "type": "number",
"schema": { "schema": {
"$schema": "https://spec.openapis.org/oas/3.0/schema/2019-04-02#/definitions/Schema", "$schema": "https://spec.openapis.org/oas/3.0/schema/2019-04-02#/definitions/Schema",
@ -55787,7 +55791,8 @@
}, },
"required": true, "required": true,
"includeInSnippet": true, "includeInSnippet": true,
"labelRequired": true "description": "The number to round.",
"labelRequired": false
} }
], ],
"returnValue": { "returnValue": {
@ -103470,10 +103475,10 @@
"tags": [ "tags": [
"math" "math"
], ],
"keywordArguments": false, "keywordArguments": true,
"args": [ "args": [
{ {
"name": "num", "name": "input",
"type": "number", "type": "number",
"schema": { "schema": {
"$schema": "https://spec.openapis.org/oas/3.0/schema/2019-04-02#/definitions/Schema", "$schema": "https://spec.openapis.org/oas/3.0/schema/2019-04-02#/definitions/Schema",
@ -103483,7 +103488,8 @@
}, },
"required": true, "required": true,
"includeInSnippet": true, "includeInSnippet": true,
"labelRequired": true "description": "The number to round.",
"labelRequired": false
} }
], ],
"returnValue": { "returnValue": {
@ -136915,10 +136921,10 @@
"tags": [ "tags": [
"math" "math"
], ],
"keywordArguments": false, "keywordArguments": true,
"args": [ "args": [
{ {
"name": "num", "name": "input",
"type": "number", "type": "number",
"schema": { "schema": {
"$schema": "https://spec.openapis.org/oas/3.0/schema/2019-04-02#/definitions/Schema", "$schema": "https://spec.openapis.org/oas/3.0/schema/2019-04-02#/definitions/Schema",
@ -136928,7 +136934,8 @@
}, },
"required": true, "required": true,
"includeInSnippet": true, "includeInSnippet": true,
"labelRequired": true "description": "The number to compute the logarithm of.",
"labelRequired": false
} }
], ],
"returnValue": { "returnValue": {
@ -149898,10 +149905,10 @@
"tags": [ "tags": [
"math" "math"
], ],
"keywordArguments": false, "keywordArguments": true,
"args": [ "args": [
{ {
"name": "num", "name": "input",
"type": "number", "type": "number",
"schema": { "schema": {
"$schema": "https://spec.openapis.org/oas/3.0/schema/2019-04-02#/definitions/Schema", "$schema": "https://spec.openapis.org/oas/3.0/schema/2019-04-02#/definitions/Schema",
@ -149911,7 +149918,8 @@
}, },
"required": true, "required": true,
"includeInSnippet": true, "includeInSnippet": true,
"labelRequired": true "description": "The number to compute the logarithm of.",
"labelRequired": false
}, },
{ {
"name": "base", "name": "base",
@ -149924,6 +149932,7 @@
}, },
"required": true, "required": true,
"includeInSnippet": true, "includeInSnippet": true,
"description": "The base of the logarithm.",
"labelRequired": true "labelRequired": true
} }
], ],
@ -149943,7 +149952,7 @@
"unpublished": false, "unpublished": false,
"deprecated": false, "deprecated": false,
"examples": [ "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": [ "tags": [
"math" "math"
], ],
"keywordArguments": false, "keywordArguments": true,
"args": [ "args": [
{ {
"name": "num", "name": "input",
"type": "number", "type": "number",
"schema": { "schema": {
"$schema": "https://spec.openapis.org/oas/3.0/schema/2019-04-02#/definitions/Schema", "$schema": "https://spec.openapis.org/oas/3.0/schema/2019-04-02#/definitions/Schema",
@ -150008,7 +150017,8 @@
}, },
"required": true, "required": true,
"includeInSnippet": true, "includeInSnippet": true,
"labelRequired": true "description": "The number to compute the logarithm of.",
"labelRequired": false
} }
], ],
"returnValue": { "returnValue": {
@ -157497,10 +157507,10 @@
"tags": [ "tags": [
"math" "math"
], ],
"keywordArguments": false, "keywordArguments": true,
"args": [ "args": [
{ {
"name": "args", "name": "input",
"type": "[number]", "type": "[number]",
"schema": { "schema": {
"$schema": "https://spec.openapis.org/oas/3.0/schema/2019-04-02#/definitions/Schema", "$schema": "https://spec.openapis.org/oas/3.0/schema/2019-04-02#/definitions/Schema",
@ -157513,7 +157523,8 @@
}, },
"required": true, "required": true,
"includeInSnippet": true, "includeInSnippet": true,
"labelRequired": true "description": "An array of numbers to compute the maximum of.",
"labelRequired": false
} }
], ],
"returnValue": { "returnValue": {
@ -157532,7 +157543,7 @@
"unpublished": false, "unpublished": false,
"deprecated": false, "deprecated": false,
"examples": [ "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": [ "tags": [
"math" "math"
], ],
"keywordArguments": false, "keywordArguments": true,
"args": [ "args": [
{ {
"name": "args", "name": "input",
"type": "[number]", "type": "[number]",
"schema": { "schema": {
"$schema": "https://spec.openapis.org/oas/3.0/schema/2019-04-02#/definitions/Schema", "$schema": "https://spec.openapis.org/oas/3.0/schema/2019-04-02#/definitions/Schema",
@ -157558,7 +157569,8 @@
}, },
"required": true, "required": true,
"includeInSnippet": true, "includeInSnippet": true,
"labelRequired": true "description": "An array of numbers to compute the minimum of.",
"labelRequired": false
} }
], ],
"returnValue": { "returnValue": {
@ -157577,7 +157589,7 @@
"unpublished": false, "unpublished": false,
"deprecated": false, "deprecated": false,
"examples": [ "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": [ "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.\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)", "// 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)", "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)", "// 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)" "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": [ "tags": [
"math" "math"
], ],
"keywordArguments": false, "keywordArguments": true,
"args": [ "args": [
{ {
"name": "num", "name": "input",
"type": "number", "type": "number",
"schema": { "schema": {
"$schema": "https://spec.openapis.org/oas/3.0/schema/2019-04-02#/definitions/Schema", "$schema": "https://spec.openapis.org/oas/3.0/schema/2019-04-02#/definitions/Schema",
@ -232213,10 +232225,11 @@
}, },
"required": true, "required": true,
"includeInSnippet": true, "includeInSnippet": true,
"labelRequired": true "description": "The number to raise.",
"labelRequired": false
}, },
{ {
"name": "pow", "name": "exp",
"type": "number", "type": "number",
"schema": { "schema": {
"$schema": "https://spec.openapis.org/oas/3.0/schema/2019-04-02#/definitions/Schema", "$schema": "https://spec.openapis.org/oas/3.0/schema/2019-04-02#/definitions/Schema",
@ -232226,6 +232239,7 @@
}, },
"required": true, "required": true,
"includeInSnippet": true, "includeInSnippet": true,
"description": "The power to raise to.",
"labelRequired": true "labelRequired": true
} }
], ],
@ -232245,7 +232259,7 @@
"unpublished": false, "unpublished": false,
"deprecated": false, "deprecated": false,
"examples": [ "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": [ "tags": [
"math" "math"
], ],
"keywordArguments": false, "keywordArguments": true,
"args": [ "args": [
{ {
"name": "num", "name": "input",
"type": "number", "type": "number",
"schema": { "schema": {
"$schema": "https://spec.openapis.org/oas/3.0/schema/2019-04-02#/definitions/Schema", "$schema": "https://spec.openapis.org/oas/3.0/schema/2019-04-02#/definitions/Schema",
@ -269337,7 +269351,8 @@
}, },
"required": true, "required": true,
"includeInSnippet": true, "includeInSnippet": true,
"labelRequired": true "description": "The number to round.",
"labelRequired": false
} }
], ],
"returnValue": { "returnValue": {
@ -286036,10 +286051,10 @@
"tags": [ "tags": [
"math" "math"
], ],
"keywordArguments": false, "keywordArguments": true,
"args": [ "args": [
{ {
"name": "num", "name": "input",
"type": "number", "type": "number",
"schema": { "schema": {
"$schema": "https://spec.openapis.org/oas/3.0/schema/2019-04-02#/definitions/Schema", "$schema": "https://spec.openapis.org/oas/3.0/schema/2019-04-02#/definitions/Schema",
@ -286049,7 +286064,8 @@
}, },
"required": true, "required": true,
"includeInSnippet": true, "includeInSnippet": true,
"labelRequired": true "description": "The number to compute the square root of.",
"labelRequired": false
} }
], ],
"returnValue": { "returnValue": {

View File

@ -31,7 +31,7 @@ fn slot(sketch1, start, end, width) {
toDegrees( atan((end[1] - start[1]) / (end[0] - start[0]))) 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] xstart = width / 2 * cos(toRadians(angle - 90)) + start[0]
ystart = width / 2 * sin(toRadians(angle - 90)) + start[1] ystart = width / 2 * sin(toRadians(angle - 90)) + start[1]
slotSketch = startProfile(sketch1, at = [xstart, ystart]) slotSketch = startProfile(sketch1, at = [xstart, ystart])

View File

@ -5,7 +5,7 @@
fn cond = (bools) => { fn cond = (bools) => {
return (a, b) => { return (a, b) => {
x = min(max(-1, a-b), 1) + 1 x = min([max([-1, a-b]), 1]) + 1
return bools[x] return bools[x]
} }
} }

View File

@ -1315,7 +1315,7 @@ const part001 = startSketchOn(XY)
|> startProfile(at = [0, 0]) |> startProfile(at = [0, 0])
|> line(end = [3, 4], tag = $seg01) |> line(end = [3, 4], tag = $seg01)
|> line(end = [ |> line(end = [
min(segLen(seg01), myVar), min([segLen(seg01), myVar]),
-legLen(hypotenuse = segLen(seg01), leg = myVar) -legLen(hypotenuse = segLen(seg01), leg = myVar)
]) ])
"#; "#;
@ -1330,7 +1330,7 @@ const part001 = startSketchOn(XY)
|> startProfile(at = [0, 0]) |> startProfile(at = [0, 0])
|> line(end = [3, 4], tag = $seg01) |> line(end = [3, 4], tag = $seg01)
|> line(end = [ |> line(end = [
min(segLen(seg01), myVar), min([segLen(seg01), myVar]),
legLen(hypotenuse = segLen(seg01), leg = myVar) legLen(hypotenuse = segLen(seg01), leg = myVar)
]) ])
"#; "#;
@ -1723,7 +1723,7 @@ let shape = layer() |> patternTransform(instances = 10, transform = transform)
#[tokio::test(flavor = "multi_thread")] #[tokio::test(flavor = "multi_thread")]
async fn test_math_execute_with_functions() { 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(); let result = parse_execute(ast).await.unwrap();
assert_eq!( assert_eq!(
5.0, 5.0,

View File

@ -2054,10 +2054,10 @@ o = 3mm / 3
p = 3_ / 4 p = 3_ / 4
q = 4inch / 2_ q = 4inch / 2_
r = min(0, 3, 42) r = min([0, 3, 42])
s = min(0, 3mm, -42) s = min([0, 3mm, -42])
t = min(100, 3in, 142mm) t = min([100, 3in, 142mm])
u = min(3rad, 4in) u = min([3rad, 4in])
"#; "#;
let result = parse_execute(program).await.unwrap(); let result = parse_execute(program).await.unwrap();

View File

@ -3683,7 +3683,7 @@ fn ghi = (x) => {
#[test] #[test]
fn test_ast_in_comment() { 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 const h = 30
// st // st
@ -3703,7 +3703,7 @@ const cylinder = startSketchOn('-XZ')
#[test] #[test]
fn test_ast_in_comment_pipe() { 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 const h = 30
// st // st

View File

@ -598,23 +598,6 @@ impl Args {
Ok(TyF64::from_kcl_val(&arg.value).unwrap().n) Ok(TyF64::from_kcl_val(&arg.value).unwrap().n)
} }
pub(crate) fn get_number_array_with_types(&self) -> Result<Vec<TyF64>, KclError> {
let numbers = self
.args
.iter()
.map(|arg| {
let Some(num) = <TyF64>::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::<Result<_, _>>()?;
Ok(numbers)
}
pub(crate) async fn get_adjacent_face_to_tag( pub(crate) async fn get_adjacent_face_to_tag(
&self, &self,
exec_state: &mut ExecState, 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!(crate::execution::Metadata);
impl_from_kcl_for_vec!(super::fillet::EdgeReference); impl_from_kcl_for_vec!(super::fillet::EdgeReference);
impl_from_kcl_for_vec!(ExtrudeSurface); impl_from_kcl_for_vec!(ExtrudeSurface);
impl_from_kcl_for_vec!(TyF64);
impl<'a> FromKclValue<'a> for SourceRange { impl<'a> FromKclValue<'a> for SourceRange {
fn from_kcl_val(arg: &'a KclValue) -> Option<Self> { fn from_kcl_val(arg: &'a KclValue) -> Option<Self> {

View File

@ -4,9 +4,9 @@ use anyhow::Result;
use kcl_derive_docs::stdlib; use kcl_derive_docs::stdlib;
use crate::{ use crate::{
errors::{KclError, KclErrorDetails}, errors::KclError,
execution::{ execution::{
types::{NumericType, RuntimeType, UnitAngle, UnitType}, types::{ArrayLen, NumericType, RuntimeType, UnitAngle, UnitType},
ExecState, KclValue, ExecState, KclValue,
}, },
std::args::{Args, TyF64}, std::args::{Args, TyF64},
@ -147,8 +147,8 @@ fn inner_pi() -> Result<f64, KclError> {
/// Compute the square root of a number. /// Compute the square root of a number.
pub async fn sqrt(exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> { pub async fn sqrt(exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
let num = args.get_number_with_type()?; let input: TyF64 = args.get_unlabeled_kw_arg_typed("input", &RuntimeType::num_any(), exec_state)?;
let result = inner_sqrt(num.n)?; let result = inner_sqrt(input.n);
Ok(args.make_user_val_from_f64_with_type(TyF64::new(result, exec_state.current_default_units()))) 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<KclValue, Kc
#[stdlib { #[stdlib {
name = "sqrt", name = "sqrt",
tags = ["math"], tags = ["math"],
keywords = true,
unlabeled_first = true,
args = {
input = {docs = "The number to compute the square root of."},
}
}] }]
fn inner_sqrt(num: f64) -> Result<f64, KclError> { fn inner_sqrt(input: f64) -> f64 {
Ok(num.sqrt()) input.sqrt()
} }
/// Compute the absolute value of a number. /// Compute the absolute value of a number.
pub async fn abs(_exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> { pub async fn abs(exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
let num = args.get_number_with_type()?; let input: TyF64 = args.get_unlabeled_kw_arg_typed("input", &RuntimeType::num_any(), exec_state)?;
let result = inner_abs(num.n)?; 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. /// Compute the absolute value of a number.
@ -207,17 +212,22 @@ pub async fn abs(_exec_state: &mut ExecState, args: Args) -> Result<KclValue, Kc
#[stdlib { #[stdlib {
name = "abs", name = "abs",
tags = ["math"], tags = ["math"],
keywords = true,
unlabeled_first = true,
args = {
input = {docs = "The number to compute the absolute value of."},
}
}] }]
fn inner_abs(num: f64) -> Result<f64, KclError> { fn inner_abs(input: f64) -> f64 {
Ok(num.abs()) input.abs()
} }
/// Round a number to the nearest integer. /// Round a number to the nearest integer.
pub async fn round(_exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> { pub async fn round(exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
let num = args.get_number_with_type()?; let input: TyF64 = args.get_unlabeled_kw_arg_typed("input", &RuntimeType::num_any(), exec_state)?;
let result = inner_round(num.n)?; 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. /// Round a number to the nearest integer.
@ -235,17 +245,22 @@ pub async fn round(_exec_state: &mut ExecState, args: Args) -> Result<KclValue,
#[stdlib { #[stdlib {
name = "round", name = "round",
tags = ["math"], tags = ["math"],
keywords = true,
unlabeled_first = true,
args = {
input = {docs = "The number to round."},
}
}] }]
fn inner_round(num: f64) -> Result<f64, KclError> { fn inner_round(input: f64) -> f64 {
Ok(num.round()) input.round()
} }
/// Compute the largest integer less than or equal to a number. /// Compute the largest integer less than or equal to a number.
pub async fn floor(_exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> { pub async fn floor(exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
let num = args.get_number_with_type()?; let input: TyF64 = args.get_unlabeled_kw_arg_typed("input", &RuntimeType::num_any(), exec_state)?;
let result = inner_floor(num.n)?; 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. /// 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<KclValue,
#[stdlib { #[stdlib {
name = "floor", name = "floor",
tags = ["math"], tags = ["math"],
keywords = true,
unlabeled_first = true,
args = {
input = {docs = "The number to round."},
}
}] }]
fn inner_floor(num: f64) -> Result<f64, KclError> { fn inner_floor(input: f64) -> f64 {
Ok(num.floor()) input.floor()
} }
/// Compute the smallest integer greater than or equal to a number. /// Compute the smallest integer greater than or equal to a number.
pub async fn ceil(_exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> { pub async fn ceil(exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
let num = args.get_number_with_type()?; let input: TyF64 = args.get_unlabeled_kw_arg_typed("input", &RuntimeType::num_any(), exec_state)?;
let result = inner_ceil(num.n)?; 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. /// 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<KclValue, K
#[stdlib { #[stdlib {
name = "ceil", name = "ceil",
tags = ["math"], tags = ["math"],
keywords = true,
unlabeled_first = true,
args = {
input = {docs = "The number to round."},
}
}] }]
fn inner_ceil(num: f64) -> Result<f64, KclError> { fn inner_ceil(input: f64) -> f64 {
Ok(num.ceil()) input.ceil()
} }
/// Compute the minimum of the given arguments. /// Compute the minimum of the given arguments.
pub async fn min(exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> { pub async fn min(exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
let nums = args.get_number_array_with_types()?; let nums: Vec<TyF64> = 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); let (nums, ty) = NumericType::combine_eq_array(&nums);
if ty == NumericType::Unknown { if ty == NumericType::Unknown {
exec_state.warn(CompilationError::err( exec_state.warn(CompilationError::err(
@ -318,7 +347,7 @@ pub async fn min(exec_state: &mut ExecState, args: Args) -> Result<KclValue, Kcl
/// |> startProfile(at = [0, 0]) /// |> startProfile(at = [0, 0])
/// |> angledLine( /// |> angledLine(
/// angle = 70, /// angle = 70,
/// length = min(15, 31, 4, 13, 22) /// length = min([15, 31, 4, 13, 22])
/// ) /// )
/// |> line(end = [20, 0]) /// |> line(end = [20, 0])
/// |> close() /// |> close()
@ -328,12 +357,17 @@ pub async fn min(exec_state: &mut ExecState, args: Args) -> Result<KclValue, Kcl
#[stdlib { #[stdlib {
name = "min", name = "min",
tags = ["math"], tags = ["math"],
keywords = true,
unlabeled_first = true,
args = {
input = {docs = "An array of numbers to compute the minimum of."},
}
}] }]
fn inner_min(args: Vec<f64>) -> f64 { fn inner_min(input: Vec<f64>) -> f64 {
let mut min = f64::MAX; let mut min = f64::MAX;
for arg in args.iter() { for num in input.iter() {
if *arg < min { if *num < min {
min = *arg; min = *num;
} }
} }
@ -342,7 +376,11 @@ fn inner_min(args: Vec<f64>) -> f64 {
/// Compute the maximum of the given arguments. /// Compute the maximum of the given arguments.
pub async fn max(exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> { pub async fn max(exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
let nums = args.get_number_array_with_types()?; let nums: Vec<TyF64> = 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); let (nums, ty) = NumericType::combine_eq_array(&nums);
if ty == NumericType::Unknown { if ty == NumericType::Unknown {
exec_state.warn(CompilationError::err( exec_state.warn(CompilationError::err(
@ -362,7 +400,7 @@ pub async fn max(exec_state: &mut ExecState, args: Args) -> Result<KclValue, Kcl
/// |> startProfile(at = [0, 0]) /// |> startProfile(at = [0, 0])
/// |> angledLine( /// |> angledLine(
/// angle = 70, /// angle = 70,
/// length = max(15, 31, 4, 13, 22) /// length = max([15, 31, 4, 13, 22])
/// ) /// )
/// |> line(end = [20, 0]) /// |> line(end = [20, 0])
/// |> close() /// |> close()
@ -372,12 +410,17 @@ pub async fn max(exec_state: &mut ExecState, args: Args) -> Result<KclValue, Kcl
#[stdlib { #[stdlib {
name = "max", name = "max",
tags = ["math"], tags = ["math"],
keywords = true,
unlabeled_first = true,
args = {
input = {docs = "An array of numbers to compute the maximum of."},
}
}] }]
fn inner_max(args: Vec<f64>) -> f64 { fn inner_max(input: Vec<f64>) -> f64 {
let mut max = f64::MIN; let mut max = f64::MIN;
for arg in args.iter() { for num in input.iter() {
if *arg > max { if *num > max {
max = *arg; max = *num;
} }
} }
@ -386,22 +429,9 @@ fn inner_max(args: Vec<f64>) -> f64 {
/// Compute the number to a power. /// Compute the number to a power.
pub async fn pow(exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> { pub async fn pow(exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
let nums = args.get_number_array_with_types()?; let input: TyF64 = args.get_unlabeled_kw_arg_typed("input", &RuntimeType::num_any(), exec_state)?;
if nums.len() > 2 { let exp: TyF64 = args.get_kw_arg_typed("exp", &RuntimeType::count(), exec_state)?;
return Err(KclError::Type(KclErrorDetails { let result = inner_pow(input.n, exp.n);
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)?;
Ok(args.make_user_val_from_f64_with_type(TyF64::new(result, exec_state.current_default_units()))) 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<KclValue, Kcl
/// |> startProfile(at = [0, 0]) /// |> startProfile(at = [0, 0])
/// |> angledLine( /// |> angledLine(
/// angle = 50, /// angle = 50,
/// length = pow(5, 2), /// length = pow(5, exp = 2),
/// ) /// )
/// |> yLine(endAbsolute = 0) /// |> yLine(endAbsolute = 0)
/// |> close() /// |> close()
@ -423,27 +453,21 @@ pub async fn pow(exec_state: &mut ExecState, args: Args) -> Result<KclValue, Kcl
#[stdlib { #[stdlib {
name = "pow", name = "pow",
tags = ["math"], tags = ["math"],
keywords = true,
unlabeled_first = true,
args = {
input = {docs = "The number to raise."},
exp = {docs = "The power to raise to."},
}
}] }]
fn inner_pow(num: f64, pow: f64) -> Result<f64, KclError> { fn inner_pow(input: f64, exp: f64) -> f64 {
Ok(num.powf(pow)) input.powf(exp)
} }
/// Compute the arccosine of a number (in radians). /// Compute the arccosine of a number (in radians).
pub async fn acos(exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> { pub async fn acos(exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
let num = args.get_number_with_type()?; let input: TyF64 = args.get_unlabeled_kw_arg_typed("input", &RuntimeType::count(), exec_state)?;
if matches!( let result = inner_acos(input.n);
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)?;
Ok(args.make_user_val_from_f64_with_type(TyF64::new(result, NumericType::radians()))) 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<KclValue, Kc
#[stdlib { #[stdlib {
name = "acos", name = "acos",
tags = ["math"], tags = ["math"],
keywords = true,
unlabeled_first = true,
args = {
input = {docs = "The number to compute arccosine of."},
}
}] }]
fn inner_acos(num: f64) -> Result<f64, KclError> { fn inner_acos(input: f64) -> f64 {
Ok(num.acos()) input.acos()
} }
/// Compute the arcsine of a number (in radians). /// Compute the arcsine of a number (in radians).
pub async fn asin(exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> { pub async fn asin(exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
let num = args.get_number_with_type()?; let input: TyF64 = args.get_unlabeled_kw_arg_typed("input", &RuntimeType::count(), exec_state)?;
if matches!( let result = inner_asin(input.n);
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)?;
Ok(args.make_user_val_from_f64_with_type(TyF64::new(result, NumericType::radians()))) 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<KclValue, Kc
#[stdlib { #[stdlib {
name = "asin", name = "asin",
tags = ["math"], tags = ["math"],
keywords = true,
unlabeled_first = true,
args = {
input = {docs = "The number to compute arcsine of."},
}
}] }]
fn inner_asin(num: f64) -> Result<f64, KclError> { fn inner_asin(input: f64) -> f64 {
Ok(num.asin()) input.asin()
} }
/// Compute the arctangent of a number (in radians). /// Compute the arctangent of a number (in radians).
pub async fn atan(exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> { pub async fn atan(exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
let num = args.get_number_with_type()?; let input: TyF64 = args.get_unlabeled_kw_arg_typed("input", &RuntimeType::count(), exec_state)?;
if matches!( let result = inner_atan(input.n);
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)?;
Ok(args.make_user_val_from_f64_with_type(TyF64::new(result, NumericType::radians()))) Ok(args.make_user_val_from_f64_with_type(TyF64::new(result, NumericType::radians())))
} }
/// Compute the arctangent of a number (in radians). /// Compute the arctangent of a number (in radians).
/// ///
/// Consider using `atan2()` instead for the true inverse of tangent.
///
/// ```no_run /// ```no_run
/// sketch001 = startSketchOn('XZ') /// sketch001 = startSketchOn('XZ')
/// |> startProfile(at = [0, 0]) /// |> startProfile(at = [0, 0])
@ -550,9 +562,14 @@ pub async fn atan(exec_state: &mut ExecState, args: Args) -> Result<KclValue, Kc
#[stdlib { #[stdlib {
name = "atan", name = "atan",
tags = ["math"], tags = ["math"],
keywords = true,
unlabeled_first = true,
args = {
input = {docs = "The number to compute arctangent of."},
}
}] }]
fn inner_atan(num: f64) -> Result<f64, KclError> { fn inner_atan(input: f64) -> f64 {
Ok(num.atan()) input.atan()
} }
/// Compute the four quadrant arctangent of Y and X (in radians). /// 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<KclValue, K
let y = args.get_kw_arg_typed("y", &RuntimeType::length(), exec_state)?; let y = args.get_kw_arg_typed("y", &RuntimeType::length(), exec_state)?;
let x = args.get_kw_arg_typed("x", &RuntimeType::length(), exec_state)?; let x = args.get_kw_arg_typed("x", &RuntimeType::length(), exec_state)?;
let (y, x, _) = NumericType::combine_eq_coerce(y, x); let (y, x, _) = NumericType::combine_eq_coerce(y, x);
let result = inner_atan2(y, x)?; let result = inner_atan2(y, x);
Ok(args.make_user_val_from_f64_with_type(TyF64::new(result, NumericType::radians()))) Ok(args.make_user_val_from_f64_with_type(TyF64::new(result, NumericType::radians())))
} }
@ -589,8 +606,8 @@ pub async fn atan2(exec_state: &mut ExecState, args: Args) -> Result<KclValue, K
x = { docs = "X"}, x = { docs = "X"},
} }
}] }]
fn inner_atan2(y: f64, x: f64) -> Result<f64, KclError> { fn inner_atan2(y: f64, x: f64) -> f64 {
Ok(y.atan2(x)) y.atan2(x)
} }
/// Compute the logarithm of the number with respect to an arbitrary base. /// Compute the logarithm of the number with respect to an arbitrary base.
@ -599,21 +616,9 @@ fn inner_atan2(y: f64, x: f64) -> Result<f64, KclError> {
/// details; `log2()` can produce more accurate results for base 2, /// details; `log2()` can produce more accurate results for base 2,
/// and `log10()` can produce more accurate results for base 10. /// and `log10()` can produce more accurate results for base 10.
pub async fn log(exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> { pub async fn log(exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
let nums = args.get_number_array_with_types()?; let input: TyF64 = args.get_unlabeled_kw_arg_typed("input", &RuntimeType::num_any(), exec_state)?;
if nums.len() > 2 { let base: TyF64 = args.get_kw_arg_typed("base", &RuntimeType::count(), exec_state)?;
return Err(KclError::Type(KclErrorDetails { let result = inner_log(input.n, base.n);
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)?;
Ok(args.make_user_val_from_f64_with_type(TyF64::new(result, exec_state.current_default_units()))) 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<KclValue, Kcl
/// ```no_run /// ```no_run
/// exampleSketch = startSketchOn("XZ") /// exampleSketch = startSketchOn("XZ")
/// |> startProfile(at = [0, 0]) /// |> startProfile(at = [0, 0])
/// |> line(end = [log(100, 5), 0]) /// |> line(end = [log(100, base = 5), 0])
/// |> line(end = [5, 8]) /// |> line(end = [5, 8])
/// |> line(end = [-10, 0]) /// |> line(end = [-10, 0])
/// |> close() /// |> close()
@ -637,15 +642,21 @@ pub async fn log(exec_state: &mut ExecState, args: Args) -> Result<KclValue, Kcl
#[stdlib { #[stdlib {
name = "log", name = "log",
tags = ["math"], tags = ["math"],
keywords = true,
unlabeled_first = true,
args = {
input = {docs = "The number to compute the logarithm of."},
base = {docs = "The base of the logarithm."},
}
}] }]
fn inner_log(num: f64, base: f64) -> Result<f64, KclError> { fn inner_log(input: f64, base: f64) -> f64 {
Ok(num.log(base)) input.log(base)
} }
/// Compute the base 2 logarithm of the number. /// Compute the base 2 logarithm of the number.
pub async fn log2(exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> { pub async fn log2(exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
let num = args.get_number_with_type()?; let input: TyF64 = args.get_unlabeled_kw_arg_typed("input", &RuntimeType::num_any(), exec_state)?;
let result = inner_log2(num.n)?; let result = inner_log2(input.n);
Ok(args.make_user_val_from_f64_with_type(TyF64::new(result, exec_state.current_default_units()))) 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<KclValue, Kc
#[stdlib { #[stdlib {
name = "log2", name = "log2",
tags = ["math"], tags = ["math"],
keywords = true,
unlabeled_first = true,
args = {
input = {docs = "The number to compute the logarithm of."},
}
}] }]
fn inner_log2(num: f64) -> Result<f64, KclError> { fn inner_log2(input: f64) -> f64 {
Ok(num.log2()) input.log2()
} }
/// Compute the base 10 logarithm of the number. /// Compute the base 10 logarithm of the number.
pub async fn log10(exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> { pub async fn log10(exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
let num = args.get_number_with_type()?; let input: TyF64 = args.get_unlabeled_kw_arg_typed("input", &RuntimeType::num_any(), exec_state)?;
let result = inner_log10(num.n)?; let result = inner_log10(input.n);
Ok(args.make_user_val_from_f64_with_type(TyF64::new(result, exec_state.current_default_units()))) 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<KclValue, K
name = "log10", name = "log10",
tags = ["math"], tags = ["math"],
}] }]
fn inner_log10(num: f64) -> Result<f64, KclError> { fn inner_log10(num: f64) -> f64 {
Ok(num.log10()) num.log10()
} }
/// Compute the natural logarithm of the number. /// Compute the natural logarithm of the number.
pub async fn ln(exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> { pub async fn ln(exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
let num = args.get_number_with_type()?; let input: TyF64 = args.get_unlabeled_kw_arg_typed("input", &RuntimeType::num_any(), exec_state)?;
let result = inner_ln(num.n)?; let result = inner_ln(input.n);
Ok(args.make_user_val_from_f64_with_type(TyF64::new(result, exec_state.current_default_units()))) 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<KclValue, KclE
#[stdlib { #[stdlib {
name = "ln", name = "ln",
tags = ["math"], tags = ["math"],
keywords = true,
unlabeled_first = true,
args = {
input = {docs = "The number to compute the logarithm of."},
}
}] }]
fn inner_ln(num: f64) -> Result<f64, KclError> { fn inner_ln(input: f64) -> f64 {
Ok(num.ln()) input.ln()
} }
/// Return the value of Eulers number `e`. /// Return the value of Eulers number `e`.

View File

@ -162,7 +162,7 @@ pub async fn pattern_transform_2d(exec_state: &mut ExecState, args: Args) -> Res
/// // Move down each time. /// // Move down each time.
/// translate = [0, 0, -i * width], /// translate = [0, 0, -i * width],
/// // Make the cube longer, wider and flatter each time. /// // 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. /// // Turn by 15 degrees each time.
/// rotation = { /// rotation = {
/// angle = 15 * i, /// angle = 15 * i,

View File

@ -1,76 +1,76 @@
```mermaid ```mermaid
flowchart LR flowchart LR
subgraph path2 [Path] subgraph path2 [Path]
2["Path<br>[1448, 1505, 0]"] 2["Path<br>[1460, 1517, 0]"]
3["Segment<br>[1511, 1543, 0]"] 3["Segment<br>[1523, 1555, 0]"]
4["Segment<br>[1549, 1586, 0]"] 4["Segment<br>[1561, 1598, 0]"]
5["Segment<br>[1592, 1625, 0]"] 5["Segment<br>[1604, 1637, 0]"]
6["Segment<br>[1631, 1698, 0]"] 6["Segment<br>[1643, 1710, 0]"]
7["Segment<br>[1704, 1711, 0]"] 7["Segment<br>[1716, 1723, 0]"]
8[Solid2d] 8[Solid2d]
end end
subgraph path9 [Path] subgraph path9 [Path]
9["Path<br>[1001, 1045, 0]"] 9["Path<br>[1013, 1057, 0]"]
10["Segment<br>[1053, 1093, 0]"] 10["Segment<br>[1065, 1105, 0]"]
11["Segment<br>[1101, 1147, 0]"] 11["Segment<br>[1113, 1159, 0]"]
12["Segment<br>[1155, 1196, 0]"] 12["Segment<br>[1167, 1208, 0]"]
13["Segment<br>[1204, 1269, 0]"] 13["Segment<br>[1216, 1281, 0]"]
14["Segment<br>[1277, 1284, 0]"] 14["Segment<br>[1289, 1296, 0]"]
15[Solid2d] 15[Solid2d]
end end
subgraph path16 [Path] subgraph path16 [Path]
16["Path<br>[1001, 1045, 0]"] 16["Path<br>[1013, 1057, 0]"]
17["Segment<br>[1053, 1093, 0]"] 17["Segment<br>[1065, 1105, 0]"]
18["Segment<br>[1101, 1147, 0]"] 18["Segment<br>[1113, 1159, 0]"]
19["Segment<br>[1155, 1196, 0]"] 19["Segment<br>[1167, 1208, 0]"]
20["Segment<br>[1204, 1269, 0]"] 20["Segment<br>[1216, 1281, 0]"]
21["Segment<br>[1277, 1284, 0]"] 21["Segment<br>[1289, 1296, 0]"]
22[Solid2d] 22[Solid2d]
end end
subgraph path23 [Path] subgraph path23 [Path]
23["Path<br>[1001, 1045, 0]"] 23["Path<br>[1013, 1057, 0]"]
24["Segment<br>[1053, 1093, 0]"] 24["Segment<br>[1065, 1105, 0]"]
25["Segment<br>[1101, 1147, 0]"] 25["Segment<br>[1113, 1159, 0]"]
26["Segment<br>[1155, 1196, 0]"] 26["Segment<br>[1167, 1208, 0]"]
27["Segment<br>[1204, 1269, 0]"] 27["Segment<br>[1216, 1281, 0]"]
28["Segment<br>[1277, 1284, 0]"] 28["Segment<br>[1289, 1296, 0]"]
29[Solid2d] 29[Solid2d]
end end
subgraph path44 [Path] subgraph path44 [Path]
44["Path<br>[2744, 2800, 0]"] 44["Path<br>[2756, 2812, 0]"]
45["Segment<br>[2806, 2865, 0]"] 45["Segment<br>[2818, 2877, 0]"]
46["Segment<br>[2871, 2906, 0]"] 46["Segment<br>[2883, 2918, 0]"]
47["Segment<br>[2912, 2945, 0]"] 47["Segment<br>[2924, 2957, 0]"]
48["Segment<br>[2951, 3010, 0]"] 48["Segment<br>[2963, 3022, 0]"]
49["Segment<br>[3016, 3052, 0]"] 49["Segment<br>[3028, 3064, 0]"]
50["Segment<br>[3058, 3082, 0]"] 50["Segment<br>[3070, 3094, 0]"]
51["Segment<br>[3088, 3095, 0]"] 51["Segment<br>[3100, 3107, 0]"]
52[Solid2d] 52[Solid2d]
end end
subgraph path71 [Path] subgraph path71 [Path]
71["Path<br>[3690, 3740, 0]"] 71["Path<br>[3702, 3752, 0]"]
72["Segment<br>[3746, 3796, 0]"] 72["Segment<br>[3758, 3808, 0]"]
73["Segment<br>[3802, 3868, 0]"] 73["Segment<br>[3814, 3880, 0]"]
74["Segment<br>[3874, 3925, 0]"] 74["Segment<br>[3886, 3937, 0]"]
75["Segment<br>[3931, 3996, 0]"] 75["Segment<br>[3943, 4008, 0]"]
76["Segment<br>[4002, 4055, 0]"] 76["Segment<br>[4014, 4067, 0]"]
77["Segment<br>[4061, 4128, 0]"] 77["Segment<br>[4073, 4140, 0]"]
78["Segment<br>[4134, 4208, 0]"] 78["Segment<br>[4146, 4220, 0]"]
79["Segment<br>[4214, 4282, 0]"] 79["Segment<br>[4226, 4294, 0]"]
80["Segment<br>[4288, 4295, 0]"] 80["Segment<br>[4300, 4307, 0]"]
81[Solid2d] 81[Solid2d]
end end
subgraph path100 [Path] subgraph path100 [Path]
100["Path<br>[1001, 1045, 0]"] 100["Path<br>[1013, 1057, 0]"]
101["Segment<br>[1053, 1093, 0]"] 101["Segment<br>[1065, 1105, 0]"]
102["Segment<br>[1101, 1147, 0]"] 102["Segment<br>[1113, 1159, 0]"]
103["Segment<br>[1155, 1196, 0]"] 103["Segment<br>[1167, 1208, 0]"]
104["Segment<br>[1204, 1269, 0]"] 104["Segment<br>[1216, 1281, 0]"]
105["Segment<br>[1277, 1284, 0]"] 105["Segment<br>[1289, 1296, 0]"]
106[Solid2d] 106[Solid2d]
end end
1["Plane<br>[1377, 1394, 0]"] 1["Plane<br>[1389, 1406, 0]"]
30["Sweep Extrusion<br>[2316, 2366, 0]"] 30["Sweep Extrusion<br>[2328, 2378, 0]"]
31[Wall] 31[Wall]
32[Wall] 32[Wall]
33[Wall] 33[Wall]
@ -83,8 +83,8 @@ flowchart LR
40["SweepEdge Opposite"] 40["SweepEdge Opposite"]
41["SweepEdge Opposite"] 41["SweepEdge Opposite"]
42["SweepEdge Adjacent"] 42["SweepEdge Adjacent"]
43["Plane<br>[2641, 2683, 0]"] 43["Plane<br>[2653, 2695, 0]"]
53["Sweep Extrusion<br>[3129, 3173, 0]"] 53["Sweep Extrusion<br>[3141, 3185, 0]"]
54[Wall] 54[Wall]
55[Wall] 55[Wall]
56[Wall] 56[Wall]
@ -101,8 +101,8 @@ flowchart LR
67["SweepEdge Opposite"] 67["SweepEdge Opposite"]
68["SweepEdge Opposite"] 68["SweepEdge Opposite"]
69["SweepEdge Adjacent"] 69["SweepEdge Adjacent"]
70["Plane<br>[3616, 3642, 0]"] 70["Plane<br>[3628, 3654, 0]"]
82["Sweep Extrusion<br>[4351, 4393, 0]"] 82["Sweep Extrusion<br>[4363, 4405, 0]"]
83[Wall] 83[Wall]
84[Wall] 84[Wall]
85[Wall] 85[Wall]
@ -120,7 +120,7 @@ flowchart LR
97["SweepEdge Opposite"] 97["SweepEdge Opposite"]
98["SweepEdge Opposite"] 98["SweepEdge Opposite"]
99["SweepEdge Opposite"] 99["SweepEdge Opposite"]
107["Sweep Extrusion<br>[4628, 4678, 0]"] 107["Sweep Extrusion<br>[4640, 4690, 0]"]
108[Wall] 108[Wall]
109[Wall] 109[Wall]
110[Wall] 110[Wall]
@ -128,12 +128,12 @@ flowchart LR
112["SweepEdge Opposite"] 112["SweepEdge Opposite"]
113["SweepEdge Opposite"] 113["SweepEdge Opposite"]
114["SweepEdge Opposite"] 114["SweepEdge Opposite"]
115["EdgeCut Fillet<br>[2403, 2544, 0]"] 115["EdgeCut Fillet<br>[2415, 2556, 0]"]
116["EdgeCut Fillet<br>[2403, 2544, 0]"] 116["EdgeCut Fillet<br>[2415, 2556, 0]"]
117["EdgeCut Fillet<br>[3216, 3347, 0]"] 117["EdgeCut Fillet<br>[3228, 3359, 0]"]
118["EdgeCut Fillet<br>[3216, 3347, 0]"] 118["EdgeCut Fillet<br>[3228, 3359, 0]"]
119["StartSketchOnPlane<br>[2627, 2684, 0]"] 119["StartSketchOnPlane<br>[2639, 2696, 0]"]
120["StartSketchOnFace<br>[4452, 4491, 0]"] 120["StartSketchOnFace<br>[4464, 4503, 0]"]
1 --- 2 1 --- 2
1 --- 9 1 --- 9
1 --- 16 1 --- 16

View File

@ -1109,79 +1109,25 @@ description: Result of parsing food-service-spatula.kcl
"left": { "left": {
"arguments": [ "arguments": [
{ {
"commentStart": 0, "type": "LabeledArg",
"end": 0, "label": {
"left": {
"commentStart": 0, "commentStart": 0,
"computed": false,
"end": 0, "end": 0,
"object": { "name": "exp",
"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, "start": 0,
"type": "MemberExpression", "type": "Identifier"
"type": "MemberExpression"
}, },
"operator": "-", "arg": {
"right": {
"commentStart": 0, "commentStart": 0,
"computed": false,
"end": 0, "end": 0,
"object": { "raw": "2",
"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, "start": 0,
"type": "MemberExpression", "type": "Literal",
"type": "MemberExpression" "type": "Literal",
}, "value": {
"start": 0, "value": 2.0,
"type": "BinaryExpression", "suffix": "None"
"type": "BinaryExpression" }
},
{
"commentStart": 0,
"end": 0,
"raw": "2",
"start": 0,
"type": "Literal",
"type": "Literal",
"value": {
"value": 2.0,
"suffix": "None"
} }
} }
], ],
@ -1203,86 +1149,96 @@ description: Result of parsing food-service-spatula.kcl
"commentStart": 0, "commentStart": 0,
"end": 0, "end": 0,
"start": 0, "start": 0,
"type": "CallExpression", "type": "CallExpressionKw",
"type": "CallExpression" "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": "+", "operator": "+",
"right": { "right": {
"arguments": [ "arguments": [
{ {
"commentStart": 0, "type": "LabeledArg",
"end": 0, "label": {
"left": {
"commentStart": 0, "commentStart": 0,
"computed": false,
"end": 0, "end": 0,
"object": { "name": "exp",
"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, "start": 0,
"type": "MemberExpression", "type": "Identifier"
"type": "MemberExpression"
}, },
"operator": "-", "arg": {
"right": {
"commentStart": 0, "commentStart": 0,
"computed": false,
"end": 0, "end": 0,
"object": { "raw": "2",
"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, "start": 0,
"type": "MemberExpression", "type": "Literal",
"type": "MemberExpression" "type": "Literal",
}, "value": {
"start": 0, "value": 2.0,
"type": "BinaryExpression", "suffix": "None"
"type": "BinaryExpression" }
},
{
"commentStart": 0,
"end": 0,
"raw": "2",
"start": 0,
"type": "Literal",
"type": "Literal",
"value": {
"value": 2.0,
"suffix": "None"
} }
} }
], ],
@ -1304,8 +1260,72 @@ description: Result of parsing food-service-spatula.kcl
"commentStart": 0, "commentStart": 0,
"end": 0, "end": 0,
"start": 0, "start": 0,
"type": "CallExpression", "type": "CallExpressionKw",
"type": "CallExpression" "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, "start": 0,
"type": "BinaryExpression", "type": "BinaryExpression",

View File

@ -25,7 +25,7 @@ description: Operations executed food-service-spatula.kcl
"name": "slot", "name": "slot",
"functionSourceRange": [ "functionSourceRange": [
462, 462,
1306, 1318,
0 0
], ],
"unlabeledArg": null, "unlabeledArg": null,
@ -133,7 +133,7 @@ description: Operations executed food-service-spatula.kcl
"name": "slot", "name": "slot",
"functionSourceRange": [ "functionSourceRange": [
462, 462,
1306, 1318,
0 0
], ],
"unlabeledArg": null, "unlabeledArg": null,
@ -241,7 +241,7 @@ description: Operations executed food-service-spatula.kcl
"name": "slot", "name": "slot",
"functionSourceRange": [ "functionSourceRange": [
462, 462,
1306, 1318,
0 0
], ],
"unlabeledArg": null, "unlabeledArg": null,
@ -877,7 +877,7 @@ description: Operations executed food-service-spatula.kcl
"name": "slot", "name": "slot",
"functionSourceRange": [ "functionSourceRange": [
462, 462,
1306, 1318,
0 0
], ],
"unlabeledArg": null, "unlabeledArg": null,

View File

@ -27,9 +27,9 @@ description: Variables in memory after executing food-service-spatula.kcl
"id": "[uuid]", "id": "[uuid]",
"sourceRange": [], "sourceRange": [],
"tag": { "tag": {
"commentStart": 1576, "commentStart": 1588,
"end": 1585, "end": 1597,
"start": 1576, "start": 1588,
"type": "TagDeclarator", "type": "TagDeclarator",
"value": "backEdge" "value": "backEdge"
}, },
@ -90,9 +90,9 @@ description: Variables in memory after executing food-service-spatula.kcl
-30.0 -30.0
], ],
"tag": { "tag": {
"commentStart": 1576, "commentStart": 1588,
"end": 1585, "end": 1597,
"start": 1576, "start": 1588,
"type": "TagDeclarator", "type": "TagDeclarator",
"value": "backEdge" "value": "backEdge"
}, },
@ -299,9 +299,9 @@ description: Variables in memory after executing food-service-spatula.kcl
-30.0 -30.0
], ],
"tag": { "tag": {
"commentStart": 1576, "commentStart": 1588,
"end": 1585, "end": 1597,
"start": 1576, "start": 1588,
"type": "TagDeclarator", "type": "TagDeclarator",
"value": "backEdge" "value": "backEdge"
}, },
@ -551,9 +551,9 @@ description: Variables in memory after executing food-service-spatula.kcl
"id": "[uuid]", "id": "[uuid]",
"sourceRange": [], "sourceRange": [],
"tag": { "tag": {
"commentStart": 4195, "commentStart": 4207,
"end": 4207, "end": 4219,
"start": 4195, "start": 4207,
"type": "TagDeclarator", "type": "TagDeclarator",
"value": "gripEdgeTop" "value": "gripEdgeTop"
}, },
@ -713,9 +713,9 @@ description: Variables in memory after executing food-service-spatula.kcl
7.0 7.0
], ],
"tag": { "tag": {
"commentStart": 4195, "commentStart": 4207,
"end": 4207, "end": 4219,
"start": 4195, "start": 4207,
"type": "TagDeclarator", "type": "TagDeclarator",
"value": "gripEdgeTop" "value": "gripEdgeTop"
}, },
@ -1058,9 +1058,9 @@ description: Variables in memory after executing food-service-spatula.kcl
"id": "[uuid]", "id": "[uuid]",
"sourceRange": [], "sourceRange": [],
"tag": { "tag": {
"commentStart": 4195, "commentStart": 4207,
"end": 4207, "end": 4219,
"start": 4195, "start": 4207,
"type": "TagDeclarator", "type": "TagDeclarator",
"value": "gripEdgeTop" "value": "gripEdgeTop"
}, },
@ -1220,9 +1220,9 @@ description: Variables in memory after executing food-service-spatula.kcl
7.0 7.0
], ],
"tag": { "tag": {
"commentStart": 4195, "commentStart": 4207,
"end": 4207, "end": 4219,
"start": 4195, "start": 4207,
"type": "TagDeclarator", "type": "TagDeclarator",
"value": "gripEdgeTop" "value": "gripEdgeTop"
}, },
@ -1538,9 +1538,9 @@ description: Variables in memory after executing food-service-spatula.kcl
7.0 7.0
], ],
"tag": { "tag": {
"commentStart": 4195, "commentStart": 4207,
"end": 4207, "end": 4219,
"start": 4195, "start": 4207,
"type": "TagDeclarator", "type": "TagDeclarator",
"value": "gripEdgeTop" "value": "gripEdgeTop"
}, },
@ -1729,9 +1729,9 @@ description: Variables in memory after executing food-service-spatula.kcl
"id": "[uuid]", "id": "[uuid]",
"sourceRange": [], "sourceRange": [],
"tag": { "tag": {
"commentStart": 2847, "commentStart": 2859,
"end": 2864, "end": 2876,
"start": 2847, "start": 2859,
"type": "TagDeclarator", "type": "TagDeclarator",
"value": "handleBottomEdge" "value": "handleBottomEdge"
}, },
@ -1756,9 +1756,9 @@ description: Variables in memory after executing food-service-spatula.kcl
"id": "[uuid]", "id": "[uuid]",
"sourceRange": [], "sourceRange": [],
"tag": { "tag": {
"commentStart": 2995, "commentStart": 3007,
"end": 3009, "end": 3021,
"start": 2995, "start": 3007,
"type": "TagDeclarator", "type": "TagDeclarator",
"value": "handleTopEdge" "value": "handleTopEdge"
}, },
@ -1800,9 +1800,9 @@ description: Variables in memory after executing food-service-spatula.kcl
3.5 3.5
], ],
"tag": { "tag": {
"commentStart": 2847, "commentStart": 2859,
"end": 2864, "end": 2876,
"start": 2847, "start": 2859,
"type": "TagDeclarator", "type": "TagDeclarator",
"value": "handleBottomEdge" "value": "handleBottomEdge"
}, },
@ -1863,9 +1863,9 @@ description: Variables in memory after executing food-service-spatula.kcl
91.3213 91.3213
], ],
"tag": { "tag": {
"commentStart": 2995, "commentStart": 3007,
"end": 3009, "end": 3021,
"start": 2995, "start": 3007,
"type": "TagDeclarator", "type": "TagDeclarator",
"value": "handleTopEdge" "value": "handleTopEdge"
}, },
@ -2211,9 +2211,9 @@ description: Variables in memory after executing food-service-spatula.kcl
3.5 3.5
], ],
"tag": { "tag": {
"commentStart": 2847, "commentStart": 2859,
"end": 2864, "end": 2876,
"start": 2847, "start": 2859,
"type": "TagDeclarator", "type": "TagDeclarator",
"value": "handleBottomEdge" "value": "handleBottomEdge"
}, },
@ -2274,9 +2274,9 @@ description: Variables in memory after executing food-service-spatula.kcl
91.3213 91.3213
], ],
"tag": { "tag": {
"commentStart": 2995, "commentStart": 3007,
"end": 3009, "end": 3021,
"start": 2995, "start": 3007,
"type": "TagDeclarator", "type": "TagDeclarator",
"value": "handleTopEdge" "value": "handleTopEdge"
}, },
@ -2536,9 +2536,9 @@ description: Variables in memory after executing food-service-spatula.kcl
"id": "[uuid]", "id": "[uuid]",
"sourceRange": [], "sourceRange": [],
"tag": { "tag": {
"commentStart": 4195, "commentStart": 4207,
"end": 4207, "end": 4219,
"start": 4195, "start": 4207,
"type": "TagDeclarator", "type": "TagDeclarator",
"value": "gripEdgeTop" "value": "gripEdgeTop"
}, },
@ -2698,9 +2698,9 @@ description: Variables in memory after executing food-service-spatula.kcl
7.0 7.0
], ],
"tag": { "tag": {
"commentStart": 4195, "commentStart": 4207,
"end": 4207, "end": 4219,
"start": 4195, "start": 4207,
"type": "TagDeclarator", "type": "TagDeclarator",
"value": "gripEdgeTop" "value": "gripEdgeTop"
}, },
@ -3370,9 +3370,9 @@ description: Variables in memory after executing food-service-spatula.kcl
-30.0 -30.0
], ],
"tag": { "tag": {
"commentStart": 1576, "commentStart": 1588,
"end": 1585, "end": 1597,
"start": 1576, "start": 1588,
"type": "TagDeclarator", "type": "TagDeclarator",
"value": "backEdge" "value": "backEdge"
}, },

View File

@ -352,28 +352,28 @@ describe('testing math operators', () => {
expect(mem['myVar']?.value).toBe(12.5) expect(mem['myVar']?.value).toBe(12.5)
}) })
it('with callExpression at start', async () => { 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) const mem = await exe(code)
expect(mem['myVar']?.value).toBe(6) expect(mem['myVar']?.value).toBe(6)
}) })
it('with callExpression at end', async () => { 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) const mem = await exe(code)
expect(mem['myVar']?.value).toBe(6) expect(mem['myVar']?.value).toBe(6)
}) })
it('with nested callExpression', async () => { 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) const mem = await exe(code)
expect(mem['myVar']?.value).toBe(6) expect(mem['myVar']?.value).toBe(6)
}) })
it('with unaryExpression', async () => { it('with unaryExpression', async () => {
const code = 'const myVar = -min(100, 3)' const code = 'myVar = -min([100, 3])'
const mem = await exe(code) const mem = await exe(code)
expect(mem['myVar']?.value).toBe(-3) expect(mem['myVar']?.value).toBe(-3)
}) })
it('with unaryExpression in callExpression', async () => { it('with unaryExpression in callExpression', async () => {
const code = 'const myVar = min(-legLen(hypotenuse = 5, leg = 4), 5)' const code = 'myVar = min([-legLen(hypotenuse = 5, leg = 4), 5])'
const code2 = 'const myVar = min(5 , -legLen(hypotenuse = 5, leg = 4))' const code2 = 'myVar = min([5 , -legLen(hypotenuse = 5, leg = 4)])'
const mem = await exe(code) const mem = await exe(code)
const mem2 = await exe(code2) const mem2 = await exe(code2)
expect(mem['myVar']?.value).toBe(-3) expect(mem['myVar']?.value).toBe(-3)
@ -399,11 +399,11 @@ describe('testing math operators', () => {
const code = [ const code = [
'part001 = startSketchOn(XY)', 'part001 = startSketchOn(XY)',
' |> startProfile(at = [0, 0])', ' |> 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') ].join('\n')
const mem = await exe(code) const mem = await exe(code)
const sketch = sketchFromKclValue(mem['part001'], 'part001') 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] const yVal = (sketch as Sketch).paths?.[0]?.to?.[1]
expect(yVal).toBe(-4) expect(yVal).toBe(-4)
}) })
@ -414,7 +414,7 @@ describe('testing math operators', () => {
` |> startProfile(at = [0, 0])`, ` |> startProfile(at = [0, 0])`,
` |> line(end = [3, 4], tag = $seg01)`, ` |> line(end = [3, 4], tag = $seg01)`,
` |> line(end = [`, ` |> line(end = [`,
` min(segLen(seg01), myVar),`, ` min([segLen(seg01), myVar]),`,
` -legLen(hypotenuse = segLen(seg01), leg = 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]) expect((removedUnaryExpMemSketch as Sketch).paths?.[1]?.to).toEqual([6, 8])
}) })
it('with nested callExpression and binaryExpression', async () => { it('with nested callExpression and binaryExpression', async () => {
const code = const code = 'myVar = 2 + min([100, -1 + legLen(hypotenuse = 5, leg = 3)])'
'const myVar = 2 + min(100, -1 + legLen(hypotenuse = 5, leg = 3))'
const mem = await exe(code) const mem = await exe(code)
expect(mem['myVar']?.value).toBe(5) expect(mem['myVar']?.value).toBe(5)
}) })

View File

@ -298,21 +298,21 @@ mySk1 = startSketchOn(XY)
describe('testing call Expressions in BinaryExpressions and UnaryExpressions', () => { describe('testing call Expressions in BinaryExpressions and UnaryExpressions', () => {
it('nested callExpression in binaryExpression', () => { 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 { ast } = code2ast(code)
const recasted = recast(ast) const recasted = recast(ast)
if (err(recasted)) throw recasted if (err(recasted)) throw recasted
expect(recasted.trim()).toBe(code) expect(recasted.trim()).toBe(code)
}) })
it('nested callExpression in unaryExpression', () => { 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 { ast } = code2ast(code)
const recasted = recast(ast) const recasted = recast(ast)
if (err(recasted)) throw recasted if (err(recasted)) throw recasted
expect(recasted.trim()).toBe(code) expect(recasted.trim()).toBe(code)
}) })
it('with unaryExpression in callExpression', () => { 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 { ast } = code2ast(code)
const recasted = recast(ast) const recasted = recast(ast)
if (err(recasted)) throw recasted if (err(recasted)) throw recasted
@ -322,7 +322,7 @@ describe('testing call Expressions in BinaryExpressions and UnaryExpressions', (
const code = [ const code = [
'part001 = startSketchOn(XY)', 'part001 = startSketchOn(XY)',
' |> startProfile(at = [0, 0])', ' |> 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') ].join('\n')
const { ast } = code2ast(code) const { ast } = code2ast(code)
const recasted = recast(ast) const recasted = recast(ast)

View File

@ -307,31 +307,31 @@ part001 = startSketchOn(XY)
|> angledLine(angle = 135, length = segLen(seg01)) // ln-angledLineToY-free should become angledLine |> angledLine(angle = 135, length = segLen(seg01)) // ln-angledLineToY-free should become angledLine
|> angledLine(angle = myAng2, length = segLen(seg01)) // ln-angledLineToY-angle should become angledLine |> angledLine(angle = myAng2, length = segLen(seg01)) // ln-angledLineToY-angle should become angledLine
|> line(end = [ |> line(end = [
min(segLen(seg01), myVar), min([segLen(seg01), myVar]),
legLen(hypotenuse = segLen(seg01), leg = myVar) legLen(hypotenuse = segLen(seg01), leg = myVar)
]) // ln-should use legLen for y ]) // ln-should use legLen for y
|> line(end = [ |> line(end = [
min(segLen(seg01), myVar), min([segLen(seg01), myVar]),
-legLen(hypotenuse = segLen(seg01), leg = myVar) -legLen(hypotenuse = segLen(seg01), leg = myVar)
]) // ln-legLen but negative ]) // ln-legLen but negative
|> angledLine(angle = -112, length = segLen(seg01)) // ln-should become angledLine |> angledLine(angle = -112, length = segLen(seg01)) // ln-should become angledLine
|> angledLine(angle = myVar, length = segLen(seg01)) // ln-use segLen for second arg |> angledLine(angle = myVar, length = segLen(seg01)) // ln-use segLen for second arg
|> angledLine(angle = 45, length = segLen(seg01)) // ln-segLen again |> angledLine(angle = 45, length = segLen(seg01)) // ln-segLen again
|> angledLine(angle = 54, length = segLen(seg01)) // ln-should be transformed to angledLine |> 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 = 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 = 180 + legAngX(segLen(seg01), myVar), lengthX = min([segLen(seg01), myVar])) // ln-same as above but should have + 180 to match original quadrant
|> line(end = [ |> line(end = [
legLen(hypotenuse = segLen(seg01), leg = myVar), legLen(hypotenuse = segLen(seg01), leg = myVar),
min(segLen(seg01), myVar) min([segLen(seg01), myVar])
]) // ln-legLen again but yRelative ]) // ln-legLen again but yRelative
|> line(end = [ |> line(end = [
-legLen(hypotenuse = segLen(seg01), leg = myVar), -legLen(hypotenuse = segLen(seg01), leg = myVar),
min(segLen(seg01), myVar) min([segLen(seg01), myVar])
]) // ln-negative legLen yRelative ]) // ln-negative legLen yRelative
|> angledLine(angle = 58, length = segLen(seg01)) // ln-angledLineOfYLength-free should become angledLine |> 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 = 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 = 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 = 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 |> xLine(length = segLen(seg01)) // ln-xLine-free should sub in segLen
|> yLine(length = segLen(seg01)) // ln-yLine-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 |> xLine(length = segLen(seg01)) // ln-xLineTo-free should convert to xLine

View File

@ -452,7 +452,11 @@ const getMinAndSegLenVals = (
): [Expr, BinaryPart] => { ): [Expr, BinaryPart] => {
const segLenVal = createSegLen(referenceSegName) const segLenVal = createSegLen(referenceSegName)
return [ return [
createCallExpression('min', [segLenVal, varVal]), createCallExpressionStdLibKw(
'min',
createArrayExpression([segLenVal, varVal]),
[]
),
createCallExpressionStdLibKw('legLen', null, [ createCallExpressionStdLibKw('legLen', null, [
createLabeledArg('hypotenuse', segLenVal), createLabeledArg('hypotenuse', segLenVal),
createLabeledArg('leg', varVal), createLabeledArg('leg', varVal),
@ -465,10 +469,11 @@ const getMinAndSegAngVals = (
varVal: Expr, varVal: Expr,
fnName: 'legAngX' | 'legAngY' = 'legAngX' fnName: 'legAngX' | 'legAngY' = 'legAngX'
): [Expr, BinaryPart] => { ): [Expr, BinaryPart] => {
const minVal = createCallExpression('min', [ const minVal = createCallExpressionStdLibKw(
createSegLen(referenceSegName), 'min',
varVal, createArrayExpression([createSegLen(referenceSegName), varVal]),
]) []
)
const legAngle = createCallExpression(fnName, [ const legAngle = createCallExpression(fnName, [
createSegLen(referenceSegName), createSegLen(referenceSegName),
varVal, varVal,