Move more functions to KCL decls (#7266)

* Move some sketch functions to KCL

Signed-off-by: Nick Cameron <nrc@ncameron.org>

* Move asserts to KCL

Signed-off-by: Nick Cameron <nrc@ncameron.org>

* sweep, loft -> KCL

Signed-off-by: Nick Cameron <nrc@ncameron.org>

* Move pattern transforms to KCL

Signed-off-by: Nick Cameron <nrc@ncameron.org>

---------

Signed-off-by: Nick Cameron <nrc@ncameron.org>
This commit is contained in:
Nick Cameron
2025-05-30 11:00:16 +12:00
committed by GitHub
parent 46b6707e3a
commit 80e3dc9095
52 changed files with 974 additions and 78951 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,50 @@
---
title: "assert"
subtitle: "Function in std"
excerpt: ""
layout: manual
---
```kcl
assert(
@actual: number,
isGreaterThan?: number,
isLessThan?: number,
isGreaterThanOrEqual?: number,
isLessThanOrEqual?: number,
isEqualTo?: number,
tolerance?: number,
error?: string,
)
```
Check a value meets some expected conditions at runtime. Program terminates with an error if conditions aren't met.
If you provide multiple conditions, they will all be checked and all must be met.
### Arguments
| Name | Type | Description | Required |
|----------|------|-------------|----------|
| `actual` | [`number`](/docs/kcl-std/types/std-types-number) | Value to check. If this is the boolean value true, assert passes. Otherwise it fails.. | Yes |
| `isGreaterThan` | [`number`](/docs/kcl-std/types/std-types-number) | Comparison argument. If given, checks the `actual` value is greater than this. | No |
| `isLessThan` | [`number`](/docs/kcl-std/types/std-types-number) | Comparison argument. If given, checks the `actual` value is less than this. | No |
| `isGreaterThanOrEqual` | [`number`](/docs/kcl-std/types/std-types-number) | Comparison argument. If given, checks the `actual` value is greater than or equal to this. | No |
| `isLessThanOrEqual` | [`number`](/docs/kcl-std/types/std-types-number) | Comparison argument. If given, checks the `actual` value is less than or equal to this. | No |
| `isEqualTo` | [`number`](/docs/kcl-std/types/std-types-number) | Comparison argument. If given, checks the `actual` value is less than or equal to this. | No |
| `tolerance` | [`number`](/docs/kcl-std/types/std-types-number) | If `isEqualTo` is used, this is the tolerance to allow for the comparison. This tolerance is used because KCL's number system has some floating-point imprecision when used with very large decimal places. | No |
| `error` | [`string`](/docs/kcl-std/types/std-types-string) | If the value was false, the program will terminate with this error message | No |
### Examples
```kcl
n = 10
assert(n, isEqualTo = 10)
assert(n, isGreaterThanOrEqual = 0, isLessThan = 100, error = "number should be between 0 and 100")
assert(1.0000000000012, isEqualTo = 1, tolerance = 0.0001, error = "number should be almost exactly 1")
```

View File

@ -0,0 +1,35 @@
---
title: "assertIs"
subtitle: "Function in std"
excerpt: "Asserts that a value is the boolean value true."
layout: manual
---
Asserts that a value is the boolean value true.
```kcl
assertIs(
@actual: bool,
error?: string,
)
```
### Arguments
| Name | Type | Description | Required |
|----------|------|-------------|----------|
| `actual` | [`bool`](/docs/kcl-std/types/std-types-bool) | Value to check. If this is the boolean value true, assert passes. Otherwise it fails.. | Yes |
| `error` | [`string`](/docs/kcl-std/types/std-types-string) | If the value was false, the program will terminate with this error message | No |
### Examples
```kcl
kclIsFun = true
assertIs(kclIsFun)
```

View File

@ -9,7 +9,7 @@ layout: manual
```kcl ```kcl
circle( circle(
@sketch_or_surface: Sketch | Plane | Face, @sketchOrSurface: Sketch | Plane | Face,
center: Point2d, center: Point2d,
radius?: number(Length), radius?: number(Length),
diameter?: number(Length), diameter?: number(Length),
@ -24,7 +24,7 @@ the provided (x, y) origin point.
| Name | Type | Description | Required | | Name | Type | Description | Required |
|----------|------|-------------|----------| |----------|------|-------------|----------|
| `sketch_or_surface` | [`Sketch`](/docs/kcl-std/types/std-types-Sketch) or [`Plane`](/docs/kcl-std/types/std-types-Plane) or [`Face`](/docs/kcl-std/types/std-types-Face) | Sketch to extend, or plane or surface to sketch on. | Yes | | `sketchOrSurface` | [`Sketch`](/docs/kcl-std/types/std-types-Sketch) or [`Plane`](/docs/kcl-std/types/std-types-Plane) or [`Face`](/docs/kcl-std/types/std-types-Face) | Sketch to extend, or plane or surface to sketch on. | Yes |
| `center` | [`Point2d`](/docs/kcl-std/types/std-types-Point2d) | The center of the circle. | Yes | | `center` | [`Point2d`](/docs/kcl-std/types/std-types-Point2d) | The center of the circle. | Yes |
| `radius` | [`number(Length)`](/docs/kcl-std/types/std-types-number) | The radius of the circle. Incompatible with `diameter`. | No | | `radius` | [`number(Length)`](/docs/kcl-std/types/std-types-number) | The radius of the circle. Incompatible with `diameter`. | No |
| `diameter` | [`number(Length)`](/docs/kcl-std/types/std-types-number) | The diameter of the circle. Incompatible with `radius`. | No | | `diameter` | [`number(Length)`](/docs/kcl-std/types/std-types-number) | The diameter of the circle. Incompatible with `radius`. | No |

View File

@ -9,11 +9,11 @@ Construct a circle derived from 3 points.
```kcl ```kcl
circleThreePoint( circleThreePoint(
@sketchSurfaceOrGroup: Sketch | Plane | Face, @sketchOrSurface: Sketch | Plane | Face,
p1: Point2d, p1: Point2d,
p2: Point2d, p2: Point2d,
p3: Point2d, p3: Point2d,
tag?: TagDeclarator, tag?: tag,
): Sketch ): Sketch
``` ```
@ -23,11 +23,11 @@ circleThreePoint(
| Name | Type | Description | Required | | Name | Type | Description | Required |
|----------|------|-------------|----------| |----------|------|-------------|----------|
| `sketchSurfaceOrGroup` | [`Sketch`](/docs/kcl-std/types/std-types-Sketch) or [`Plane`](/docs/kcl-std/types/std-types-Plane) or [`Face`](/docs/kcl-std/types/std-types-Face) | Plane or surface to sketch on. | Yes | | `sketchOrSurface` | [`Sketch`](/docs/kcl-std/types/std-types-Sketch) or [`Plane`](/docs/kcl-std/types/std-types-Plane) or [`Face`](/docs/kcl-std/types/std-types-Face) | Plane or surface to sketch on. | Yes |
| `p1` | [`Point2d`](/docs/kcl-std/types/std-types-Point2d) | 1st point to derive the circle. | Yes | | `p1` | [`Point2d`](/docs/kcl-std/types/std-types-Point2d) | 1st point to derive the circle. | Yes |
| `p2` | [`Point2d`](/docs/kcl-std/types/std-types-Point2d) | 2nd point to derive the circle. | Yes | | `p2` | [`Point2d`](/docs/kcl-std/types/std-types-Point2d) | 2nd point to derive the circle. | Yes |
| `p3` | [`Point2d`](/docs/kcl-std/types/std-types-Point2d) | 3rd point to derive the circle. | Yes | | `p3` | [`Point2d`](/docs/kcl-std/types/std-types-Point2d) | 3rd point to derive the circle. | Yes |
| [`tag`](/docs/kcl-std/types/std-types-tag) | [`TagDeclarator`](/docs/kcl-lang/types#TagDeclarator) | Identifier for the circle to reference elsewhere. | No | | [`tag`](/docs/kcl-std/types/std-types-tag) | [`tag`](/docs/kcl-std/types/std-types-tag) | Identifier for the circle to reference elsewhere. | No |
### Returns ### Returns
@ -38,7 +38,7 @@ circleThreePoint(
```kcl ```kcl
exampleSketch = startSketchOn(XY) exampleSketch = startSketchOn(XY)
|> circleThreePoint(p1 = [10, 10], p2 = [20, 8], p3 = [15, 5]) |> circleThreePoint(p1 = [10,10], p2 = [20,8], p3 = [15,5])
|> extrude(length = 5) |> extrude(length = 5)
``` ```

View File

@ -1,39 +1,43 @@
--- ---
title: "extrude" title: "extrude"
subtitle: "Function in std::sketch" subtitle: "Function in std::sketch"
excerpt: "Extend a 2-dimensional sketch through a third dimension in order to create new 3-dimensional volume, or if extruded into an existing volume, cut into an existing solid." excerpt: ""
layout: manual layout: manual
--- ---
Extend a 2-dimensional sketch through a third dimension in order to create new 3-dimensional volume, or if extruded into an existing volume, cut into an existing solid.
```kcl ```kcl
extrude( extrude(
@sketches: [Sketch], @sketches: [Sketch; 1+],
length: number, length: number(Length),
symmetric?: bool, symmetric?: bool,
bidirectionalLength?: number, bidirectionalLength?: number(Length),
tagStart?: TagDeclarator, tagStart?: tag,
tagEnd?: TagDeclarator, tagEnd?: tag,
): [Solid] ): [Solid; 1+]
``` ```
You can provide more than one sketch to extrude, and they will all be extruded in the same direction. Extend a 2-dimensional sketch through a third dimension in order to
create new 3-dimensional volume, or if extruded into an existing volume,cut into an existing solid.
You can provide more than one sketch to extrude, and they will all be
extruded in the same direction.
### Arguments ### Arguments
| Name | Type | Description | Required | | Name | Type | Description | Required |
|----------|------|-------------|----------| |----------|------|-------------|----------|
| `sketches` | [`[Sketch]`](/docs/kcl-std/types/std-types-Sketch) | Which sketch or sketches should be extruded | Yes | | `sketches` | [`[Sketch; 1+]`](/docs/kcl-std/types/std-types-Sketch) | Which sketch or sketches should be extruded. | Yes |
| `length` | [`number`](/docs/kcl-std/types/std-types-number) | How far to extrude the given sketches | Yes | | `length` | [`number(Length)`](/docs/kcl-std/types/std-types-number) | How far to extrude the given sketches. | Yes |
| `symmetric` | [`bool`](/docs/kcl-std/types/std-types-bool) | If true, the extrusion will happen symmetrically around the sketch. Otherwise, the extrusion will happen on only one side of the sketch. | No | | `symmetric` | [`bool`](/docs/kcl-std/types/std-types-bool) | If true, the extrusion will happen symmetrically around the sketch. Otherwise, the extrusion will happen on only one side of the sketch. | No |
| `bidirectionalLength` | [`number`](/docs/kcl-std/types/std-types-number) | If specified, will also extrude in the opposite direction to 'distance' to the specified distance. If 'symmetric' is true, this value is ignored. | No | | `bidirectionalLength` | [`number(Length)`](/docs/kcl-std/types/std-types-number) | If specified, will also extrude in the opposite direction to 'distance' to the specified distance. If 'symmetric' is true, this value is ignored. | No |
| `tagStart` | [`TagDeclarator`](/docs/kcl-lang/types#TagDeclarator) | A named tag for the face at the start of the extrusion, i.e. the original sketch | No | | `tagStart` | [`tag`](/docs/kcl-std/types/std-types-tag) | A named tag for the face at the start of the extrusion, i.e. the original sketch. | No |
| `tagEnd` | [`TagDeclarator`](/docs/kcl-lang/types#TagDeclarator) | A named tag for the face at the end of the extrusion, i.e. the new face created by extruding the original sketch | No | | `tagEnd` | [`tag`](/docs/kcl-std/types/std-types-tag) | A named tag for the face at the end of the extrusion, i.e. the new face created by extruding the original sketch. | No |
### Returns ### Returns
[`[Solid]`](/docs/kcl-std/types/std-types-Solid) [`[Solid; 1+]`](/docs/kcl-std/types/std-types-Solid)
### Examples ### Examples
@ -42,10 +46,18 @@ You can provide more than one sketch to extrude, and they will all be extruded i
example = startSketchOn(XZ) example = startSketchOn(XZ)
|> startProfile(at = [0, 0]) |> startProfile(at = [0, 0])
|> line(end = [10, 0]) |> line(end = [10, 0])
|> arc(angleStart = 120, angleEnd = 0, radius = 5) |> arc(
angleStart = 120,
angleEnd = 0,
radius = 5,
)
|> line(end = [5, 0]) |> line(end = [5, 0])
|> line(end = [0, 10]) |> line(end = [0, 10])
|> bezierCurve(control1 = [-10, 0], control2 = [2, 10], end = [-5, 10]) |> bezierCurve(
control1 = [-10, 0],
control2 = [2, 10],
end = [-5, 10],
)
|> line(end = [-5, -2]) |> line(end = [-5, -2])
|> close() |> close()
|> extrude(length = 10) |> extrude(length = 10)
@ -56,10 +68,18 @@ example = startSketchOn(XZ)
```kcl ```kcl
exampleSketch = startSketchOn(XZ) exampleSketch = startSketchOn(XZ)
|> startProfile(at = [-10, 0]) |> startProfile(at = [-10, 0])
|> arc(angleStart = 120, angleEnd = -60, radius = 5) |> arc(
angleStart = 120,
angleEnd = -60,
radius = 5,
)
|> line(end = [10, 0]) |> line(end = [10, 0])
|> line(end = [5, 0]) |> line(end = [5, 0])
|> bezierCurve(control1 = [-3, 0], control2 = [2, 10], end = [-5, 10]) |> bezierCurve(
control1 = [-3, 0],
control2 = [2, 10],
end = [-5, 10],
)
|> line(end = [-4, 10]) |> line(end = [-4, 10])
|> line(end = [-5, -2]) |> line(end = [-5, -2])
|> close() |> close()
@ -72,10 +92,18 @@ example = extrude(exampleSketch, length = 10)
```kcl ```kcl
exampleSketch = startSketchOn(XZ) exampleSketch = startSketchOn(XZ)
|> startProfile(at = [-10, 0]) |> startProfile(at = [-10, 0])
|> arc(angleStart = 120, angleEnd = -60, radius = 5) |> arc(
angleStart = 120,
angleEnd = -60,
radius = 5,
)
|> line(end = [10, 0]) |> line(end = [10, 0])
|> line(end = [5, 0]) |> line(end = [5, 0])
|> bezierCurve(control1 = [-3, 0], control2 = [2, 10], end = [-5, 10]) |> bezierCurve(
control1 = [-3, 0],
control2 = [2, 10],
end = [-5, 10],
)
|> line(end = [-4, 10]) |> line(end = [-4, 10])
|> line(end = [-5, -2]) |> line(end = [-5, -2])
|> close() |> close()
@ -88,10 +116,18 @@ example = extrude(exampleSketch, length = 20, symmetric = true)
```kcl ```kcl
exampleSketch = startSketchOn(XZ) exampleSketch = startSketchOn(XZ)
|> startProfile(at = [-10, 0]) |> startProfile(at = [-10, 0])
|> arc(angleStart = 120, angleEnd = -60, radius = 5) |> arc(
angleStart = 120,
angleEnd = -60,
radius = 5,
)
|> line(end = [10, 0]) |> line(end = [10, 0])
|> line(end = [5, 0]) |> line(end = [5, 0])
|> bezierCurve(control1 = [-3, 0], control2 = [2, 10], end = [-5, 10]) |> bezierCurve(
control1 = [-3, 0],
control2 = [2, 10],
end = [-5, 10],
)
|> line(end = [-4, 10]) |> line(end = [-4, 10])
|> line(end = [-5, -2]) |> line(end = [-5, -2])
|> close() |> close()

File diff suppressed because one or more lines are too long

View File

@ -1,39 +1,41 @@
--- ---
title: "patternCircular2d" title: "patternCircular2d"
subtitle: "Function in std::sketch" subtitle: "Function in std::sketch"
excerpt: "Repeat a 2-dimensional sketch some number of times along a partial or complete circle some specified number of times. Each object may additionally be rotated along the circle, ensuring orientation of the solid with respect to the center of the circle is maintained." excerpt: ""
layout: manual layout: manual
--- ---
Repeat a 2-dimensional sketch some number of times along a partial or complete circle some specified number of times. Each object may additionally be rotated along the circle, ensuring orientation of the solid with respect to the center of the circle is maintained.
```kcl ```kcl
patternCircular2d( patternCircular2d(
@sketchSet: [Sketch], @sketches: [Sketch; 1+],
instances: number, instances: number(_),
center: Point2d, center: Point2d,
arcDegrees?: number, arcDegrees?: number(Angle),
rotateDuplicates?: bool, rotateDuplicates?: bool,
useOriginal?: bool, useOriginal?: bool,
): [Sketch] ): [Sketch; 1+]
``` ```
Repeat a 2-dimensional sketch some number of times along a partial or
complete circle some specified number of times. Each object mayadditionally be rotated along the circle, ensuring orientation of the
solid with respect to the center of the circle is maintained.
### Arguments ### Arguments
| Name | Type | Description | Required | | Name | Type | Description | Required |
|----------|------|-------------|----------| |----------|------|-------------|----------|
| `sketchSet` | [`[Sketch]`](/docs/kcl-std/types/std-types-Sketch) | Which sketch(es) to pattern | Yes | | `sketches` | [`[Sketch; 1+]`](/docs/kcl-std/types/std-types-Sketch) | The sketch(es) to duplicate. | Yes |
| `instances` | [`number`](/docs/kcl-std/types/std-types-number) | 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. | Yes | | `instances` | [`number(_)`](/docs/kcl-std/types/std-types-number) | 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. | Yes |
| `center` | [`Point2d`](/docs/kcl-std/types/std-types-Point2d) | The center about which to make the pattern. This is a 2D vector. | Yes | | `center` | [`Point2d`](/docs/kcl-std/types/std-types-Point2d) | The center about which to make the pattern. This is a 2D vector. | Yes |
| `arcDegrees` | [`number`](/docs/kcl-std/types/std-types-number) | The arc angle (in degrees) to place the repetitions. Must be greater than 0. Defaults to 360. | No | | `arcDegrees` | [`number(Angle)`](/docs/kcl-std/types/std-types-number) | The arc angle (in degrees) to place the repetitions. Must be greater than 0. | No |
| `rotateDuplicates` | [`bool`](/docs/kcl-std/types/std-types-bool) | Whether or not to rotate the duplicates as they are copied. Defaults to true. | No | | `rotateDuplicates` | [`bool`](/docs/kcl-std/types/std-types-bool) | Whether or not to rotate the duplicates as they are copied. | No |
| `useOriginal` | [`bool`](/docs/kcl-std/types/std-types-bool) | If the target was sketched on an extrusion, setting this will use the original sketch as the target, not the entire joined solid. Defaults to false. | No | | `useOriginal` | [`bool`](/docs/kcl-std/types/std-types-bool) | If the target was sketched on an extrusion, setting this will use the original sketch as the target, not the entire joined solid. | No |
### Returns ### Returns
[`[Sketch]`](/docs/kcl-std/types/std-types-Sketch) [`[Sketch; 1+]`](/docs/kcl-std/types/std-types-Sketch)
### Examples ### Examples
@ -49,7 +51,7 @@ exampleSketch = startSketchOn(XZ)
center = [0, 0], center = [0, 0],
instances = 13, instances = 13,
arcDegrees = 360, arcDegrees = 360,
rotateDuplicates = true, rotateDuplicates = true
) )
example = extrude(exampleSketch, length = 1) example = extrude(exampleSketch, length = 1)

File diff suppressed because one or more lines are too long

View File

@ -9,9 +9,9 @@ Create a regular polygon with the specified number of sides that is either inscr
```kcl ```kcl
polygon( polygon(
@sketchSurfaceOrGroup: Sketch | Plane | Face, @sketchOrSurface: Sketch | Plane | Face,
radius: number, radius: number(Length),
numSides: u64, numSides: number(_),
center: Point2d, center: Point2d,
inscribed?: bool, inscribed?: bool,
): Sketch ): Sketch
@ -23,11 +23,11 @@ polygon(
| Name | Type | Description | Required | | Name | Type | Description | Required |
|----------|------|-------------|----------| |----------|------|-------------|----------|
| `sketchSurfaceOrGroup` | [`Sketch`](/docs/kcl-std/types/std-types-Sketch) or [`Plane`](/docs/kcl-std/types/std-types-Plane) or [`Face`](/docs/kcl-std/types/std-types-Face) | Plane or surface to sketch on | Yes | | `sketchOrSurface` | [`Sketch`](/docs/kcl-std/types/std-types-Sketch) or [`Plane`](/docs/kcl-std/types/std-types-Plane) or [`Face`](/docs/kcl-std/types/std-types-Face) | Plane or surface to sketch on. | Yes |
| `radius` | [`number`](/docs/kcl-std/types/std-types-number) | The radius of the polygon | Yes | | `radius` | [`number(Length)`](/docs/kcl-std/types/std-types-number) | The radius of the polygon. | Yes |
| `numSides` | `u64` | The number of sides in the polygon | Yes | | `numSides` | [`number(_)`](/docs/kcl-std/types/std-types-number) | The number of sides in the polygon. | Yes |
| `center` | [`Point2d`](/docs/kcl-std/types/std-types-Point2d) | The center point of the polygon | Yes | | `center` | [`Point2d`](/docs/kcl-std/types/std-types-Point2d) | The center point of the polygon. | Yes |
| `inscribed` | [`bool`](/docs/kcl-std/types/std-types-bool) | Whether the polygon is inscribed (true, the default) or circumscribed (false) about a circle with the specified radius | No | | `inscribed` | [`bool`](/docs/kcl-std/types/std-types-bool) | Whether the polygon is inscribed (true, the default) or circumscribed (false) about a circle with the specified radius. | No |
### Returns ### Returns

View File

@ -9,35 +9,40 @@ Extrude a sketch along a path.
```kcl ```kcl
sweep( sweep(
@sketches: [Sketch], @sketches: [Sketch; 1+],
path: Sketch | Helix, path: Sketch | Helix,
sectional?: bool, sectional?: bool,
tolerance?: number, tolerance?: number(Length),
relativeTo?: string, relativeTo?: string,
tagStart?: TagDeclarator, tagStart?: tag,
tagEnd?: TagDeclarator, tagEnd?: tag,
): [Solid] ): [Solid; 1+]
``` ```
This, like extrude, is able to create a 3-dimensional solid from a 2-dimensional sketch. However, unlike extrude, this creates a solid by using the extent of the sketch as its path. This is useful for creating more complex shapes that can't be created with a simple extrusion. This, like extrude, is able to create a 3-dimensional solid from a
2-dimensional sketch. However, unlike extrude, this creates a solid
by using the extent of the sketch as its path. This is useful for
creating more complex shapes that can't be created with a simple
extrusion.
You can provide more than one sketch to sweep, and they will all be swept along the same path. You can provide more than one sketch to sweep, and they will all be
swept along the same path.
### Arguments ### Arguments
| Name | Type | Description | Required | | Name | Type | Description | Required |
|----------|------|-------------|----------| |----------|------|-------------|----------|
| `sketches` | [`[Sketch]`](/docs/kcl-std/types/std-types-Sketch) | The sketch or set of sketches that should be swept in space | Yes | | `sketches` | [`[Sketch; 1+]`](/docs/kcl-std/types/std-types-Sketch) | The sketch or set of sketches that should be swept in space. | Yes |
| `path` | [`Sketch`](/docs/kcl-std/types/std-types-Sketch) or [`Helix`](/docs/kcl-std/types/std-types-Helix) | The path to sweep the sketch along | Yes | | `path` | [`Sketch`](/docs/kcl-std/types/std-types-Sketch) or [`Helix`](/docs/kcl-std/types/std-types-Helix) | The path to sweep the sketch along. | Yes |
| `sectional` | [`bool`](/docs/kcl-std/types/std-types-bool) | If true, the sweep will be broken up into sub-sweeps (extrusions, revolves, sweeps) based on the trajectory path components. | No | | `sectional` | [`bool`](/docs/kcl-std/types/std-types-bool) | If true, the sweep will be broken up into sub-sweeps (extrusions, revolves, sweeps) based on the trajectory path components. | No |
| `tolerance` | [`number`](/docs/kcl-std/types/std-types-number) | Tolerance for this operation | No | | `tolerance` | [`number(Length)`](/docs/kcl-std/types/std-types-number) | Tolerance for this operation. | No |
| `relativeTo` | [`string`](/docs/kcl-std/types/std-types-string) | What is the sweep relative to? Can be either 'sketchPlane' or 'trajectoryCurve'. Defaults to trajectoryCurve. | No | | `relativeTo` | [`string`](/docs/kcl-std/types/std-types-string) | What is the sweep relative to? Can be either 'sketchPlane' or 'trajectoryCurve'. | No |
| `tagStart` | [`TagDeclarator`](/docs/kcl-lang/types#TagDeclarator) | A named tag for the face at the start of the sweep, i.e. the original sketch | No | | `tagStart` | [`tag`](/docs/kcl-std/types/std-types-tag) | A named tag for the face at the start of the sweep, i.e. the original sketch. | No |
| `tagEnd` | [`TagDeclarator`](/docs/kcl-lang/types#TagDeclarator) | A named tag for the face at the end of the sweep | No | | `tagEnd` | [`tag`](/docs/kcl-std/types/std-types-tag) | A named tag for the face at the end of the sweep. | No |
### Returns ### Returns
[`[Solid]`](/docs/kcl-std/types/std-types-Solid) [`[Solid; 1+]`](/docs/kcl-std/types/std-types-Solid)
### Examples ### Examples
@ -56,10 +61,16 @@ sweepPath = startSketchOn(XZ)
// Create a hole for the pipe. // Create a hole for the pipe.
pipeHole = startSketchOn(XY) pipeHole = startSketchOn(XY)
|> circle(center = [0, 0], radius = 1.5) |> circle(
center = [0, 0],
radius = 1.5,
)
sweepSketch = startSketchOn(XY) sweepSketch = startSketchOn(XY)
|> circle(center = [0, 0], radius = 2) |> circle(
center = [0, 0],
radius = 2,
)
|> subtract2d(tool = pipeHole) |> subtract2d(tool = pipeHole)
|> sweep(path = sweepPath) |> sweep(path = sweepPath)
``` ```
@ -77,11 +88,12 @@ helixPath = helix(
length = 10, length = 10,
radius = 5, radius = 5,
axis = Z, axis = Z,
) )
// Create a spring by sweeping around the helix path. // Create a spring by sweeping around the helix path.
springSketch = startSketchOn(XZ) springSketch = startSketchOn(XZ)
|> circle(center = [5, 0], radius = 1) |> circle( center = [5, 0], radius = 1)
|> sweep(path = helixPath) |> sweep(path = helixPath)
``` ```
@ -90,12 +102,17 @@ springSketch = startSketchOn(XZ)
```kcl ```kcl
// Sweep two sketches along the same path. // Sweep two sketches along the same path.
sketch001 = startSketchOn(XY) sketch001 = startSketchOn(XY)
rectangleSketch = startProfile(sketch001, at = [-200, 23.86]) rectangleSketch = startProfile(sketch001, at = [-200, 23.86])
|> angledLine(angle = 0, length = 73.47, tag = $rectangleSegmentA001) |> angledLine(angle = 0, length = 73.47, tag = $rectangleSegmentA001)
|> angledLine(angle = segAng(rectangleSegmentA001) - 90, length = 50.61) |> angledLine(
|> angledLine(angle = segAng(rectangleSegmentA001), length = -segLen(rectangleSegmentA001)) angle = segAng(rectangleSegmentA001) - 90,
length = 50.61,
)
|> angledLine(
angle = segAng(rectangleSegmentA001),
length = -segLen(rectangleSegmentA001),
)
|> line(endAbsolute = [profileStartX(%), profileStartY(%)]) |> line(endAbsolute = [profileStartX(%), profileStartY(%)])
|> close() |> close()
@ -115,7 +132,6 @@ sweep([rectangleSketch, circleSketch], path = sweepPath)
```kcl ```kcl
// Sectionally sweep one sketch along the path // Sectionally sweep one sketch along the path
sketch001 = startSketchOn(XY) sketch001 = startSketchOn(XY)
circleSketch = circle(sketch001, center = [200, -30.29], radius = 32.63) circleSketch = circle(sketch001, center = [200, -30.29], radius = 32.63)

View File

@ -9,12 +9,11 @@ layout: manual
### Functions ### Functions
* [**std**](/docs/kcl-std/modules/std) * [**std**](/docs/kcl-std/modules/std)
* [`assert`](/docs/kcl-std/assert) * [`assert`](/docs/kcl-std/functions/std-assert)
* [`assertIs`](/docs/kcl-std/assertIs) * [`assertIs`](/docs/kcl-std/functions/std-assertIs)
* [`clone`](/docs/kcl-std/functions/std-clone) * [`clone`](/docs/kcl-std/functions/std-clone)
* [`helix`](/docs/kcl-std/functions/std-helix) * [`helix`](/docs/kcl-std/functions/std-helix)
* [`offsetPlane`](/docs/kcl-std/functions/std-offsetPlane) * [`offsetPlane`](/docs/kcl-std/functions/std-offsetPlane)
* [`patternLinear2d`](/docs/kcl-std/patternLinear2d)
* [**std::appearance**](/docs/kcl-std/modules/std-appearance) * [**std::appearance**](/docs/kcl-std/modules/std-appearance)
* [`appearance::hexString`](/docs/kcl-std/functions/std-appearance-hexString) * [`appearance::hexString`](/docs/kcl-std/functions/std-appearance-hexString)
* [**std::array**](/docs/kcl-std/modules/std-array) * [**std::array**](/docs/kcl-std/modules/std-array)
@ -53,9 +52,9 @@ layout: manual
* [`arc`](/docs/kcl-std/arc) * [`arc`](/docs/kcl-std/arc)
* [`bezierCurve`](/docs/kcl-std/bezierCurve) * [`bezierCurve`](/docs/kcl-std/bezierCurve)
* [`circle`](/docs/kcl-std/functions/std-sketch-circle) * [`circle`](/docs/kcl-std/functions/std-sketch-circle)
* [`circleThreePoint`](/docs/kcl-std/circleThreePoint) * [`circleThreePoint`](/docs/kcl-std/functions/std-sketch-circleThreePoint)
* [`close`](/docs/kcl-std/close) * [`close`](/docs/kcl-std/close)
* [`extrude`](/docs/kcl-std/extrude) * [`extrude`](/docs/kcl-std/functions/std-sketch-extrude)
* [`getCommonEdge`](/docs/kcl-std/functions/std-sketch-getCommonEdge) * [`getCommonEdge`](/docs/kcl-std/functions/std-sketch-getCommonEdge)
* [`getNextAdjacentEdge`](/docs/kcl-std/functions/std-sketch-getNextAdjacentEdge) * [`getNextAdjacentEdge`](/docs/kcl-std/functions/std-sketch-getNextAdjacentEdge)
* [`getOppositeEdge`](/docs/kcl-std/functions/std-sketch-getOppositeEdge) * [`getOppositeEdge`](/docs/kcl-std/functions/std-sketch-getOppositeEdge)
@ -64,10 +63,11 @@ layout: manual
* [`lastSegX`](/docs/kcl-std/lastSegX) * [`lastSegX`](/docs/kcl-std/lastSegX)
* [`lastSegY`](/docs/kcl-std/lastSegY) * [`lastSegY`](/docs/kcl-std/lastSegY)
* [`line`](/docs/kcl-std/line) * [`line`](/docs/kcl-std/line)
* [`loft`](/docs/kcl-std/loft) * [`loft`](/docs/kcl-std/functions/std-sketch-loft)
* [`patternCircular2d`](/docs/kcl-std/patternCircular2d) * [`patternCircular2d`](/docs/kcl-std/functions/std-sketch-patternCircular2d)
* [`patternLinear2d`](/docs/kcl-std/functions/std-sketch-patternLinear2d)
* [`patternTransform2d`](/docs/kcl-std/functions/std-sketch-patternTransform2d) * [`patternTransform2d`](/docs/kcl-std/functions/std-sketch-patternTransform2d)
* [`polygon`](/docs/kcl-std/polygon) * [`polygon`](/docs/kcl-std/functions/std-sketch-polygon)
* [`profileStart`](/docs/kcl-std/profileStart) * [`profileStart`](/docs/kcl-std/profileStart)
* [`profileStartX`](/docs/kcl-std/profileStartX) * [`profileStartX`](/docs/kcl-std/profileStartX)
* [`profileStartY`](/docs/kcl-std/profileStartY) * [`profileStartY`](/docs/kcl-std/profileStartY)
@ -83,7 +83,7 @@ layout: manual
* [`startProfile`](/docs/kcl-std/startProfile) * [`startProfile`](/docs/kcl-std/startProfile)
* [`startSketchOn`](/docs/kcl-std/startSketchOn) * [`startSketchOn`](/docs/kcl-std/startSketchOn)
* [`subtract2d`](/docs/kcl-std/subtract2d) * [`subtract2d`](/docs/kcl-std/subtract2d)
* [`sweep`](/docs/kcl-std/sweep) * [`sweep`](/docs/kcl-std/functions/std-sketch-sweep)
* [`tangentToEnd`](/docs/kcl-std/tangentToEnd) * [`tangentToEnd`](/docs/kcl-std/tangentToEnd)
* [`tangentialArc`](/docs/kcl-std/tangentialArc) * [`tangentialArc`](/docs/kcl-std/tangentialArc)
* [`xLine`](/docs/kcl-std/xLine) * [`xLine`](/docs/kcl-std/xLine)

View File

@ -17,9 +17,9 @@ This module contains functions for creating and manipulating sketches, and makin
* [`arc`](/docs/kcl-std/arc) * [`arc`](/docs/kcl-std/arc)
* [`bezierCurve`](/docs/kcl-std/bezierCurve) * [`bezierCurve`](/docs/kcl-std/bezierCurve)
* [`circle`](/docs/kcl-std/functions/std-sketch-circle) * [`circle`](/docs/kcl-std/functions/std-sketch-circle)
* [`circleThreePoint`](/docs/kcl-std/circleThreePoint) * [`circleThreePoint`](/docs/kcl-std/functions/std-sketch-circleThreePoint)
* [`close`](/docs/kcl-std/close) * [`close`](/docs/kcl-std/close)
* [`extrude`](/docs/kcl-std/extrude) * [`extrude`](/docs/kcl-std/functions/std-sketch-extrude)
* [`getCommonEdge`](/docs/kcl-std/functions/std-sketch-getCommonEdge) * [`getCommonEdge`](/docs/kcl-std/functions/std-sketch-getCommonEdge)
* [`getNextAdjacentEdge`](/docs/kcl-std/functions/std-sketch-getNextAdjacentEdge) * [`getNextAdjacentEdge`](/docs/kcl-std/functions/std-sketch-getNextAdjacentEdge)
* [`getOppositeEdge`](/docs/kcl-std/functions/std-sketch-getOppositeEdge) * [`getOppositeEdge`](/docs/kcl-std/functions/std-sketch-getOppositeEdge)
@ -28,10 +28,11 @@ This module contains functions for creating and manipulating sketches, and makin
* [`lastSegX`](/docs/kcl-std/lastSegX) * [`lastSegX`](/docs/kcl-std/lastSegX)
* [`lastSegY`](/docs/kcl-std/lastSegY) * [`lastSegY`](/docs/kcl-std/lastSegY)
* [`line`](/docs/kcl-std/line) * [`line`](/docs/kcl-std/line)
* [`loft`](/docs/kcl-std/loft) * [`loft`](/docs/kcl-std/functions/std-sketch-loft)
* [`patternCircular2d`](/docs/kcl-std/patternCircular2d) * [`patternCircular2d`](/docs/kcl-std/functions/std-sketch-patternCircular2d)
* [`patternLinear2d`](/docs/kcl-std/functions/std-sketch-patternLinear2d)
* [`patternTransform2d`](/docs/kcl-std/functions/std-sketch-patternTransform2d) * [`patternTransform2d`](/docs/kcl-std/functions/std-sketch-patternTransform2d)
* [`polygon`](/docs/kcl-std/polygon) * [`polygon`](/docs/kcl-std/functions/std-sketch-polygon)
* [`profileStart`](/docs/kcl-std/profileStart) * [`profileStart`](/docs/kcl-std/profileStart)
* [`profileStartX`](/docs/kcl-std/profileStartX) * [`profileStartX`](/docs/kcl-std/profileStartX)
* [`profileStartY`](/docs/kcl-std/profileStartY) * [`profileStartY`](/docs/kcl-std/profileStartY)
@ -47,7 +48,7 @@ This module contains functions for creating and manipulating sketches, and makin
* [`startProfile`](/docs/kcl-std/startProfile) * [`startProfile`](/docs/kcl-std/startProfile)
* [`startSketchOn`](/docs/kcl-std/startSketchOn) * [`startSketchOn`](/docs/kcl-std/startSketchOn)
* [`subtract2d`](/docs/kcl-std/subtract2d) * [`subtract2d`](/docs/kcl-std/subtract2d)
* [`sweep`](/docs/kcl-std/sweep) * [`sweep`](/docs/kcl-std/functions/std-sketch-sweep)
* [`tangentToEnd`](/docs/kcl-std/tangentToEnd) * [`tangentToEnd`](/docs/kcl-std/tangentToEnd)
* [`tangentialArc`](/docs/kcl-std/tangentialArc) * [`tangentialArc`](/docs/kcl-std/tangentialArc)
* [`xLine`](/docs/kcl-std/xLine) * [`xLine`](/docs/kcl-std/xLine)

View File

@ -36,10 +36,9 @@ You might also want the [KCL language reference](/docs/kcl-lang) or the [KCL gui
* [`Y`](/docs/kcl-std/consts/std-Y) * [`Y`](/docs/kcl-std/consts/std-Y)
* [`YZ`](/docs/kcl-std/consts/std-YZ) * [`YZ`](/docs/kcl-std/consts/std-YZ)
* [`Z`](/docs/kcl-std/consts/std-Z) * [`Z`](/docs/kcl-std/consts/std-Z)
* [`assert`](/docs/kcl-std/assert) * [`assert`](/docs/kcl-std/functions/std-assert)
* [`assertIs`](/docs/kcl-std/assertIs) * [`assertIs`](/docs/kcl-std/functions/std-assertIs)
* [`clone`](/docs/kcl-std/functions/std-clone) * [`clone`](/docs/kcl-std/functions/std-clone)
* [`helix`](/docs/kcl-std/functions/std-helix) * [`helix`](/docs/kcl-std/functions/std-helix)
* [`offsetPlane`](/docs/kcl-std/functions/std-offsetPlane) * [`offsetPlane`](/docs/kcl-std/functions/std-offsetPlane)
* [`patternLinear2d`](/docs/kcl-std/patternLinear2d)

File diff suppressed because it is too large Load Diff

View File

@ -265,6 +265,7 @@ middle(0)
}) })
await expect( await expect(
page.getByText(`assert failed: Expected 0 to be greater than 0 but it wasn't page.getByText(`assert failed: Expected 0 to be greater than 0 but it wasn't
assert()
check() check()
middle()`) middle()`)
).toBeVisible() ).toBeVisible()

View File

@ -117,6 +117,23 @@ pub const TEST_NAMES: &[&str] = &[
"std-sketch-getOppositeEdge-0", "std-sketch-getOppositeEdge-0",
"std-sketch-getPreviousAdjacentEdge-0", "std-sketch-getPreviousAdjacentEdge-0",
"std-sketch-getNextAdjacentEdge-0", "std-sketch-getNextAdjacentEdge-0",
"std-sketch-extrude-0",
"std-sketch-extrude-1",
"std-sketch-extrude-2",
"std-sketch-extrude-3",
"std-sketch-polygon-0",
"std-sketch-polygon-1",
"std-sketch-sweep-0",
"std-sketch-sweep-1",
"std-sketch-sweep-2",
"std-sketch-sweep-3",
"std-sketch-loft-0",
"std-sketch-loft-1",
"std-sketch-loft-2",
"std-sketch-patternLinear2d-0",
"std-sketch-patternLinear2d-1",
"std-sketch-patternCircular2d-0",
"std-sketch-circleThreePoint-0",
"std-solid-appearance-0", "std-solid-appearance-0",
"std-solid-appearance-1", "std-solid-appearance-1",
"std-solid-appearance-2", "std-solid-appearance-2",

View File

@ -644,13 +644,13 @@ impl FnData {
format!("{}({})", self.preferred_name, args.join(", ")) format!("{}({})", self.preferred_name, args.join(", "))
} }
fn to_signature_help(&self) -> SignatureHelp { pub(crate) fn to_signature_help(&self) -> SignatureHelp {
// TODO Fill this in based on the current position of the cursor. // TODO Fill this in based on the current position of the cursor.
let active_parameter = None; let active_parameter = None;
SignatureHelp { SignatureHelp {
signatures: vec![SignatureInformation { signatures: vec![SignatureInformation {
label: self.preferred_name.clone(), label: self.preferred_name.clone() + &self.fn_signature(),
documentation: self.short_docs().map(|s| { documentation: self.short_docs().map(|s| {
Documentation::MarkupContent(MarkupContent { Documentation::MarkupContent(MarkupContent {
kind: MarkupKind::Markdown, kind: MarkupKind::Markdown,
@ -824,6 +824,7 @@ impl ArgData {
), ),
)), )),
Some("Axis2d | Edge") | Some("Axis3d | Edge") => Some((index, format!(r#"{label}${{{index}:X}}"#))), Some("Axis2d | Edge") | Some("Axis3d | Edge") => Some((index, format!(r#"{label}${{{index}:X}}"#))),
Some("Sketch") | Some("Sketch | Helix") => Some((index, format!(r#"{label}${{{index}:sketch000}}"#))),
Some("Edge") => Some((index, format!(r#"{label}${{{index}:tag_or_edge_fn}}"#))), Some("Edge") => Some((index, format!(r#"{label}${{{index}:tag_or_edge_fn}}"#))),
Some("[Edge; 1+]") => Some((index, format!(r#"{label}[${{{index}:tag_or_edge_fn}}]"#))), Some("[Edge; 1+]") => Some((index, format!(r#"{label}[${{{index}:tag_or_edge_fn}}]"#))),
Some("Plane") => Some((index, format!(r#"{label}${{{}:XY}}"#, index))), Some("Plane") => Some((index, format!(r#"{label}${{{}:XY}}"#, index))),
@ -1280,7 +1281,10 @@ mod test {
continue; continue;
}; };
for i in 0..f.examples.len() { for (i, (_, props)) in f.examples.iter().enumerate() {
if props.norun {
continue;
}
let name = format!("{}-{i}", f.qual_name.replace("::", "-")); let name = format!("{}-{i}", f.qual_name.replace("::", "-"));
assert!(TEST_NAMES.contains(&&*name), "Missing test for example \"{name}\", maybe need to update kcl-derive-docs/src/example_tests.rs?") assert!(TEST_NAMES.contains(&&*name), "Missing test for example \"{name}\", maybe need to update kcl-derive-docs/src/example_tests.rs?")
} }

View File

@ -976,9 +976,12 @@ mod tests {
#[test] #[test]
fn get_autocomplete_snippet_extrude() { fn get_autocomplete_snippet_extrude() {
let extrude_fn: Box<dyn StdLibFn> = Box::new(crate::std::extrude::Extrude); let data = kcl_doc::walk_prelude();
let snippet = extrude_fn.to_autocomplete_snippet().unwrap(); let DocData::Fn(data) = data.find_by_name("extrude").unwrap() else {
assert_eq!(snippet, r#"extrude(${0:%}, length = ${1:3.14})"#); panic!();
};
let snippet = data.to_autocomplete_snippet();
assert_eq!(snippet, r#"extrude(length = ${0:10})"#);
} }
#[test] #[test]
@ -1064,11 +1067,14 @@ mod tests {
#[test] #[test]
fn get_autocomplete_snippet_pattern_linear_2d() { fn get_autocomplete_snippet_pattern_linear_2d() {
let pattern_fn: Box<dyn StdLibFn> = Box::new(crate::std::patterns::PatternLinear2D); let data = kcl_doc::walk_prelude();
let snippet = pattern_fn.to_autocomplete_snippet().unwrap(); let DocData::Fn(data) = data.find_by_name("patternLinear2d").unwrap() else {
panic!();
};
let snippet = data.to_autocomplete_snippet();
assert_eq!( assert_eq!(
snippet, snippet,
r#"patternLinear2d(${0:%}, instances = ${1:10}, distance = ${2:3.14}, axis = [${3:1}, ${4:0}])"# r#"patternLinear2d(instances = ${0:10}, distance = ${1:10}, axis = [${2:1}, ${3:0}])"#
); );
} }
@ -1084,16 +1090,22 @@ mod tests {
#[test] #[test]
fn get_autocomplete_snippet_loft() { fn get_autocomplete_snippet_loft() {
let loft_fn: Box<dyn StdLibFn> = Box::new(crate::std::loft::Loft); let data = kcl_doc::walk_prelude();
let snippet = loft_fn.to_autocomplete_snippet().unwrap(); let DocData::Fn(data) = data.find_by_name("loft").unwrap() else {
panic!();
};
let snippet = data.to_autocomplete_snippet();
assert_eq!(snippet, r#"loft([${0:sketch000}, ${1:sketch001}])"#); assert_eq!(snippet, r#"loft([${0:sketch000}, ${1:sketch001}])"#);
} }
#[test] #[test]
fn get_autocomplete_snippet_sweep() { fn get_autocomplete_snippet_sweep() {
let sweep_fn: Box<dyn StdLibFn> = Box::new(crate::std::sweep::Sweep); let data = kcl_doc::walk_prelude();
let snippet = sweep_fn.to_autocomplete_snippet().unwrap(); let DocData::Fn(data) = data.find_by_name("sweep").unwrap() else {
assert_eq!(snippet, r#"sweep(${0:%}, path = ${1:sketch000})"#); panic!();
};
let snippet = data.to_autocomplete_snippet();
assert_eq!(snippet, r#"sweep(path = ${0:sketch000})"#);
} }
#[test] #[test]
@ -1225,18 +1237,21 @@ mod tests {
#[test] #[test]
fn get_extrude_signature_help() { fn get_extrude_signature_help() {
let extrude_fn: Box<dyn StdLibFn> = Box::new(crate::std::extrude::Extrude); let data = kcl_doc::walk_prelude();
let sh = extrude_fn.to_signature_help(); let DocData::Fn(data) = data.find_by_name("extrude").unwrap() else {
panic!();
};
let sh = data.to_signature_help();
assert_eq!( assert_eq!(
sh.signatures[0].label, sh.signatures[0].label,
r#"extrude( r#"extrude(
@sketches: [Sketch], @sketches: [Sketch; 1+],
length: number, length: number(Length),
symmetric?: bool, symmetric?: bool,
bidirectionalLength?: number, bidirectionalLength?: number(Length),
tagStart?: TagNode, tagStart?: tag,
tagEnd?: TagNode, tagEnd?: tag,
): [Solid]"# ): [Solid; 1+]"#
); );
} }
} }

View File

@ -1202,17 +1202,7 @@ a1 = startSketchOn(offsetPlane(XY, offset = 10))
"Expected one signature, got {:?}", "Expected one signature, got {:?}",
signature_help.signatures signature_help.signatures
); );
assert_eq!( assert!(signature_help.signatures[0].label.starts_with("extrude"));
signature_help.signatures[0].label,
r#"extrude(
@sketches: [Sketch],
length: number,
symmetric?: bool,
bidirectionalLength?: number,
tagStart?: TagNode,
tagEnd?: TagNode,
): [Solid]"#
);
} else { } else {
panic!("Expected signature help"); panic!("Expected signature help");
} }
@ -1300,17 +1290,7 @@ a1 = startSketchOn(offsetPlane(XY, offset = 10))
"Expected one signature, got {:?}", "Expected one signature, got {:?}",
signature_help.signatures signature_help.signatures
); );
assert_eq!( assert!(signature_help.signatures[0].label.starts_with("extrude"));
signature_help.signatures[0].label,
r#"extrude(
@sketches: [Sketch],
length: number,
symmetric?: bool,
bidirectionalLength?: number,
tagStart?: TagNode,
tagEnd?: TagNode,
): [Solid]"#
);
} else { } else {
panic!("Expected signature help"); panic!("Expected signature help");
} }
@ -1393,17 +1373,7 @@ a1 = startSketchOn(offsetPlane(XY, offset = 10))
"Expected one signature, got {:?}", "Expected one signature, got {:?}",
signature_help.signatures signature_help.signatures
); );
assert_eq!( assert!(signature_help.signatures[0].label.starts_with("extrude"));
signature_help.signatures[0].label,
r#"extrude(
@sketches: [Sketch],
length: number,
symmetric?: bool,
bidirectionalLength?: number,
tagStart?: TagNode,
tagEnd?: TagNode,
): [Solid]"#
);
} else { } else {
panic!("Expected signature help"); panic!("Expected signature help");
} }
@ -1491,17 +1461,7 @@ a1 = startSketchOn(offsetPlane(XY, offset = 10))
"Expected one signature, got {:?}", "Expected one signature, got {:?}",
signature_help.signatures signature_help.signatures
); );
assert_eq!( assert!(signature_help.signatures[0].label.starts_with("extrude"));
signature_help.signatures[0].label,
r#"extrude(
@sketches: [Sketch],
length: number,
symmetric?: bool,
bidirectionalLength?: number,
tagStart?: TagNode,
tagEnd?: TagNode,
): [Solid]"#
);
} else { } else {
panic!("Expected signature help"); panic!("Expected signature help");
} }

View File

@ -1,7 +1,6 @@
//! Standard library assert functions. //! Standard library assert functions.
use anyhow::Result; use anyhow::Result;
use kcl_derive_docs::stdlib;
use super::args::TyF64; use super::args::TyF64;
use crate::{ use crate::{
@ -42,19 +41,6 @@ pub async fn assert(exec_state: &mut ExecState, args: Args) -> Result<KclValue,
Ok(KclValue::none()) Ok(KclValue::none())
} }
/// Asserts that a value is the boolean value true.
/// ```no_run
/// kclIsFun = true
/// assertIs(kclIsFun)
/// ```
#[stdlib{
name = "assertIs",
unlabeled_first = true,
args = {
actual = { docs = "Value to check. If this is the boolean value true, assert passes. Otherwise it fails." },
error = { docs = "If the value was false, the program will terminate with this error message" },
}
}]
async fn inner_assert_is(actual: bool, error: Option<String>, args: &Args) -> Result<(), KclError> { async fn inner_assert_is(actual: bool, error: Option<String>, args: &Args) -> Result<(), KclError> {
let error_msg = match &error { let error_msg = match &error {
Some(x) => x, Some(x) => x,
@ -63,29 +49,6 @@ async fn inner_assert_is(actual: bool, error: Option<String>, args: &Args) -> Re
_assert(actual, error_msg, args).await _assert(actual, error_msg, args).await
} }
/// Check a value meets some expected conditions at runtime. Program terminates with an error if conditions aren't met.
/// If you provide multiple conditions, they will all be checked and all must be met.
///
/// ```no_run
/// n = 10
/// assert(n, isEqualTo = 10)
/// assert(n, isGreaterThanOrEqual = 0, isLessThan = 100, error = "number should be between 0 and 100")
/// assert(1.0000000000012, isEqualTo = 1, tolerance = 0.0001, error = "number should be almost exactly 1")
/// ```
#[stdlib {
name = "assert",
unlabeled_first = true,
args = {
actual = { docs = "Value to check. It will be compared with one of the comparison arguments." },
is_greater_than = { docs = "Comparison argument. If given, checks the `actual` value is greater than this." },
is_less_than = { docs = "Comparison argument. If given, checks the `actual` value is less than this." },
is_greater_than_or_equal = { docs = "Comparison argument. If given, checks the `actual` value is greater than or equal to this." },
is_less_than_or_equal = { docs = "Comparison argument. If given, checks the `actual` value is less than or equal to this." },
is_equal_to = { docs = "Comparison argument. If given, checks the `actual` value is less than or equal to this.", include_in_snippet = true },
tolerance = { docs = "If `isEqualTo` is used, this is the tolerance to allow for the comparison. This tolerance is used because KCL's number system has some floating-point imprecision when used with very large decimal places." },
error = { docs = "If the value was false, the program will terminate with this error message" },
}
}]
#[allow(clippy::too_many_arguments)] #[allow(clippy::too_many_arguments)]
async fn inner_assert( async fn inner_assert(
actual: TyF64, actual: TyF64,

View File

@ -3,7 +3,6 @@
use std::collections::HashMap; use std::collections::HashMap;
use anyhow::Result; use anyhow::Result;
use kcl_derive_docs::stdlib;
use kcmc::{ use kcmc::{
each_cmd as mcmd, each_cmd as mcmd,
length_unit::LengthUnit, length_unit::LengthUnit,
@ -52,113 +51,6 @@ pub async fn extrude(exec_state: &mut ExecState, args: Args) -> Result<KclValue,
Ok(result.into()) Ok(result.into())
} }
/// Extend a 2-dimensional sketch through a third dimension in order to
/// create new 3-dimensional volume, or if extruded into an existing volume,
/// cut into an existing solid.
///
/// You can provide more than one sketch to extrude, and they will all be
/// extruded in the same direction.
///
/// ```no_run
/// example = startSketchOn(XZ)
/// |> startProfile(at = [0, 0])
/// |> line(end = [10, 0])
/// |> arc(
/// angleStart = 120,
/// angleEnd = 0,
/// radius = 5,
/// )
/// |> line(end = [5, 0])
/// |> line(end = [0, 10])
/// |> bezierCurve(
/// control1 = [-10, 0],
/// control2 = [2, 10],
/// end = [-5, 10],
/// )
/// |> line(end = [-5, -2])
/// |> close()
/// |> extrude(length = 10)
/// ```
///
/// ```no_run
/// exampleSketch = startSketchOn(XZ)
/// |> startProfile(at = [-10, 0])
/// |> arc(
/// angleStart = 120,
/// angleEnd = -60,
/// radius = 5,
/// )
/// |> line(end = [10, 0])
/// |> line(end = [5, 0])
/// |> bezierCurve(
/// control1 = [-3, 0],
/// control2 = [2, 10],
/// end = [-5, 10],
/// )
/// |> line(end = [-4, 10])
/// |> line(end = [-5, -2])
/// |> close()
///
/// example = extrude(exampleSketch, length = 10)
/// ```
///
/// ```no_run
/// exampleSketch = startSketchOn(XZ)
/// |> startProfile(at = [-10, 0])
/// |> arc(
/// angleStart = 120,
/// angleEnd = -60,
/// radius = 5,
/// )
/// |> line(end = [10, 0])
/// |> line(end = [5, 0])
/// |> bezierCurve(
/// control1 = [-3, 0],
/// control2 = [2, 10],
/// end = [-5, 10],
/// )
/// |> line(end = [-4, 10])
/// |> line(end = [-5, -2])
/// |> close()
///
/// example = extrude(exampleSketch, length = 20, symmetric = true)
/// ```
///
/// ```no_run
/// exampleSketch = startSketchOn(XZ)
/// |> startProfile(at = [-10, 0])
/// |> arc(
/// angleStart = 120,
/// angleEnd = -60,
/// radius = 5,
/// )
/// |> line(end = [10, 0])
/// |> line(end = [5, 0])
/// |> bezierCurve(
/// control1 = [-3, 0],
/// control2 = [2, 10],
/// end = [-5, 10],
/// )
/// |> line(end = [-4, 10])
/// |> line(end = [-5, -2])
/// |> close()
///
/// example = extrude(exampleSketch, length = 10, bidirectionalLength = 50)
/// ```
#[stdlib {
name = "extrude",
feature_tree_operation = true,
unlabeled_first = true,
args = {
sketches = { docs = "Which sketch or sketches should be extruded"},
length = { docs = "How far to extrude the given sketches"},
symmetric = { docs = "If true, the extrusion will happen symmetrically around the sketch. Otherwise, the extrusion will happen on only one side of the sketch." },
bidirectional_length = { docs = "If specified, will also extrude in the opposite direction to 'distance' to the specified distance. If 'symmetric' is true, this value is ignored."},
tag_start = { docs = "A named tag for the face at the start of the extrusion, i.e. the original sketch" },
tag_end = { docs = "A named tag for the face at the end of the extrusion, i.e. the new face created by extruding the original sketch" },
},
tags = ["sketch"]
}]
#[allow(clippy::too_many_arguments)] #[allow(clippy::too_many_arguments)]
async fn inner_extrude( async fn inner_extrude(
sketches: Vec<Sketch>, sketches: Vec<Sketch>,

View File

@ -3,7 +3,6 @@
use std::num::NonZeroU32; use std::num::NonZeroU32;
use anyhow::Result; use anyhow::Result;
use kcl_derive_docs::stdlib;
use kcmc::{each_cmd as mcmd, length_unit::LengthUnit, ModelingCmd}; use kcmc::{each_cmd as mcmd, length_unit::LengthUnit, ModelingCmd};
use kittycad_modeling_cmds as kcmc; use kittycad_modeling_cmds as kcmc;
@ -55,87 +54,6 @@ pub async fn loft(exec_state: &mut ExecState, args: Args) -> Result<KclValue, Kc
Ok(KclValue::Solid { value }) Ok(KclValue::Solid { value })
} }
/// Create a 3D surface or solid by interpolating between two or more sketches.
///
/// The sketches need to closed and on the same plane.
///
/// ```no_run
/// // Loft a square and a triangle.
/// squareSketch = startSketchOn(XY)
/// |> startProfile(at = [-100, 200])
/// |> line(end = [200, 0])
/// |> line(end = [0, -200])
/// |> line(end = [-200, 0])
/// |> line(endAbsolute = [profileStartX(%), profileStartY(%)])
/// |> close()
///
/// triangleSketch = startSketchOn(offsetPlane(XY, offset = 75))
/// |> startProfile(at = [0, 125])
/// |> line(end = [-15, -30])
/// |> line(end = [30, 0])
/// |> line(endAbsolute = [profileStartX(%), profileStartY(%)])
/// |> close()
///
/// loft([triangleSketch, squareSketch])
/// ```
///
/// ```no_run
/// // Loft a square, a circle, and another circle.
/// squareSketch = startSketchOn(XY)
/// |> startProfile(at = [-100, 200])
/// |> line(end = [200, 0])
/// |> line(end = [0, -200])
/// |> line(end = [-200, 0])
/// |> line(endAbsolute = [profileStartX(%), profileStartY(%)])
/// |> close()
///
/// circleSketch0 = startSketchOn(offsetPlane(XY, offset = 75))
/// |> circle( center = [0, 100], radius = 50 )
///
/// circleSketch1 = startSketchOn(offsetPlane(XY, offset = 150))
/// |> circle( center = [0, 100], radius = 20 )
///
/// loft([squareSketch, circleSketch0, circleSketch1])
/// ```
///
/// ```no_run
/// // Loft a square, a circle, and another circle with options.
/// squareSketch = startSketchOn(XY)
/// |> startProfile(at = [-100, 200])
/// |> line(end = [200, 0])
/// |> line(end = [0, -200])
/// |> line(end = [-200, 0])
/// |> line(endAbsolute = [profileStartX(%), profileStartY(%)])
/// |> close()
///
/// circleSketch0 = startSketchOn(offsetPlane(XY, offset = 75))
/// |> circle( center = [0, 100], radius = 50 )
///
/// circleSketch1 = startSketchOn(offsetPlane(XY, offset = 150))
/// |> circle( center = [0, 100], radius = 20 )
///
/// loft([squareSketch, circleSketch0, circleSketch1],
/// baseCurveIndex = 0,
/// bezApproximateRational = false,
/// tolerance = 0.000001,
/// vDegree = 2,
/// )
/// ```
#[stdlib {
name = "loft",
feature_tree_operation = true,
unlabeled_first = true,
args = {
sketches = {docs = "Which sketches to loft. Must include at least 2 sketches."},
v_degree = {docs = "Degree of the interpolation. Must be greater than zero. For example, use 2 for quadratic, or 3 for cubic interpolation in the V direction. This defaults to 2, if not specified."},
bez_approximate_rational = {docs = "Attempt to approximate rational curves (such as arcs) using a bezier. This will remove banding around interpolations between arcs and non-arcs. It may produce errors in other scenarios Over time, this field won't be necessary."},
base_curve_index = {docs = "This can be set to override the automatically determined topological base curve, which is usually the first section encountered."},
tolerance = {docs = "Tolerance for the loft operation."},
tag_start = { docs = "A named tag for the face at the start of the loft, i.e. the original sketch" },
tag_end = { docs = "A named tag for the face at the end of the loft, i.e. the last sketch" },
},
tags = ["sketch"]
}]
#[allow(clippy::too_many_arguments)] #[allow(clippy::too_many_arguments)]
async fn inner_loft( async fn inner_loft(
sketches: Vec<Sketch>, sketches: Vec<Sketch>,

View File

@ -45,7 +45,6 @@ pub type StdFn = fn(
lazy_static! { lazy_static! {
static ref CORE_FNS: Vec<Box<dyn StdLibFn>> = vec![ static ref CORE_FNS: Vec<Box<dyn StdLibFn>> = vec![
Box::new(crate::std::extrude::Extrude),
Box::new(crate::std::segment::SegEnd), Box::new(crate::std::segment::SegEnd),
Box::new(crate::std::segment::SegEndX), Box::new(crate::std::segment::SegEndX),
Box::new(crate::std::segment::SegEndY), Box::new(crate::std::segment::SegEndY),
@ -57,8 +56,6 @@ lazy_static! {
Box::new(crate::std::segment::SegLen), Box::new(crate::std::segment::SegLen),
Box::new(crate::std::segment::SegAng), Box::new(crate::std::segment::SegAng),
Box::new(crate::std::segment::TangentToEnd), Box::new(crate::std::segment::TangentToEnd),
Box::new(crate::std::shapes::CircleThreePoint),
Box::new(crate::std::shapes::Polygon),
Box::new(crate::std::sketch::InvoluteCircular), Box::new(crate::std::sketch::InvoluteCircular),
Box::new(crate::std::sketch::Line), Box::new(crate::std::sketch::Line),
Box::new(crate::std::sketch::XLine), Box::new(crate::std::sketch::XLine),
@ -75,12 +72,6 @@ lazy_static! {
Box::new(crate::std::sketch::TangentialArc), Box::new(crate::std::sketch::TangentialArc),
Box::new(crate::std::sketch::BezierCurve), Box::new(crate::std::sketch::BezierCurve),
Box::new(crate::std::sketch::Subtract2D), Box::new(crate::std::sketch::Subtract2D),
Box::new(crate::std::patterns::PatternLinear2D),
Box::new(crate::std::patterns::PatternCircular2D),
Box::new(crate::std::sweep::Sweep),
Box::new(crate::std::loft::Loft),
Box::new(crate::std::assert::Assert),
Box::new(crate::std::assert::AssertIs)
]; ];
} }
@ -233,6 +224,14 @@ pub(crate) fn std_fn(path: &str, fn_name: &str) -> (crate::std::StdFn, StdFnProp
|e, a| Box::pin(crate::std::planes::offset_plane(e, a)), |e, a| Box::pin(crate::std::planes::offset_plane(e, a)),
StdFnProps::default("std::offsetPlane").include_in_feature_tree(), StdFnProps::default("std::offsetPlane").include_in_feature_tree(),
), ),
("prelude", "assert") => (
|e, a| Box::pin(crate::std::assert::assert(e, a)),
StdFnProps::default("std::assert"),
),
("prelude", "assertIs") => (
|e, a| Box::pin(crate::std::assert::assert_is(e, a)),
StdFnProps::default("std::assertIs"),
),
("solid", "fillet") => ( ("solid", "fillet") => (
|e, a| Box::pin(crate::std::fillet::fillet(e, a)), |e, a| Box::pin(crate::std::fillet::fillet(e, a)),
StdFnProps::default("std::solid::fillet").include_in_feature_tree(), StdFnProps::default("std::solid::fillet").include_in_feature_tree(),
@ -301,6 +300,10 @@ pub(crate) fn std_fn(path: &str, fn_name: &str) -> (crate::std::StdFn, StdFnProp
|e, a| Box::pin(crate::std::shapes::circle(e, a)), |e, a| Box::pin(crate::std::shapes::circle(e, a)),
StdFnProps::default("std::sketch::circle"), StdFnProps::default("std::sketch::circle"),
), ),
("sketch", "extrude") => (
|e, a| Box::pin(crate::std::extrude::extrude(e, a)),
StdFnProps::default("std::sketch::extrude").include_in_feature_tree(),
),
("sketch", "patternTransform2d") => ( ("sketch", "patternTransform2d") => (
|e, a| Box::pin(crate::std::patterns::pattern_transform_2d(e, a)), |e, a| Box::pin(crate::std::patterns::pattern_transform_2d(e, a)),
StdFnProps::default("std::sketch::patternTransform2d"), StdFnProps::default("std::sketch::patternTransform2d"),
@ -309,6 +312,22 @@ pub(crate) fn std_fn(path: &str, fn_name: &str) -> (crate::std::StdFn, StdFnProp
|e, a| Box::pin(crate::std::revolve::revolve(e, a)), |e, a| Box::pin(crate::std::revolve::revolve(e, a)),
StdFnProps::default("std::sketch::revolve").include_in_feature_tree(), StdFnProps::default("std::sketch::revolve").include_in_feature_tree(),
), ),
("sketch", "sweep") => (
|e, a| Box::pin(crate::std::sweep::sweep(e, a)),
StdFnProps::default("std::sketch::sweep").include_in_feature_tree(),
),
("sketch", "loft") => (
|e, a| Box::pin(crate::std::loft::loft(e, a)),
StdFnProps::default("std::sketch::loft").include_in_feature_tree(),
),
("sketch", "polygon") => (
|e, a| Box::pin(crate::std::shapes::polygon(e, a)),
StdFnProps::default("std::sketch::polygon"),
),
("sketch", "circleThreePoint") => (
|e, a| Box::pin(crate::std::shapes::circle_three_point(e, a)),
StdFnProps::default("std::sketch::circleThreePoint"),
),
("sketch", "getCommonEdge") => ( ("sketch", "getCommonEdge") => (
|e, a| Box::pin(crate::std::edge::get_common_edge(e, a)), |e, a| Box::pin(crate::std::edge::get_common_edge(e, a)),
StdFnProps::default("std::sketch::getCommonEdge"), StdFnProps::default("std::sketch::getCommonEdge"),
@ -325,6 +344,14 @@ pub(crate) fn std_fn(path: &str, fn_name: &str) -> (crate::std::StdFn, StdFnProp
|e, a| Box::pin(crate::std::edge::get_previous_adjacent_edge(e, a)), |e, a| Box::pin(crate::std::edge::get_previous_adjacent_edge(e, a)),
StdFnProps::default("std::sketch::getPreviousAdjacentEdge"), StdFnProps::default("std::sketch::getPreviousAdjacentEdge"),
), ),
("sketch", "patternLinear2d") => (
|e, a| Box::pin(crate::std::patterns::pattern_linear_2d(e, a)),
StdFnProps::default("std::sketch::patternLinear2d"),
),
("sketch", "patternCircular2d") => (
|e, a| Box::pin(crate::std::patterns::pattern_circular_2d(e, a)),
StdFnProps::default("std::sketch::patternCircular2d"),
),
("appearance", "hexString") => ( ("appearance", "hexString") => (
|e, a| Box::pin(crate::std::appearance::hex_string(e, a)), |e, a| Box::pin(crate::std::appearance::hex_string(e, a)),
StdFnProps::default("std::appearance::hexString"), StdFnProps::default("std::appearance::hexString"),

View File

@ -3,7 +3,6 @@
use std::cmp::Ordering; use std::cmp::Ordering;
use anyhow::Result; use anyhow::Result;
use kcl_derive_docs::stdlib;
use kcmc::{ use kcmc::{
each_cmd as mcmd, length_unit::LengthUnit, ok_response::OkModelingCmdResponse, shared::Transform, each_cmd as mcmd, length_unit::LengthUnit, ok_response::OkModelingCmdResponse, shared::Transform,
websocket::OkWebSocketResponseData, ModelingCmd, websocket::OkWebSocketResponseData, ModelingCmd,
@ -546,47 +545,6 @@ pub async fn pattern_linear_2d(exec_state: &mut ExecState, args: Args) -> Result
Ok(sketches.into()) Ok(sketches.into())
} }
/// Repeat a 2-dimensional sketch along some dimension, with a dynamic amount
/// of distance between each repetition, some specified number of times.
///
/// ```no_run
/// /// Pattern using a named axis.
///
/// exampleSketch = startSketchOn(XZ)
/// |> circle(center = [0, 0], radius = 1)
/// |> patternLinear2d(
/// axis = X,
/// instances = 7,
/// distance = 4
/// )
///
/// example = extrude(exampleSketch, length = 1)
/// ```
///
/// ```no_run
/// /// Pattern using a raw axis.
///
/// exampleSketch = startSketchOn(XZ)
/// |> circle(center = [0, 0], radius = 1)
/// |> patternLinear2d(
/// axis = [1, 0],
/// instances = 7,
/// distance = 4
/// )
///
/// example = extrude(exampleSketch, length = 1)
/// ```
#[stdlib {
name = "patternLinear2d",
unlabeled_first = true,
args = {
sketches = { docs = "The sketch(es) to duplicate" },
instances = { docs = "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." },
distance = { docs = "Distance between each repetition. Also known as 'spacing'."},
axis = { docs = "The axis of the pattern. A 2D vector.", snippet_value_array = ["1", "0"] },
use_original = { docs = "If the target was sketched on an extrusion, setting this will use the original sketch as the target, not the entire joined solid. Defaults to false." },
}
}]
async fn inner_pattern_linear_2d( async fn inner_pattern_linear_2d(
sketches: Vec<Sketch>, sketches: Vec<Sketch>,
instances: u32, instances: u32,
@ -810,40 +768,6 @@ pub async fn pattern_circular_2d(exec_state: &mut ExecState, args: Args) -> Resu
Ok(sketches.into()) Ok(sketches.into())
} }
/// Repeat a 2-dimensional sketch some number of times along a partial or
/// complete circle some specified number of times. Each object may
/// additionally be rotated along the circle, ensuring orientation of the
/// solid with respect to the center of the circle is maintained.
///
/// ```no_run
/// exampleSketch = startSketchOn(XZ)
/// |> startProfile(at = [.5, 25])
/// |> line(end = [0, 5])
/// |> line(end = [-1, 0])
/// |> line(end = [0, -5])
/// |> close()
/// |> patternCircular2d(
/// center = [0, 0],
/// instances = 13,
/// arcDegrees = 360,
/// rotateDuplicates = true
/// )
///
/// example = extrude(exampleSketch, length = 1)
/// ```
#[stdlib {
name = "patternCircular2d",
unlabeled_first = true,
args = {
sketch_set = { docs = "Which sketch(es) to pattern" },
instances = { docs = "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."},
center = { docs = "The center about which to make the pattern. This is a 2D vector.", snippet_value_array = ["0", "0"]},
arc_degrees = { docs = "The arc angle (in degrees) to place the repetitions. Must be greater than 0. Defaults to 360."},
rotate_duplicates= { docs = "Whether or not to rotate the duplicates as they are copied. Defaults to true."},
use_original= { docs = "If the target was sketched on an extrusion, setting this will use the original sketch as the target, not the entire joined solid. Defaults to false."},
},
tags = ["sketch"]
}]
#[allow(clippy::too_many_arguments)] #[allow(clippy::too_many_arguments)]
async fn inner_pattern_circular_2d( async fn inner_pattern_circular_2d(
sketch_set: Vec<Sketch>, sketch_set: Vec<Sketch>,

View File

@ -1,7 +1,6 @@
//! Standard library shapes. //! Standard library shapes.
use anyhow::Result; use anyhow::Result;
use kcl_derive_docs::stdlib;
use kcmc::{ use kcmc::{
each_cmd as mcmd, each_cmd as mcmd,
length_unit::LengthUnit, length_unit::LengthUnit,
@ -143,26 +142,6 @@ pub async fn circle_three_point(exec_state: &mut ExecState, args: Args) -> Resul
}) })
} }
/// Construct a circle derived from 3 points.
///
/// ```no_run
/// exampleSketch = startSketchOn(XY)
/// |> circleThreePoint(p1 = [10,10], p2 = [20,8], p3 = [15,5])
/// |> extrude(length = 5)
/// ```
#[stdlib {
name = "circleThreePoint",
unlabeled_first = true,
args = {
sketch_surface_or_group = {docs = "Plane or surface to sketch on."},
p1 = {docs = "1st point to derive the circle."},
p2 = {docs = "2nd point to derive the circle."},
p3 = {docs = "3rd point to derive the circle."},
tag = {docs = "Identifier for the circle to reference elsewhere."},
},
tags = ["sketch"]
}]
// Similar to inner_circle, but needs to retain 3-point information in the // Similar to inner_circle, but needs to retain 3-point information in the
// path so it can be used for other features, otherwise it's lost. // path so it can be used for other features, otherwise it's lost.
async fn inner_circle_three_point( async fn inner_circle_three_point(
@ -281,44 +260,6 @@ pub async fn polygon(exec_state: &mut ExecState, args: Args) -> Result<KclValue,
}) })
} }
/// Create a regular polygon with the specified number of sides that is either inscribed or circumscribed around a circle of the specified radius.
///
/// ```no_run
/// // Create a regular hexagon inscribed in a circle of radius 10
/// hex = startSketchOn(XY)
/// |> polygon(
/// radius = 10,
/// numSides = 6,
/// center = [0, 0],
/// inscribed = true,
/// )
///
/// example = extrude(hex, length = 5)
/// ```
///
/// ```no_run
/// // Create a square circumscribed around a circle of radius 5
/// square = startSketchOn(XY)
/// |> polygon(
/// radius = 5.0,
/// numSides = 4,
/// center = [10, 10],
/// inscribed = false,
/// )
/// example = extrude(square, length = 5)
/// ```
#[stdlib {
name = "polygon",
unlabeled_first = true,
args = {
sketch_surface_or_group = { docs = "Plane or surface to sketch on" },
radius = { docs = "The radius of the polygon", include_in_snippet = true },
num_sides = { docs = "The number of sides in the polygon", include_in_snippet = true },
center = { docs = "The center point of the polygon", snippet_value_array = ["0", "0"] },
inscribed = { docs = "Whether the polygon is inscribed (true, the default) or circumscribed (false) about a circle with the specified radius" },
},
tags = ["sketch"]
}]
#[allow(clippy::too_many_arguments)] #[allow(clippy::too_many_arguments)]
async fn inner_polygon( async fn inner_polygon(
sketch_surface_or_group: SketchOrSurface, sketch_surface_or_group: SketchOrSurface,

View File

@ -1,7 +1,6 @@
//! Standard library sweep. //! Standard library sweep.
use anyhow::Result; use anyhow::Result;
use kcl_derive_docs::stdlib;
use kcmc::{each_cmd as mcmd, length_unit::LengthUnit, ModelingCmd}; use kcmc::{each_cmd as mcmd, length_unit::LengthUnit, ModelingCmd};
use kittycad_modeling_cmds::{self as kcmc, shared::RelativeTo}; use kittycad_modeling_cmds::{self as kcmc, shared::RelativeTo};
use schemars::JsonSchema; use schemars::JsonSchema;
@ -56,122 +55,6 @@ pub async fn sweep(exec_state: &mut ExecState, args: Args) -> Result<KclValue, K
Ok(value.into()) Ok(value.into())
} }
/// Extrude a sketch along a path.
///
/// This, like extrude, is able to create a 3-dimensional solid from a
/// 2-dimensional sketch. However, unlike extrude, this creates a solid
/// by using the extent of the sketch as its path. This is useful for
/// creating more complex shapes that can't be created with a simple
/// extrusion.
///
/// You can provide more than one sketch to sweep, and they will all be
/// swept along the same path.
///
/// ```no_run
/// // Create a pipe using a sweep.
///
/// // Create a path for the sweep.
/// sweepPath = startSketchOn(XZ)
/// |> startProfile(at = [0.05, 0.05])
/// |> line(end = [0, 7])
/// |> tangentialArc(angle = 90, radius = 5)
/// |> line(end = [-3, 0])
/// |> tangentialArc(angle = -90, radius = 5)
/// |> line(end = [0, 7])
///
/// // Create a hole for the pipe.
/// pipeHole = startSketchOn(XY)
/// |> circle(
/// center = [0, 0],
/// radius = 1.5,
/// )
///
/// sweepSketch = startSketchOn(XY)
/// |> circle(
/// center = [0, 0],
/// radius = 2,
/// )
/// |> subtract2d(tool = pipeHole)
/// |> sweep(path = sweepPath)
/// ```
///
/// ```no_run
/// // Create a spring by sweeping around a helix path.
///
/// // Create a helix around the Z axis.
/// helixPath = helix(
/// angleStart = 0,
/// ccw = true,
/// revolutions = 4,
/// length = 10,
/// radius = 5,
/// axis = Z,
/// )
///
///
/// // Create a spring by sweeping around the helix path.
/// springSketch = startSketchOn(XZ)
/// |> circle( center = [5, 0], radius = 1)
/// |> sweep(path = helixPath)
/// ```
///
/// ```no_run
/// // Sweep two sketches along the same path.
///
/// sketch001 = startSketchOn(XY)
/// rectangleSketch = startProfile(sketch001, at = [-200, 23.86])
/// |> angledLine(angle = 0, length = 73.47, tag = $rectangleSegmentA001)
/// |> angledLine(
/// angle = segAng(rectangleSegmentA001) - 90,
/// length = 50.61,
/// )
/// |> angledLine(
/// angle = segAng(rectangleSegmentA001),
/// length = -segLen(rectangleSegmentA001),
/// )
/// |> line(endAbsolute = [profileStartX(%), profileStartY(%)])
/// |> close()
///
/// circleSketch = circle(sketch001, center = [200, -30.29], radius = 32.63)
///
/// sketch002 = startSketchOn(YZ)
/// sweepPath = startProfile(sketch002, at = [0, 0])
/// |> yLine(length = 231.81)
/// |> tangentialArc(radius = 80, angle = -90)
/// |> xLine(length = 384.93)
///
/// sweep([rectangleSketch, circleSketch], path = sweepPath)
/// ```
/// ```
/// // Sectionally sweep one sketch along the path
///
/// sketch001 = startSketchOn(XY)
/// circleSketch = circle(sketch001, center = [200, -30.29], radius = 32.63)
///
/// sketch002 = startSketchOn(YZ)
/// sweepPath = startProfile(sketch002, at = [0, 0])
/// |> yLine(length = 231.81)
/// |> tangentialArc(radius = 80, angle = -90)
/// |> xLine(length = 384.93)
///
/// sweep(circleSketch, path = sweepPath, sectional = true)
/// ```
#[stdlib {
name = "sweep",
feature_tree_operation = true,
unlabeled_first = true,
args = {
sketches = { docs = "The sketch or set of sketches that should be swept in space" },
path = { docs = "The path to sweep the sketch along" },
sectional = { docs = "If true, the sweep will be broken up into sub-sweeps (extrusions, revolves, sweeps) based on the trajectory path components." },
tolerance = { docs = "Tolerance for this operation" },
relative_to = { docs = "What is the sweep relative to? Can be either 'sketchPlane' or 'trajectoryCurve'. Defaults to trajectoryCurve."},
tag_start = { docs = "A named tag for the face at the start of the sweep, i.e. the original sketch" },
tag_end = { docs = "A named tag for the face at the end of the sweep" },
},
tags = ["sketch"]
}]
#[allow(clippy::too_many_arguments)] #[allow(clippy::too_many_arguments)]
async fn inner_sweep( async fn inner_sweep(
sketches: Vec<Sketch>, sketches: Vec<Sketch>,

View File

@ -484,3 +484,47 @@ export fn clone(
/// The sketch, solid, or imported geometry to be cloned. /// The sketch, solid, or imported geometry to be cloned.
@geometry: Sketch | Solid | ImportedGeometry, @geometry: Sketch | Solid | ImportedGeometry,
): Sketch | Solid | ImportedGeometry {} ): Sketch | Solid | ImportedGeometry {}
/// Asserts that a value is the boolean value true.
///
/// ```kcl,norun
/// kclIsFun = true
/// assertIs(kclIsFun)
/// ```
@(impl = std_rust)
export fn assertIs(
/// Value to check. If this is the boolean value true, assert passes. Otherwise it fails..
@actual: bool,
/// If the value was false, the program will terminate with this error message
error?: string,
) {}
/// Check a value meets some expected conditions at runtime. Program terminates with an error if conditions aren't met.
/// If you provide multiple conditions, they will all be checked and all must be met.
///
/// ```kcl,norun
/// n = 10
/// assert(n, isEqualTo = 10)
/// assert(n, isGreaterThanOrEqual = 0, isLessThan = 100, error = "number should be between 0 and 100")
/// assert(1.0000000000012, isEqualTo = 1, tolerance = 0.0001, error = "number should be almost exactly 1")
/// ```
@(impl = std_rust)
export fn assert(
/// Value to check. If this is the boolean value true, assert passes. Otherwise it fails..
@actual: number,
/// Comparison argument. If given, checks the `actual` value is greater than this.
isGreaterThan?: number,
/// Comparison argument. If given, checks the `actual` value is less than this.
isLessThan?: number,
/// Comparison argument. If given, checks the `actual` value is greater than or equal to this.
isGreaterThanOrEqual?: number,
/// Comparison argument. If given, checks the `actual` value is less than or equal to this.
isLessThanOrEqual?: number,
/// Comparison argument. If given, checks the `actual` value is less than or equal to this.
@(includeInSnippet = true)
isEqualTo?: number,
/// If `isEqualTo` is used, this is the tolerance to allow for the comparison. This tolerance is used because KCL's number system has some floating-point imprecision when used with very large decimal places.
tolerance?: number,
/// If the value was false, the program will terminate with this error message
error?: string,
) {}

View File

@ -31,7 +31,7 @@
@(impl = std_rust) @(impl = std_rust)
export fn circle( export fn circle(
/// Sketch to extend, or plane or surface to sketch on. /// Sketch to extend, or plane or surface to sketch on.
@sketch_or_surface: Sketch | Plane | Face, @sketchOrSurface: Sketch | Plane | Face,
/// The center of the circle. /// The center of the circle.
@(snippetArray = ["0", "0"]) @(snippetArray = ["0", "0"])
center: Point2d, center: Point2d,
@ -44,6 +44,115 @@ export fn circle(
tag?: tag, tag?: tag,
): Sketch {} ): Sketch {}
/// Extend a 2-dimensional sketch through a third dimension in order to
/// create new 3-dimensional volume, or if extruded into an existing volume,
/// cut into an existing solid.
///
/// You can provide more than one sketch to extrude, and they will all be
/// extruded in the same direction.
///
/// ```kcl
/// example = startSketchOn(XZ)
/// |> startProfile(at = [0, 0])
/// |> line(end = [10, 0])
/// |> arc(
/// angleStart = 120,
/// angleEnd = 0,
/// radius = 5,
/// )
/// |> line(end = [5, 0])
/// |> line(end = [0, 10])
/// |> bezierCurve(
/// control1 = [-10, 0],
/// control2 = [2, 10],
/// end = [-5, 10],
/// )
/// |> line(end = [-5, -2])
/// |> close()
/// |> extrude(length = 10)
/// ```
///
/// ```kcl
/// exampleSketch = startSketchOn(XZ)
/// |> startProfile(at = [-10, 0])
/// |> arc(
/// angleStart = 120,
/// angleEnd = -60,
/// radius = 5,
/// )
/// |> line(end = [10, 0])
/// |> line(end = [5, 0])
/// |> bezierCurve(
/// control1 = [-3, 0],
/// control2 = [2, 10],
/// end = [-5, 10],
/// )
/// |> line(end = [-4, 10])
/// |> line(end = [-5, -2])
/// |> close()
///
/// example = extrude(exampleSketch, length = 10)
/// ```
///
/// ```kcl
/// exampleSketch = startSketchOn(XZ)
/// |> startProfile(at = [-10, 0])
/// |> arc(
/// angleStart = 120,
/// angleEnd = -60,
/// radius = 5,
/// )
/// |> line(end = [10, 0])
/// |> line(end = [5, 0])
/// |> bezierCurve(
/// control1 = [-3, 0],
/// control2 = [2, 10],
/// end = [-5, 10],
/// )
/// |> line(end = [-4, 10])
/// |> line(end = [-5, -2])
/// |> close()
///
/// example = extrude(exampleSketch, length = 20, symmetric = true)
/// ```
///
/// ```kcl
/// exampleSketch = startSketchOn(XZ)
/// |> startProfile(at = [-10, 0])
/// |> arc(
/// angleStart = 120,
/// angleEnd = -60,
/// radius = 5,
/// )
/// |> line(end = [10, 0])
/// |> line(end = [5, 0])
/// |> bezierCurve(
/// control1 = [-3, 0],
/// control2 = [2, 10],
/// end = [-5, 10],
/// )
/// |> line(end = [-4, 10])
/// |> line(end = [-5, -2])
/// |> close()
///
/// example = extrude(exampleSketch, length = 10, bidirectionalLength = 50)
/// ```
@(impl = std_rust)
export fn extrude(
/// Which sketch or sketches should be extruded.
@sketches: [Sketch; 1+],
/// How far to extrude the given sketches.
length: number(Length),
/// If true, the extrusion will happen symmetrically around the sketch. Otherwise, the extrusion will happen on only one side of the sketch.
symmetric?: bool,
/// If specified, will also extrude in the opposite direction to 'distance' to the specified distance. If 'symmetric' is true, this value is ignored.
bidirectionalLength?: number(Length),
/// A named tag for the face at the start of the extrusion, i.e. the original sketch.
tagStart?: tag,
/// A named tag for the face at the end of the extrusion, i.e. the new face created by extruding the original sketch.
tagEnd?: tag,
): [Solid; 1+] {}
/// Rotate a sketch around some provided axis, creating a solid from its extent. /// Rotate a sketch around some provided axis, creating a solid from its extent.
/// ///
/// This, like extrude, is able to create a 3-dimensional solid from a /// This, like extrude, is able to create a 3-dimensional solid from a
@ -57,7 +166,7 @@ export fn circle(
/// You can provide more than one sketch to revolve, and they will all be /// You can provide more than one sketch to revolve, and they will all be
/// revolved around the same axis. /// revolved around the same axis.
/// ///
/// ``` /// ```kcl
/// part001 = startSketchOn(XY) /// part001 = startSketchOn(XY)
/// |> startProfile(at = [4, 12]) /// |> startProfile(at = [4, 12])
/// |> line(end = [2, 0]) /// |> line(end = [2, 0])
@ -71,7 +180,7 @@ export fn circle(
/// |> revolve(axis = Y) // default angle is 360 /// |> revolve(axis = Y) // default angle is 360
/// ``` /// ```
/// ///
/// ``` /// ```kcl
/// // A donut shape. /// // A donut shape.
/// sketch001 = startSketchOn(XY) /// sketch001 = startSketchOn(XY)
/// |> circle( center = [15, 0], radius = 5 ) /// |> circle( center = [15, 0], radius = 5 )
@ -81,7 +190,7 @@ export fn circle(
/// ) /// )
/// ``` /// ```
/// ///
/// ``` /// ```kcl
/// part001 = startSketchOn(XY) /// part001 = startSketchOn(XY)
/// |> startProfile(at = [4, 12]) /// |> startProfile(at = [4, 12])
/// |> line(end = [2, 0]) /// |> line(end = [2, 0])
@ -95,7 +204,7 @@ export fn circle(
/// |> revolve(axis = Y, angle = 180) /// |> revolve(axis = Y, angle = 180)
/// ``` /// ```
/// ///
/// ``` /// ```kcl
/// part001 = startSketchOn(XY) /// part001 = startSketchOn(XY)
/// |> startProfile(at = [4, 12]) /// |> startProfile(at = [4, 12])
/// |> line(end = [2, 0]) /// |> line(end = [2, 0])
@ -117,7 +226,7 @@ export fn circle(
/// |> extrude(length = 5) /// |> extrude(length = 5)
/// ``` /// ```
/// ///
/// ``` /// ```kcl
/// box = startSketchOn(XY) /// box = startSketchOn(XY)
/// |> startProfile(at = [0, 0]) /// |> startProfile(at = [0, 0])
/// |> line(end = [0, 20]) /// |> line(end = [0, 20])
@ -134,7 +243,7 @@ export fn circle(
/// ) /// )
/// ``` /// ```
/// ///
/// ``` /// ```kcl
/// box = startSketchOn(XY) /// box = startSketchOn(XY)
/// |> startProfile(at = [0, 0]) /// |> startProfile(at = [0, 0])
/// |> line(end = [0, 20]) /// |> line(end = [0, 20])
@ -151,7 +260,7 @@ export fn circle(
/// ) /// )
/// ``` /// ```
/// ///
/// ``` /// ```kcl
/// box = startSketchOn(XY) /// box = startSketchOn(XY)
/// |> startProfile(at = [0, 0]) /// |> startProfile(at = [0, 0])
/// |> line(end = [0, 20]) /// |> line(end = [0, 20])
@ -169,7 +278,7 @@ export fn circle(
/// ) /// )
/// ``` /// ```
/// ///
/// ``` /// ```kcl
/// sketch001 = startSketchOn(XY) /// sketch001 = startSketchOn(XY)
/// |> startProfile(at = [10, 0]) /// |> startProfile(at = [10, 0])
/// |> line(end = [5, -5]) /// |> line(end = [5, -5])
@ -186,7 +295,7 @@ export fn circle(
/// ) /// )
/// ``` /// ```
/// ///
/// ``` /// ```kcl
/// // Revolve two sketches around the same axis. /// // Revolve two sketches around the same axis.
/// ///
/// sketch001 = startSketchOn(XY) /// sketch001 = startSketchOn(XY)
@ -210,7 +319,7 @@ export fn circle(
/// ) /// )
/// ``` /// ```
/// ///
/// ``` /// ```kcl
/// // Revolve around a path that has not been extruded. /// // Revolve around a path that has not been extruded.
/// ///
/// profile001 = startSketchOn(XY) /// profile001 = startSketchOn(XY)
@ -225,7 +334,7 @@ export fn circle(
/// |> revolve(angle = 90, axis = revolveAxis) /// |> revolve(angle = 90, axis = revolveAxis)
/// ``` /// ```
/// ///
/// ``` /// ```kcl
/// // Revolve around a path that has not been extruded or closed. /// // Revolve around a path that has not been extruded or closed.
/// ///
/// profile001 = startSketchOn(XY) /// profile001 = startSketchOn(XY)
@ -238,7 +347,7 @@ export fn circle(
/// |> revolve(angle = 90, axis = revolveAxis) /// |> revolve(angle = 90, axis = revolveAxis)
/// ``` /// ```
/// ///
/// ``` /// ```kcl
/// // Symmetrically revolve around a path. /// // Symmetrically revolve around a path.
/// ///
/// profile001 = startSketchOn(XY) /// profile001 = startSketchOn(XY)
@ -251,7 +360,7 @@ export fn circle(
/// |> revolve(angle = 90, axis = revolveAxis, symmetric = true) /// |> revolve(angle = 90, axis = revolveAxis, symmetric = true)
/// ``` /// ```
/// ///
/// ``` /// ```kcl
/// // Bidirectional revolve around a path. /// // Bidirectional revolve around a path.
/// ///
/// profile001 = startSketchOn(XY) /// profile001 = startSketchOn(XY)
@ -438,3 +547,351 @@ export fn getCommonEdge(
/// The tags of the faces you want to find the common edge between. /// The tags of the faces you want to find the common edge between.
faces: [tag; 2], faces: [tag; 2],
): Edge {} ): Edge {}
/// Construct a circle derived from 3 points.
///
/// ```kcl
/// exampleSketch = startSketchOn(XY)
/// |> circleThreePoint(p1 = [10,10], p2 = [20,8], p3 = [15,5])
/// |> extrude(length = 5)
/// ```
@(impl = std_rust)
export fn circleThreePoint(
/// Plane or surface to sketch on.
@sketchOrSurface: Sketch | Plane | Face,
/// 1st point to derive the circle.
p1: Point2d,
/// 2nd point to derive the circle.
p2: Point2d,
/// 3rd point to derive the circle.
p3: Point2d,
/// Identifier for the circle to reference elsewhere.
tag?: tag,
): Sketch {}
/// Create a regular polygon with the specified number of sides that is either inscribed or circumscribed around a circle of the specified radius.
///
/// ```kcl
/// // Create a regular hexagon inscribed in a circle of radius 10
/// hex = startSketchOn(XY)
/// |> polygon(
/// radius = 10,
/// numSides = 6,
/// center = [0, 0],
/// inscribed = true,
/// )
///
/// example = extrude(hex, length = 5)
/// ```
///
/// ```kcl
/// // Create a square circumscribed around a circle of radius 5
/// square = startSketchOn(XY)
/// |> polygon(
/// radius = 5.0,
/// numSides = 4,
/// center = [10, 10],
/// inscribed = false,
/// )
/// example = extrude(square, length = 5)
/// ```
@(impl = std_rust)
export fn polygon(
/// Plane or surface to sketch on.
@sketchOrSurface: Sketch | Plane | Face,
/// The radius of the polygon.
radius: number(Length),
/// The number of sides in the polygon.
numSides: number(Count),
/// The center point of the polygon.
@(snippetArray = ["0", "0"])
center: Point2d,
/// Whether the polygon is inscribed (true, the default) or circumscribed (false) about a circle with the specified radius.
inscribed?: bool = true,
): Sketch {}
/// Extrude a sketch along a path.
///
/// This, like extrude, is able to create a 3-dimensional solid from a
/// 2-dimensional sketch. However, unlike extrude, this creates a solid
/// by using the extent of the sketch as its path. This is useful for
/// creating more complex shapes that can't be created with a simple
/// extrusion.
///
/// You can provide more than one sketch to sweep, and they will all be
/// swept along the same path.
///
/// ```kcl
/// // Create a pipe using a sweep.
///
/// // Create a path for the sweep.
/// sweepPath = startSketchOn(XZ)
/// |> startProfile(at = [0.05, 0.05])
/// |> line(end = [0, 7])
/// |> tangentialArc(angle = 90, radius = 5)
/// |> line(end = [-3, 0])
/// |> tangentialArc(angle = -90, radius = 5)
/// |> line(end = [0, 7])
///
/// // Create a hole for the pipe.
/// pipeHole = startSketchOn(XY)
/// |> circle(
/// center = [0, 0],
/// radius = 1.5,
/// )
///
/// sweepSketch = startSketchOn(XY)
/// |> circle(
/// center = [0, 0],
/// radius = 2,
/// )
/// |> subtract2d(tool = pipeHole)
/// |> sweep(path = sweepPath)
/// ```
///
/// ```kcl
/// // Create a spring by sweeping around a helix path.
///
/// // Create a helix around the Z axis.
/// helixPath = helix(
/// angleStart = 0,
/// ccw = true,
/// revolutions = 4,
/// length = 10,
/// radius = 5,
/// axis = Z,
/// )
///
///
/// // Create a spring by sweeping around the helix path.
/// springSketch = startSketchOn(XZ)
/// |> circle( center = [5, 0], radius = 1)
/// |> sweep(path = helixPath)
/// ```
///
/// ```kcl
/// // Sweep two sketches along the same path.
///
/// sketch001 = startSketchOn(XY)
/// rectangleSketch = startProfile(sketch001, at = [-200, 23.86])
/// |> angledLine(angle = 0, length = 73.47, tag = $rectangleSegmentA001)
/// |> angledLine(
/// angle = segAng(rectangleSegmentA001) - 90,
/// length = 50.61,
/// )
/// |> angledLine(
/// angle = segAng(rectangleSegmentA001),
/// length = -segLen(rectangleSegmentA001),
/// )
/// |> line(endAbsolute = [profileStartX(%), profileStartY(%)])
/// |> close()
///
/// circleSketch = circle(sketch001, center = [200, -30.29], radius = 32.63)
///
/// sketch002 = startSketchOn(YZ)
/// sweepPath = startProfile(sketch002, at = [0, 0])
/// |> yLine(length = 231.81)
/// |> tangentialArc(radius = 80, angle = -90)
/// |> xLine(length = 384.93)
///
/// sweep([rectangleSketch, circleSketch], path = sweepPath)
/// ```
///
/// ```kcl
/// // Sectionally sweep one sketch along the path
///
/// sketch001 = startSketchOn(XY)
/// circleSketch = circle(sketch001, center = [200, -30.29], radius = 32.63)
///
/// sketch002 = startSketchOn(YZ)
/// sweepPath = startProfile(sketch002, at = [0, 0])
/// |> yLine(length = 231.81)
/// |> tangentialArc(radius = 80, angle = -90)
/// |> xLine(length = 384.93)
///
/// sweep(circleSketch, path = sweepPath, sectional = true)
/// ```
@(impl = std_rust)
export fn sweep(
/// The sketch or set of sketches that should be swept in space.
@sketches: [Sketch; 1+],
/// The path to sweep the sketch along.
path: Sketch | Helix,
/// If true, the sweep will be broken up into sub-sweeps (extrusions, revolves, sweeps) based on the trajectory path components.
sectional?: bool,
/// Tolerance for this operation.
tolerance?: number(Length),
/// What is the sweep relative to? Can be either 'sketchPlane' or 'trajectoryCurve'.
relativeTo?: string = 'trajectoryCurve',
/// A named tag for the face at the start of the sweep, i.e. the original sketch.
tagStart?: tag,
/// A named tag for the face at the end of the sweep.
tagEnd?: tag,
): [Solid; 1+] {}
/// Create a 3D surface or solid by interpolating between two or more sketches.
///
/// The sketches need to closed and on the same plane.
///
/// ```kcl
/// // Loft a square and a triangle.
/// squareSketch = startSketchOn(XY)
/// |> startProfile(at = [-100, 200])
/// |> line(end = [200, 0])
/// |> line(end = [0, -200])
/// |> line(end = [-200, 0])
/// |> line(endAbsolute = [profileStartX(%), profileStartY(%)])
/// |> close()
///
/// triangleSketch = startSketchOn(offsetPlane(XY, offset = 75))
/// |> startProfile(at = [0, 125])
/// |> line(end = [-15, -30])
/// |> line(end = [30, 0])
/// |> line(endAbsolute = [profileStartX(%), profileStartY(%)])
/// |> close()
///
/// loft([triangleSketch, squareSketch])
/// ```
///
/// ```kcl
/// // Loft a square, a circle, and another circle.
/// squareSketch = startSketchOn(XY)
/// |> startProfile(at = [-100, 200])
/// |> line(end = [200, 0])
/// |> line(end = [0, -200])
/// |> line(end = [-200, 0])
/// |> line(endAbsolute = [profileStartX(%), profileStartY(%)])
/// |> close()
///
/// circleSketch0 = startSketchOn(offsetPlane(XY, offset = 75))
/// |> circle( center = [0, 100], radius = 50 )
///
/// circleSketch1 = startSketchOn(offsetPlane(XY, offset = 150))
/// |> circle( center = [0, 100], radius = 20 )
///
/// loft([squareSketch, circleSketch0, circleSketch1])
/// ```
///
/// ```kcl
/// // Loft a square, a circle, and another circle with options.
/// squareSketch = startSketchOn(XY)
/// |> startProfile(at = [-100, 200])
/// |> line(end = [200, 0])
/// |> line(end = [0, -200])
/// |> line(end = [-200, 0])
/// |> line(endAbsolute = [profileStartX(%), profileStartY(%)])
/// |> close()
///
/// circleSketch0 = startSketchOn(offsetPlane(XY, offset = 75))
/// |> circle( center = [0, 100], radius = 50 )
///
/// circleSketch1 = startSketchOn(offsetPlane(XY, offset = 150))
/// |> circle( center = [0, 100], radius = 20 )
///
/// loft([squareSketch, circleSketch0, circleSketch1],
/// baseCurveIndex = 0,
/// bezApproximateRational = false,
/// tolerance = 0.000001,
/// vDegree = 2,
/// )
/// ```
@(impl = std_rust)
export fn loft(
/// Which sketches to loft. Must include at least 2 sketches.
@sketches: [Sketch; 2+],
/// Degree of the interpolation. Must be greater than zero. For example, use 2 for quadratic, or 3 for cubic interpolation in the V direction.
vDegree?: number(Count) = 2,
/// Attempt to approximate rational curves (such as arcs) using a bezier. This will remove banding around interpolations between arcs and non-arcs. It may produce errors in other scenarios. Over time, this field won't be necessary.
bezApproximateRational?: bool = false,
/// This can be set to override the automatically determined topological base curve, which is usually the first section encountered.
baseCurveIndex?: number(Count),
/// Tolerance for the loft operation.
tolerance?: number(Length),
/// A named tag for the face at the start of the loft, i.e. the original sketch.
tagStart?: tag,
/// A named tag for the face at the end of the loft.
tagEnd?: tag,
): Solid {}
/// Repeat a 2-dimensional sketch along some dimension, with a dynamic amount
/// of distance between each repetition, some specified number of times.
///
/// ```kcl
/// /// Pattern using a named axis.
///
/// exampleSketch = startSketchOn(XZ)
/// |> circle(center = [0, 0], radius = 1)
/// |> patternLinear2d(
/// axis = X,
/// instances = 7,
/// distance = 4
/// )
///
/// example = extrude(exampleSketch, length = 1)
/// ```
///
/// ```kcl
/// /// Pattern using a raw axis.
///
/// exampleSketch = startSketchOn(XZ)
/// |> circle(center = [0, 0], radius = 1)
/// |> patternLinear2d(
/// axis = [1, 0],
/// instances = 7,
/// distance = 4
/// )
///
/// example = extrude(exampleSketch, length = 1)
/// ```
@(impl = std_rust)
export fn patternLinear2d(
/// The sketch(es) to duplicate.
@sketches: [Sketch; 1+],
/// 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.
instances: number(Count),
/// Distance between each repetition. Also known as 'spacing'.
distance: number(Length),
/// The axis of the pattern. A 2D vector.
@(snippetArray = ["1", "0"])
axis: Axis2d | Point2d,
/// If the target was sketched on an extrusion, setting this will use the original sketch as the target, not the entire joined solid.
useOriginal?: bool = false,
): [Sketch; 1+] {}
/// Repeat a 2-dimensional sketch some number of times along a partial or
/// complete circle some specified number of times. Each object may
/// additionally be rotated along the circle, ensuring orientation of the
/// solid with respect to the center of the circle is maintained.
///
/// ```kcl
/// exampleSketch = startSketchOn(XZ)
/// |> startProfile(at = [.5, 25])
/// |> line(end = [0, 5])
/// |> line(end = [-1, 0])
/// |> line(end = [0, -5])
/// |> close()
/// |> patternCircular2d(
/// center = [0, 0],
/// instances = 13,
/// arcDegrees = 360,
/// rotateDuplicates = true
/// )
///
/// example = extrude(exampleSketch, length = 1)
/// ```
@(impl = std_rust)
export fn patternCircular2d(
/// The sketch(es) to duplicate.
@sketches: [Sketch; 1+],
/// 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.
instances: number(Count),
/// The center about which to make the pattern. This is a 2D vector.
@(snippetArray = ["0", "0"])
center: Point2d,
/// The arc angle (in degrees) to place the repetitions. Must be greater than 0.
arcDegrees?: number(Angle) = 360deg,
/// Whether or not to rotate the duplicates as they are copied.
rotateDuplicates?: bool = true,
/// If the target was sketched on an extrusion, setting this will use the original sketch as the target, not the entire joined solid.
useOriginal?: bool = false,
): [Sketch; 1+] {}

View File

@ -8,6 +8,17 @@ KCL Engine error
│ path! │ path!
╭─[7:6] ╭─[7:6]
6 │ |> line(end = [-11.53311, 2.81559]) 6 │ |> line(end = [-11.53311, 2.81559])
7 │ |> extrude(length = 4)
· ─────────┬─────────┬
· ╰── tests/execute_engine_error_return/input.kcl
· ╰── tests/execute_engine_error_return/input.kcl
╰────
╰─▶ KCL Engine error
× engine: The path is not closed. Solid2D construction requires a
│ closed path!
╭─[7:6]
6 │ |> line(end = [-11.53311, 2.81559])
7 │ |> extrude(length = 4) 7 │ |> extrude(length = 4)
· ─────────┬───────── · ─────────┬─────────
· ╰── tests/execute_engine_error_return/input.kcl · ╰── tests/execute_engine_error_return/input.kcl

View File

@ -485,13 +485,8 @@ description: Operations executed herringbone-gear.kcl
"type": "Number", "type": "Number",
"value": 1.0, "value": 1.0,
"ty": { "ty": {
"type": "Default", "type": "Known",
"len": { "type": "Count"
"type": "Mm"
},
"angle": {
"type": "Degrees"
}
} }
}, },
"sourceRange": [] "sourceRange": []

View File

@ -932,13 +932,8 @@ description: Operations executed herringbone-planetary-gearset.kcl
"type": "Number", "type": "Number",
"value": 1.0, "value": 1.0,
"ty": { "ty": {
"type": "Default", "type": "Known",
"len": { "type": "Count"
"type": "Mm"
},
"angle": {
"type": "Degrees"
}
} }
}, },
"sourceRange": [] "sourceRange": []
@ -981,13 +976,8 @@ description: Operations executed herringbone-planetary-gearset.kcl
"type": "Number", "type": "Number",
"value": 1.0, "value": 1.0,
"ty": { "ty": {
"type": "Default", "type": "Known",
"len": { "type": "Count"
"type": "Mm"
},
"angle": {
"type": "Degrees"
}
} }
}, },
"sourceRange": [] "sourceRange": []
@ -1563,13 +1553,8 @@ description: Operations executed herringbone-planetary-gearset.kcl
"type": "Number", "type": "Number",
"value": 1.0, "value": 1.0,
"ty": { "ty": {
"type": "Default", "type": "Known",
"len": { "type": "Count"
"type": "Mm"
},
"angle": {
"type": "Degrees"
}
} }
}, },
"sourceRange": [] "sourceRange": []

Binary file not shown.

Before

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 19 KiB

View File

Before

Width:  |  Height:  |  Size: 59 KiB

After

Width:  |  Height:  |  Size: 59 KiB

View File

Before

Width:  |  Height:  |  Size: 62 KiB

After

Width:  |  Height:  |  Size: 62 KiB

View File

Before

Width:  |  Height:  |  Size: 69 KiB

After

Width:  |  Height:  |  Size: 69 KiB

View File

Before

Width:  |  Height:  |  Size: 64 KiB

After

Width:  |  Height:  |  Size: 64 KiB

View File

Before

Width:  |  Height:  |  Size: 78 KiB

After

Width:  |  Height:  |  Size: 78 KiB

View File

Before

Width:  |  Height:  |  Size: 132 KiB

After

Width:  |  Height:  |  Size: 132 KiB

View File

Before

Width:  |  Height:  |  Size: 132 KiB

After

Width:  |  Height:  |  Size: 132 KiB

View File

Before

Width:  |  Height:  |  Size: 48 KiB

After

Width:  |  Height:  |  Size: 48 KiB

View File

Before

Width:  |  Height:  |  Size: 53 KiB

After

Width:  |  Height:  |  Size: 53 KiB

View File

Before

Width:  |  Height:  |  Size: 73 KiB

After

Width:  |  Height:  |  Size: 73 KiB

View File

Before

Width:  |  Height:  |  Size: 185 KiB

After

Width:  |  Height:  |  Size: 185 KiB

View File

Before

Width:  |  Height:  |  Size: 88 KiB

After

Width:  |  Height:  |  Size: 88 KiB

View File

Before

Width:  |  Height:  |  Size: 58 KiB

After

Width:  |  Height:  |  Size: 58 KiB