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
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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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()

View File

@ -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

View File

@ -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()

View File

@ -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()

View File

@ -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" }
}

View File

@ -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()

View File

@ -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

View File

@ -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

View File

@ -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": {

View File

@ -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])

View File

@ -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]
}
}

View File

@ -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,

View File

@ -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();

View File

@ -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

View File

@ -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<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(
&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<Self> {

View File

@ -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<f64, KclError> {
/// Compute the square root of a number.
pub async fn sqrt(exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
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<KclValue, Kc
#[stdlib {
name = "sqrt",
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> {
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<KclValue, KclError> {
let num = args.get_number_with_type()?;
let result = inner_abs(num.n)?;
pub async fn abs(exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
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<KclValue, Kc
#[stdlib {
name = "abs",
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> {
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<KclValue, KclError> {
let num = args.get_number_with_type()?;
let result = inner_round(num.n)?;
pub async fn round(exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
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<KclValue,
#[stdlib {
name = "round",
tags = ["math"],
keywords = true,
unlabeled_first = true,
args = {
input = {docs = "The number to round."},
}
}]
fn inner_round(num: f64) -> Result<f64, KclError> {
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<KclValue, KclError> {
let num = args.get_number_with_type()?;
let result = inner_floor(num.n)?;
pub async fn floor(exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
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<KclValue,
#[stdlib {
name = "floor",
tags = ["math"],
keywords = true,
unlabeled_first = true,
args = {
input = {docs = "The number to round."},
}
}]
fn inner_floor(num: f64) -> Result<f64, KclError> {
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<KclValue, KclError> {
let num = args.get_number_with_type()?;
let result = inner_ceil(num.n)?;
pub async fn ceil(exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
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<KclValue, K
#[stdlib {
name = "ceil",
tags = ["math"],
keywords = true,
unlabeled_first = true,
args = {
input = {docs = "The number to round."},
}
}]
fn inner_ceil(num: f64) -> Result<f64, KclError> {
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<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);
if ty == NumericType::Unknown {
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])
/// |> 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<KclValue, Kcl
#[stdlib {
name = "min",
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;
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>) -> f64 {
/// Compute the maximum of the given arguments.
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);
if ty == NumericType::Unknown {
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])
/// |> 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<KclValue, Kcl
#[stdlib {
name = "max",
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;
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>) -> f64 {
/// Compute the number to a power.
pub async fn pow(exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
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<KclValue, Kcl
/// |> 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<KclValue, Kcl
#[stdlib {
name = "pow",
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> {
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<KclValue, KclError> {
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<KclValue, Kc
#[stdlib {
name = "acos",
tags = ["math"],
keywords = true,
unlabeled_first = true,
args = {
input = {docs = "The number to compute arccosine of."},
}
}]
fn inner_acos(num: f64) -> Result<f64, KclError> {
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<KclValue, KclError> {
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<KclValue, Kc
#[stdlib {
name = "asin",
tags = ["math"],
keywords = true,
unlabeled_first = true,
args = {
input = {docs = "The number to compute arcsine of."},
}
}]
fn inner_asin(num: f64) -> Result<f64, KclError> {
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<KclValue, KclError> {
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<KclValue, Kc
#[stdlib {
name = "atan",
tags = ["math"],
keywords = true,
unlabeled_first = true,
args = {
input = {docs = "The number to compute arctangent of."},
}
}]
fn inner_atan(num: f64) -> Result<f64, KclError> {
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<KclValue, K
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 (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())))
}
@ -589,8 +606,8 @@ pub async fn atan2(exec_state: &mut ExecState, args: Args) -> Result<KclValue, K
x = { docs = "X"},
}
}]
fn inner_atan2(y: f64, x: f64) -> Result<f64, KclError> {
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<f64, KclError> {
/// 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<KclValue, KclError> {
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<KclValue, Kcl
/// ```no_run
/// 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()
@ -637,15 +642,21 @@ pub async fn log(exec_state: &mut ExecState, args: Args) -> Result<KclValue, Kcl
#[stdlib {
name = "log",
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> {
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<KclValue, KclError> {
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<KclValue, Kc
#[stdlib {
name = "log2",
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> {
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<KclValue, KclError> {
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<KclValue, K
name = "log10",
tags = ["math"],
}]
fn inner_log10(num: f64) -> Result<f64, KclError> {
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<KclValue, KclError> {
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<KclValue, KclE
#[stdlib {
name = "ln",
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> {
Ok(num.ln())
fn inner_ln(input: f64) -> f64 {
input.ln()
}
/// 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.
/// 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,

View File

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

View File

@ -1109,6 +1109,49 @@ description: Result of parsing food-service-spatula.kcl
"left": {
"arguments": [
{
"type": "LabeledArg",
"label": {
"commentStart": 0,
"end": 0,
"name": "exp",
"start": 0,
"type": "Identifier"
},
"arg": {
"commentStart": 0,
"end": 0,
"raw": "2",
"start": 0,
"type": "Literal",
"type": "Literal",
"value": {
"value": 2.0,
"suffix": "None"
}
}
}
],
"callee": {
"abs_path": false,
"commentStart": 0,
"end": 0,
"name": {
"commentStart": 0,
"end": 0,
"name": "pow",
"start": 0,
"type": "Identifier"
},
"path": [],
"start": 0,
"type": "Name"
},
"commentStart": 0,
"end": 0,
"start": 0,
"type": "CallExpressionKw",
"type": "CallExpressionKw",
"unlabeled": {
"commentStart": 0,
"end": 0,
"left": {
@ -1171,45 +1214,55 @@ description: Result of parsing food-service-spatula.kcl
"start": 0,
"type": "BinaryExpression",
"type": "BinaryExpression"
},
{
"commentStart": 0,
"end": 0,
"raw": "2",
"start": 0,
"type": "Literal",
"type": "Literal",
"value": {
"value": 2.0,
"suffix": "None"
}
}
],
"callee": {
"abs_path": false,
"commentStart": 0,
"end": 0,
"name": {
"commentStart": 0,
"end": 0,
"name": "pow",
"start": 0,
"type": "Identifier"
},
"path": [],
"start": 0,
"type": "Name"
},
"commentStart": 0,
"end": 0,
"start": 0,
"type": "CallExpression",
"type": "CallExpression"
},
"operator": "+",
"right": {
"arguments": [
{
"type": "LabeledArg",
"label": {
"commentStart": 0,
"end": 0,
"name": "exp",
"start": 0,
"type": "Identifier"
},
"arg": {
"commentStart": 0,
"end": 0,
"raw": "2",
"start": 0,
"type": "Literal",
"type": "Literal",
"value": {
"value": 2.0,
"suffix": "None"
}
}
}
],
"callee": {
"abs_path": false,
"commentStart": 0,
"end": 0,
"name": {
"commentStart": 0,
"end": 0,
"name": "pow",
"start": 0,
"type": "Identifier"
},
"path": [],
"start": 0,
"type": "Name"
},
"commentStart": 0,
"end": 0,
"start": 0,
"type": "CallExpressionKw",
"type": "CallExpressionKw",
"unlabeled": {
"commentStart": 0,
"end": 0,
"left": {
@ -1272,40 +1325,7 @@ description: Result of parsing food-service-spatula.kcl
"start": 0,
"type": "BinaryExpression",
"type": "BinaryExpression"
},
{
"commentStart": 0,
"end": 0,
"raw": "2",
"start": 0,
"type": "Literal",
"type": "Literal",
"value": {
"value": 2.0,
"suffix": "None"
}
}
],
"callee": {
"abs_path": false,
"commentStart": 0,
"end": 0,
"name": {
"commentStart": 0,
"end": 0,
"name": "pow",
"start": 0,
"type": "Identifier"
},
"path": [],
"start": 0,
"type": "Name"
},
"commentStart": 0,
"end": 0,
"start": 0,
"type": "CallExpression",
"type": "CallExpression"
},
"start": 0,
"type": "BinaryExpression",

View File

@ -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,

View File

@ -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"
},

View File

@ -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)
})

View File

@ -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)

View File

@ -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

View File

@ -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,