Removes JSON from the KCL object model. Closes https://github.com/KittyCAD/modeling-app/issues/1130 -- it was filed on Nov 27 last year. Hopefully I close it before its one year anniversary. Changes: - Removed the UserVal variant from `enum KclValue`. That variant held JSON data. - Replaced it with several new variants like Number, String, Array (of KCL values), Object (where keys are String and values are KCL values) - Added a dedicated Sketch variant to KclValue. We used to have a variant like this, but I removed it as an experimental approach to fix this issue. Eventually I decided to undo it and use the approach of this PR instead. - Removed the `impl_from_arg_via_json` macro, which implemented conversion from KclValue to Rust types by matching the KclValue to its UserVal variant, grabbing the JSON, then deserializing that into the desired Rust type. - Instead, replaced it with manual conversion from KclValue to Rust types, using some convenience macros like `field!`
119 lines
484 KiB
Markdown
119 lines
484 KiB
Markdown
---
|
|
title: "offsetPlane"
|
|
excerpt: "Offset a plane by a distance along its normal."
|
|
layout: manual
|
|
---
|
|
|
|
Offset a plane by a distance along its normal.
|
|
|
|
For example, if you offset the 'XZ' plane by 10, the new plane will be parallel to the 'XZ' plane and 10 units away from it.
|
|
|
|
```js
|
|
offsetPlane(std_plane: StandardPlane, offset: number) -> PlaneData
|
|
```
|
|
|
|
|
|
### Arguments
|
|
|
|
| Name | Type | Description | Required |
|
|
|----------|------|-------------|----------|
|
|
| `std_plane` | [`StandardPlane`](/docs/kcl/types/StandardPlane) | One of the standard planes. | Yes |
|
|
| `offset` | `number` | | Yes |
|
|
|
|
### Returns
|
|
|
|
[`PlaneData`](/docs/kcl/types/PlaneData) - Data for a plane.
|
|
|
|
|
|
### Examples
|
|
|
|
```js
|
|
// Loft a square and a circle on the `XY` plane using offset.
|
|
squareSketch = startSketchOn('XY')
|
|
|> startProfileAt([-100, 200], %)
|
|
|> line([200, 0], %)
|
|
|> line([0, -200], %)
|
|
|> line([-200, 0], %)
|
|
|> lineTo([profileStartX(%), profileStartY(%)], %)
|
|
|> close(%)
|
|
|
|
circleSketch = startSketchOn(offsetPlane('XY', 150))
|
|
|> circle({ center: [0, 100], radius: 50 }, %)
|
|
|
|
loft([squareSketch, circleSketch])
|
|
```
|
|
|
|

|
|
|
|
```js
|
|
// Loft a square and a circle on the `XZ` plane using offset.
|
|
squareSketch = startSketchOn('XZ')
|
|
|> startProfileAt([-100, 200], %)
|
|
|> line([200, 0], %)
|
|
|> line([0, -200], %)
|
|
|> line([-200, 0], %)
|
|
|> lineTo([profileStartX(%), profileStartY(%)], %)
|
|
|> close(%)
|
|
|
|
circleSketch = startSketchOn(offsetPlane('XZ', 150))
|
|
|> circle({ center: [0, 100], radius: 50 }, %)
|
|
|
|
loft([squareSketch, circleSketch])
|
|
```
|
|
|
|

|
|
|
|
```js
|
|
// Loft a square and a circle on the `YZ` plane using offset.
|
|
squareSketch = startSketchOn('YZ')
|
|
|> startProfileAt([-100, 200], %)
|
|
|> line([200, 0], %)
|
|
|> line([0, -200], %)
|
|
|> line([-200, 0], %)
|
|
|> lineTo([profileStartX(%), profileStartY(%)], %)
|
|
|> close(%)
|
|
|
|
circleSketch = startSketchOn(offsetPlane('YZ', 150))
|
|
|> circle({ center: [0, 100], radius: 50 }, %)
|
|
|
|
loft([squareSketch, circleSketch])
|
|
```
|
|
|
|

|
|
|
|
```js
|
|
// Loft a square and a circle on the `-XZ` plane using offset.
|
|
squareSketch = startSketchOn('-XZ')
|
|
|> startProfileAt([-100, 200], %)
|
|
|> line([200, 0], %)
|
|
|> line([0, -200], %)
|
|
|> line([-200, 0], %)
|
|
|> lineTo([profileStartX(%), profileStartY(%)], %)
|
|
|> close(%)
|
|
|
|
circleSketch = startSketchOn(offsetPlane('-XZ', -150))
|
|
|> circle({ center: [0, 100], radius: 50 }, %)
|
|
|
|
loft([squareSketch, circleSketch])
|
|
```
|
|
|
|

|
|
|
|
```js
|
|
// A circle on the XY plane
|
|
startSketchOn("XY")
|
|
|> startProfileAt([0, 0], %)
|
|
|> circle({ radius: 10, center: [0, 0] }, %)
|
|
|
|
// Triangle on the plane 4 units above
|
|
startSketchOn(offsetPlane("XY", 4))
|
|
|> startProfileAt([0, 0], %)
|
|
|> line([10, 0], %)
|
|
|> line([0, 10], %)
|
|
|> close(%)
|
|
```
|
|
|
|

|
|
|
|
|