Skip to content

Commit

Permalink
Update KCL docs (#290)
Browse files Browse the repository at this point in the history
YOYO NEW KCL DOCS!!

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
1 parent 79ecfd3 commit 4c84794
Show file tree
Hide file tree
Showing 35 changed files with 55 additions and 1,459 deletions.
2 changes: 1 addition & 1 deletion content/pages/docs/kcl/chamfer.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ mountingPlate = extrude(thickness, mountingPlateSketch)

```js
// Sketch on the face of a chamfer.
fn cube = (pos, scale) => {
fn cube(pos, scale) {
sg = startSketchOn('XY')
|> startProfileAt(pos, %)
|> line([0, scale], %)
Expand Down
2 changes: 1 addition & 1 deletion content/pages/docs/kcl/hole.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion content/pages/docs/kcl/int.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ assertEqual(n, 3, 0.0001, "5/2 = 2.5, rounded up makes 3")
startSketchOn('XZ')
|> circle({ center = [0, 0], radius = 2 }, %)
|> extrude(5, %)
|> patternTransform(n, (id) => {
|> patternTransform(n, fn(id) {
return { translate = [4 * id, 0, 0] }
}, %)
```
Expand Down
4 changes: 2 additions & 2 deletions content/pages/docs/kcl/map.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ map(array: [KclValue], map_fn: FunctionParam) -> [KclValue]

```js
r = 10 // radius
fn drawCircle = (id) => {
fn drawCircle(id) {
return startSketchOn("XY")
|> circle({ center = [id * 2 * r, 0], radius = r }, %)
}
Expand All @@ -45,7 +45,7 @@ circles = map([1..3], drawCircle)
```js
r = 10 // radius
// Call `map`, using an anonymous function instead of a named one.
circles = map([1..3], (id) => {
circles = map([1..3], (id) {
return startSketchOn("XY")
|> circle({ center = [id * 2 * r, 0], radius = r }, %)
})
Expand Down
18 changes: 9 additions & 9 deletions content/pages/docs/kcl/patternTransform.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion content/pages/docs/kcl/patternTransform2d.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ patternTransform2d(total_instances: u32, transform_function: FunctionParam, soli

```js
// Each instance will be shifted along the X axis.
fn transform = (id) => {
fn transform(id) {
return { translate = [4 * id, 0] }
}

Expand Down
10 changes: 5 additions & 5 deletions content/pages/docs/kcl/reduce.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ reduce(array: [KclValue], start: KclValue, reduce_fn: FunctionParam) -> KclValue

```js
// This function adds two numbers.
fn add = (a, b) => {
fn add(a, b) {
return a + b
}

// This function adds an array of numbers.
// It uses the `reduce` function, to call the `add` function on every
// element of the `arr` parameter. The starting value is 0.
fn sum = (arr) => {
fn sum(arr) {
return reduce(arr, 0, add)
}

Expand All @@ -61,7 +61,7 @@ assertEqual(sum([1, 2, 3]), 6, 0.00001, "1 + 2 + 3 summed is 6")
// an anonymous `add` function as its parameter, instead of declaring a
// named function outside.
arr = [1, 2, 3]
sum = reduce(arr, 0, (i, result_so_far) => {
sum = reduce(arr, 0, (i, result_so_far) {
return i + result_so_far
})

Expand All @@ -74,7 +74,7 @@ assertEqual(sum, 6, 0.00001, "1 + 2 + 3 summed is 6")

```js
// Declare a function that sketches a decagon.
fn decagon = (radius) => {
fn decagon(radius) {
// Each side of the decagon is turned this many degrees from the previous angle.
stepAngle = 1 / 10 * tau()

Expand All @@ -84,7 +84,7 @@ fn decagon = (radius) => {
// Use a `reduce` to draw the remaining decagon sides.
// For each number in the array 1..10, run the given function,
// which takes a partially-sketched decagon and adds one more edge to it.
fullDecagon = reduce([1..10], startOfDecagonSketch, (i, partialDecagon) => {
fullDecagon = reduce([1..10], startOfDecagonSketch, (i, partialDecagon) {
// Draw one edge of the decagon.
x = cos(stepAngle * i) * radius
y = sin(stepAngle * i) * radius
Expand Down
2 changes: 1 addition & 1 deletion content/pages/docs/kcl/segEnd.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ cube = startSketchAt([0, 0])
|> close(%)
|> extrude(5, %)

fn cylinder = (radius, tag) => {
fn cylinder(radius, tag) {
return startSketchAt([0, 0])
|> circle({
radius = radius,
Expand Down
2 changes: 1 addition & 1 deletion content/pages/docs/kcl/segStart.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ cube = startSketchAt([0, 0])
|> close(%)
|> extrude(5, %)

fn cylinder = (radius, tag) => {
fn cylinder(radius, tag) {
return startSketchAt([0, 0])
|> circle({
radius = radius,
Expand Down
63 changes: 33 additions & 30 deletions content/pages/docs/kcl/types.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ If you want to get a value from an array you can use the index like so:
An object is defined with `{}` braces. Here is an example object:

```
myObj = {a: 0, b: "thing"}
myObj = { a = 0, b = "thing" }
```

We support two different ways of getting properties from objects, you can call
Expand Down Expand Up @@ -90,12 +90,12 @@ startSketchOn('XZ')
|> startProfileAt(origin, %)
|> angledLine([0, 191.26], %, $rectangleSegmentA001)
|> angledLine([
segAng(rectangleSegmentA001, %) - 90,
segAng(rectangleSegmentA001) - 90,
196.99
], %, $rectangleSegmentB001)
|> angledLine([
segAng(rectangleSegmentA001, %),
-segLen(rectangleSegmentA001, %)
segAng(rectangleSegmentA001),
-segLen(rectangleSegmentA001)
], %, $rectangleSegmentC001)
|> lineTo([profileStartX(%), profileStartY(%)], %)
|> close(%)
Expand All @@ -120,18 +120,18 @@ However if the code was written like this:
```
fn rect = (origin) => {
return startSketchOn('XZ')
|> startProfileAt(origin, %)
|> angledLine([0, 191.26], %, $rectangleSegmentA001)
|> angledLine([
segAng(rectangleSegmentA001, %) - 90,
196.99
], %, $rectangleSegmentB001)
|> angledLine([
segAng(rectangleSegmentA001, %),
-segLen(rectangleSegmentA001, %)
], %, $rectangleSegmentC001)
|> lineTo([profileStartX(%), profileStartY(%)], %)
|> close(%)
|> startProfileAt(origin, %)
|> angledLine([0, 191.26], %, $rectangleSegmentA001)
|> angledLine([
segAng(rectangleSegmentA001) - 90,
196.99
], %, $rectangleSegmentB001)
|> angledLine([
segAng(rectangleSegmentA001),
-segLen(rectangleSegmentA001)
], %, $rectangleSegmentC001)
|> lineTo([profileStartX(%), profileStartY(%)], %)
|> close(%)
}
rect([0, 0])
Expand All @@ -148,26 +148,29 @@ For example the following code works.
```
fn rect = (origin) => {
return startSketchOn('XZ')
|> startProfileAt(origin, %)
|> angledLine([0, 191.26], %, $rectangleSegmentA001)
|> angledLine([
segAng(rectangleSegmentA001, %) - 90,
196.99
], %, $rectangleSegmentB001)
|> angledLine([
segAng(rectangleSegmentA001, %),
-segLen(rectangleSegmentA001, %)
], %, $rectangleSegmentC001)
|> lineTo([profileStartX(%), profileStartY(%)], %)
|> close(%)
|> startProfileAt(origin, %)
|> angledLine([0, 191.26], %, $rectangleSegmentA001)
|> angledLine([
segAng(rectangleSegmentA001) - 90,
196.99
], %, $rectangleSegmentB001)
|> angledLine([
segAng(rectangleSegmentA001),
-segLen(rectangleSegmentA001)
], %, $rectangleSegmentC001)
|> lineTo([profileStartX(%), profileStartY(%)], %)
|> close(%)
}
rect([0, 0])
myRect = rect([20, 0])
myRect
myRect
|> extrude(10, %)
|> fillet({radius: 0.5, tags: [myRect.tags.rectangleSegmentA001]}, %)
|> fillet({
radius = 0.5,
tags = [myRect.tags.rectangleSegmentA001]
}, %)
```

See how we use the tag `rectangleSegmentA001` in the `fillet` function outside
Expand Down
161 changes: 0 additions & 161 deletions content/pages/docs/kcl/types/BinaryOperator.md

This file was deleted.

Loading

0 comments on commit 4c84794

Please sign in to comment.