Skip to content

Commit

Permalink
Implicit conversion of round numbers to integers (#4542)
Browse files Browse the repository at this point in the history
Signed-off-by: Nick Cameron <[email protected]>
  • Loading branch information
nrc authored Nov 24, 2024
1 parent 66f6b74 commit 4fe17fe
Show file tree
Hide file tree
Showing 174 changed files with 1,603 additions and 1,518 deletions.
1 change: 1 addition & 0 deletions docs/kcl/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ layout: manual
* [`reduce`](kcl/reduce)
* [`rem`](kcl/rem)
* [`revolve`](kcl/revolve)
* [`round`](kcl/round)
* [`segAng`](kcl/segAng)
* [`segEnd`](kcl/segEnd)
* [`segEndX`](kcl/segEndX)
Expand Down
8 changes: 3 additions & 5 deletions docs/kcl/int.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@ layout: manual

Convert a number to an integer.

Callers should use floor(), ceil(), or other rounding function first if they care about how numbers with fractional parts are converted. If the number has a fractional part, it's truncated, moving the number towards zero.

If the number is NaN or has a magnitude, either positive or negative, that is too large to fit into the internal integer representation, the result is a runtime error.
DEPRECATED use floor(), ceil(), or round().

```js
int(num: number) -> i64
int(num: number) -> number
```

### Tags
Expand All @@ -27,7 +25,7 @@ int(num: number) -> i64

### Returns

`i64`
`number`


### Examples
Expand Down
6 changes: 3 additions & 3 deletions docs/kcl/rem.md

Large diffs are not rendered by default.

46 changes: 46 additions & 0 deletions docs/kcl/round.md

Large diffs are not rendered by default.

169 changes: 55 additions & 114 deletions docs/kcl/std.json
Original file line number Diff line number Diff line change
Expand Up @@ -78541,7 +78541,7 @@
{
"name": "int",
"summary": "Convert a number to an integer.",
"description": "Callers should use floor(), ceil(), or other rounding function first if they care about how numbers with fractional parts are converted. If the number has a fractional part, it's truncated, moving the number towards zero.\n\nIf the number is NaN or has a magnitude, either positive or negative, that is too large to fit into the internal integer representation, the result is a runtime error.",
"description": "DEPRECATED use floor(), ceil(), or round().",
"tags": [
"convert"
],
Expand All @@ -78560,12 +78560,12 @@
],
"returnValue": {
"name": "",
"type": "i64",
"type": "number",
"schema": {
"$schema": "https://spec.openapis.org/oas/3.0/schema/2019-04-02#/definitions/Schema",
"title": "int64",
"type": "integer",
"format": "int64"
"title": "double",
"type": "number",
"format": "double"
},
"required": true
},
Expand Down Expand Up @@ -96858,10 +96858,6 @@
},
"LiteralValue": {
"anyOf": [
{
"type": "integer",
"format": "int64"
},
{
"type": "number",
"format": "double"
Expand Down Expand Up @@ -100829,10 +100825,6 @@
},
"LiteralValue": {
"anyOf": [
{
"type": "integer",
"format": "int64"
},
{
"type": "number",
"format": "double"
Expand Down Expand Up @@ -104804,10 +104796,6 @@
},
"LiteralValue": {
"anyOf": [
{
"type": "integer",
"format": "int64"
},
{
"type": "number",
"format": "double"
Expand Down Expand Up @@ -110015,11 +110003,9 @@
"properties": {
"instances": {
"description": "The number of total instances. Must be greater than or equal to 1. This includes the original entity. For example, if instances is 2, there will be two copies -- the original, and one new copy. If instances is 1, this has no effect.",
"allOf": [
{
"$ref": "#/components/schemas/Uint"
}
]
"type": "integer",
"format": "uint32",
"minimum": 0.0
},
"center": {
"description": "The center about which to make the pattern. This is a 2D vector.",
Expand All @@ -110040,13 +110026,6 @@
"description": "Whether or not to rotate the duplicates as they are copied.",
"type": "boolean"
}
},
"definitions": {
"Uint": {
"type": "integer",
"format": "uint32",
"minimum": 0.0
}
}
},
"required": true
Expand Down Expand Up @@ -110143,11 +110122,6 @@
}
],
"definitions": {
"Uint": {
"type": "integer",
"format": "uint32",
"minimum": 0.0
},
"Path": {
"description": "A path.",
"oneOf": [
Expand Down Expand Up @@ -112800,11 +112774,9 @@
"properties": {
"instances": {
"description": "The number of total instances. Must be greater than or equal to 1. This includes the original entity. For example, if instances is 2, there will be two copies -- the original, and one new copy. If instances is 1, this has no effect.",
"allOf": [
{
"$ref": "#/components/schemas/Uint"
}
]
"type": "integer",
"format": "uint32",
"minimum": 0.0
},
"axis": {
"description": "The axis around which to make the pattern. This is a 3D vector.",
Expand Down Expand Up @@ -112835,13 +112807,6 @@
"description": "Whether or not to rotate the duplicates as they are copied.",
"type": "boolean"
}
},
"definitions": {
"Uint": {
"type": "integer",
"format": "uint32",
"minimum": 0.0
}
}
},
"required": true
Expand Down Expand Up @@ -112947,11 +112912,6 @@
}
],
"definitions": {
"Uint": {
"type": "integer",
"format": "uint32",
"minimum": 0.0
},
"ExtrudeSurface": {
"description": "An extrude surface.",
"oneOf": [
Expand Down Expand Up @@ -115602,11 +115562,9 @@
"properties": {
"instances": {
"description": "The number of total instances. Must be greater than or equal to 1. This includes the original entity. For example, if instances is 2, there will be two copies -- the original, and one new copy. If instances is 1, this has no effect.",
"allOf": [
{
"$ref": "#/components/schemas/Uint"
}
]
"type": "integer",
"format": "uint32",
"minimum": 0.0
},
"distance": {
"description": "The distance between each repetition. This can also be referred to as spacing.",
Expand All @@ -115623,13 +115581,6 @@
"maxItems": 2,
"minItems": 2
}
},
"definitions": {
"Uint": {
"type": "integer",
"format": "uint32",
"minimum": 0.0
}
}
},
"required": true
Expand Down Expand Up @@ -115726,11 +115677,6 @@
}
],
"definitions": {
"Uint": {
"type": "integer",
"format": "uint32",
"minimum": 0.0
},
"Path": {
"description": "A path.",
"oneOf": [
Expand Down Expand Up @@ -118381,11 +118327,9 @@
"properties": {
"instances": {
"description": "The number of total instances. Must be greater than or equal to 1. This includes the original entity. For example, if instances is 2, there will be two copies -- the original, and one new copy. If instances is 1, this has no effect.",
"allOf": [
{
"$ref": "#/components/schemas/Uint"
}
]
"type": "integer",
"format": "uint32",
"minimum": 0.0
},
"distance": {
"description": "The distance between each repetition. This can also be referred to as spacing.",
Expand All @@ -118402,13 +118346,6 @@
"maxItems": 3,
"minItems": 3
}
},
"definitions": {
"Uint": {
"type": "integer",
"format": "uint32",
"minimum": 0.0
}
}
},
"required": true
Expand Down Expand Up @@ -118514,11 +118451,6 @@
}
],
"definitions": {
"Uint": {
"type": "integer",
"format": "uint32",
"minimum": 0.0
},
"ExtrudeSurface": {
"description": "An extrude surface.",
"oneOf": [
Expand Down Expand Up @@ -137985,10 +137917,6 @@
},
"LiteralValue": {
"anyOf": [
{
"type": "integer",
"format": "int64"
},
{
"type": "number",
"format": "double"
Expand Down Expand Up @@ -142572,10 +142500,6 @@
},
"LiteralValue": {
"anyOf": [
{
"type": "integer",
"format": "int64"
},
{
"type": "number",
"format": "double"
Expand Down Expand Up @@ -147160,10 +147084,6 @@
},
"LiteralValue": {
"anyOf": [
{
"type": "integer",
"format": "int64"
},
{
"type": "number",
"format": "double"
Expand Down Expand Up @@ -151146,10 +151066,6 @@
},
"LiteralValue": {
"anyOf": [
{
"type": "integer",
"format": "int64"
},
{
"type": "number",
"format": "double"
Expand Down Expand Up @@ -155733,10 +155649,6 @@
},
"LiteralValue": {
"anyOf": [
{
"type": "integer",
"format": "int64"
},
{
"type": "number",
"format": "double"
Expand Down Expand Up @@ -159704,10 +159616,6 @@
},
"LiteralValue": {
"anyOf": [
{
"type": "integer",
"format": "int64"
},
{
"type": "number",
"format": "double"
Expand Down Expand Up @@ -164292,10 +164200,6 @@
},
"LiteralValue": {
"anyOf": [
{
"type": "integer",
"format": "int64"
},
{
"type": "number",
"format": "double"
Expand Down Expand Up @@ -165360,7 +165264,7 @@
"unpublished": false,
"deprecated": false,
"examples": [
"assertEqual(rem(int(7), int(4)), 3, 0.01, \"remainder is 3\")\nassertEqual(rem(int(-7), int(4)), -3, 0.01, \"remainder is 3\")\nassertEqual(rem(int(7), int(-4)), 3, 0.01, \"remainder is 3\")"
"assertEqual(rem(7, 4), 3, 0.01, \"remainder is 3\")\nassertEqual(rem(-7, 4), -3, 0.01, \"remainder is 3\")\nassertEqual(rem(7, -4), 3, 0.01, \"remainder is 3\")"
]
},
{
Expand Down Expand Up @@ -169249,6 +169153,43 @@
"sketch001 = startSketchOn('XY')\n |> startProfileAt([10, 0], %)\n |> line([5, -5], %)\n |> line([5, 5], %)\n |> lineTo([profileStartX(%), profileStartY(%)], %)\n |> close(%)\n\npart001 = revolve({\n axis = {\n custom = {\n axis = [0.0, 1.0],\n origin = [0.0, 0.0]\n }\n }\n}, sketch001)"
]
},
{
"name": "round",
"summary": "Round a number to the nearest integer.",
"description": "",
"tags": [
"math"
],
"args": [
{
"name": "num",
"type": "number",
"schema": {
"$schema": "https://spec.openapis.org/oas/3.0/schema/2019-04-02#/definitions/Schema",
"title": "double",
"type": "number",
"format": "double"
},
"required": true
}
],
"returnValue": {
"name": "",
"type": "number",
"schema": {
"$schema": "https://spec.openapis.org/oas/3.0/schema/2019-04-02#/definitions/Schema",
"title": "double",
"type": "number",
"format": "double"
},
"required": true
},
"unpublished": false,
"deprecated": false,
"examples": [
"sketch001 = startSketchOn('XZ')\n |> startProfileAt([0, 0], %)\n |> lineTo([12, 10], %)\n |> line([round(7.02986), 0], %)\n |> yLineTo(0, %)\n |> close(%)\n\nextrude001 = extrude(5, sketch001)"
]
},
{
"name": "segAng",
"summary": "Compute the angle (in degrees) of the provided line segment.",
Expand Down
2 changes: 1 addition & 1 deletion docs/kcl/types/CircularPattern2dData.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Data for a circular pattern on a 2D sketch.

| Property | Type | Description | Required |
|----------|------|-------------|----------|
| `instances` |[`Uint`](/docs/kcl/types/Uint)| The number of total instances. Must be greater than or equal to 1. This includes the original entity. For example, if instances is 2, there will be two copies -- the original, and one new copy. If instances is 1, this has no effect. | No |
| `instances` |`integer`| The number of total instances. Must be greater than or equal to 1. This includes the original entity. For example, if instances is 2, there will be two copies -- the original, and one new copy. If instances is 1, this has no effect. | No |
| `center` |`[number, number]`| The center about which to make the pattern. This is a 2D vector. | No |
| `arcDegrees` |`number`| The arc angle (in degrees) to place the repetitions. Must be greater than 0. | No |
| `rotateDuplicates` |`boolean`| Whether or not to rotate the duplicates as they are copied. | No |
Expand Down
Loading

0 comments on commit 4fe17fe

Please sign in to comment.