Compare commits

..

1 Commits

Author SHA1 Message Date
0bc0ed45b9 Run file tests on Windows to cover path differences 2025-05-06 21:26:42 -04:00
524 changed files with 17487 additions and 88087 deletions

View File

@ -1,5 +1,3 @@
# DO NOT commit secrets, overrides go in the ignored `.env.development.local`
NODE_ENV=development
DEV=true
@ -9,11 +7,7 @@ VITE_KC_SITE_BASE_URL=https://dev.zoo.dev
VITE_KC_SITE_APP_URL=https://app.dev.zoo.dev
VITE_KC_SKIP_AUTH=false
VITE_KC_CONNECTION_TIMEOUT_MS=5000
#VITE_KC_DEV_TOKEN="optional token to skip auth in the app"
#token="required token for playwright. TODO: clean up env vars in #3973"
RUST_BACKTRACE=1
PYO3_PYTHON=/usr/local/bin/python3
#KITTYCAD_API_TOKEN="required token for engine testing"
# ONLY add your token in .env.development.local if you want to skip auth, otherwise this token takes precedence!
#VITE_KC_DEV_TOKEN="your token from dev.zoo.dev should go in .env.development.local"
FAIL_ON_CONSOLE_ERRORS=true

View File

@ -1,13 +0,0 @@
#!/bin/bash
set -euo pipefail
BRANCH="${GITHUB_HEAD_REF:-${GITHUB_REF_NAME:-}}"
COMMIT="${CI_COMMIT_SHA:-${GITHUB_SHA:-}}"
curl --request POST \
--header "X-API-Key: ${TAB_API_KEY}" \
--form "project=https://github.com/KittyCAD/modeling-app" \
--form "branch=${BRANCH}" \
--form "commit=${COMMIT}" \
--form "tests=@test-results/junit.xml" \
${TAB_API_URL}/api/results/bulk

View File

@ -2,6 +2,7 @@ on:
push:
branches:
- main
pull_request:
workflow_dispatch:
permissions:
@ -98,7 +99,9 @@ jobs:
popd
git add \
rust/kcl-lib/tests \
public/kcl-samples
public/kcl-samples/manifest.json \
public/kcl-samples/README.md \
public/kcl-samples/screenshots
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git remote set-url origin https://${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git
@ -128,6 +131,7 @@ jobs:
with:
name: nextest-archive
path: rust/nextest-archive.tar.zst
run-test-artifacts:
name: cargo test (shard ${{ matrix.partitionIndex}})
runs-on:
@ -175,53 +179,11 @@ jobs:
cp nextest-archive.tar.zst rust/nextest-archive.tar.zst
ls -lah
cd rust
cargo nextest run \
--retries=10 --no-fail-fast --profile=ci --archive-file nextest-archive.tar.zst \
cargo nextest run\
--retries=10 --no-fail-fast --profile ci --archive-file nextest-archive.tar.zst \
--partition count:${{ matrix.partitionIndex}}/${{ matrix.partitionTotal }} \
2>&1 | tee /tmp/github-actions.log
env:
KITTYCAD_API_TOKEN: ${{secrets.KITTYCAD_API_TOKEN_DEV}}
ZOO_HOST: https://api.dev.zoo.dev
- name: Upload results
if: always()
run: .github/ci-cd-scripts/upload-results.sh
env:
TAB_API_URL: ${{ secrets.TAB_API_URL }}
TAB_API_KEY: ${{ secrets.TAB_API_KEY }}
run-wasm-tests:
name: Run wasm tests
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
fail-fast: false
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- name: Use correct Rust toolchain
shell: bash
run: |
[ -e rust-toolchain.toml ] || cp rust/rust-toolchain.toml ./
- name: Install rust
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
cache: false # Configured below.
- uses: taiki-e/install-action@d4635f2de61c8b8104d59cd4aede2060638378cc
with:
tool: wasm-pack
- name: Rust Cache
uses: Swatinem/rust-cache@v2
with:
workspaces: './rust'
- name: Build Wasm
shell: bash
run: |
npm install
npm run build:wasm
- name: Run wasm tests
run: |
cd rust
cd kcl-wasm-lib
#wasm-pack test --headless --chrome
env:
KITTYCAD_API_TOKEN: ${{ secrets.KITTYCAD_API_TOKEN_DEV }}
NODE_ENV: development

View File

@ -229,6 +229,7 @@ jobs:
max_attempts: 5
env:
token: ${{ secrets.KITTYCAD_API_TOKEN_DEV }}
snapshottoken: ${{ secrets.KITTYCAD_API_TOKEN }}
TAB_API_URL: ${{ secrets.TAB_API_URL }}
TAB_API_KEY: ${{ secrets.TAB_API_KEY }}
CI_COMMIT_SHA: ${{ github.event.pull_request.head.sha }}

View File

@ -171,8 +171,13 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
- name: Install codespell
run: |
python -m pip install codespell
- name: Run codespell
uses: crate-ci/typos@v1.32.0
run: codespell --config .codespellrc # Edit this file to tweak the typo list and other configuration.
npm-unit-test-kcl-samples:
runs-on: ubuntu-latest

1
.husky/pre-commit Executable file
View File

@ -0,0 +1 @@
npm run fmt

View File

@ -1 +0,0 @@
npm run fmt:check

View File

@ -63,7 +63,7 @@ If you're not a Zoo employee you won't be able to access the dev environment, yo
### Development environment variables
The Copilot LSP plugin in the editor requires a Zoo API token to run. In production, we authenticate this with a token via cookie in the browser and device auth token in the desktop environment, but this token is inaccessible in the dev browser version because the cookie is considered "cross-site" (from `localhost` to `zoo.dev`). There is an optional environment variable called `VITE_KC_DEV_TOKEN` that you can populate with a dev token in a `.env.development.local` file to not check it into Git, which will use that token instead of other methods for the LSP service.
The Copilot LSP plugin in the editor requires a Zoo API token to run. In production, we authenticate this with a token via cookie in the browser and device auth token in the desktop environment, but this token is inaccessible in the dev browser version because the cookie is considered "cross-site" (from `localhost` to `dev.zoo.dev`). There is an optional environment variable called `VITE_KC_DEV_TOKEN` that you can populate with a dev token in a `.env.development.local` file to not check it into Git, which will use that token instead of other methods for the LSP service.
### Developing in Chrome
@ -198,9 +198,15 @@ For more information on fuzzing you can check out
### Playwright tests
Prepare these system dependencies:
You will need a `./e2e/playwright/playwright-secrets.env` file:
- Set $token from https://zoo.dev/account/api-tokens
```bash
$ touch ./e2e/playwright/playwright-secrets.env
$ cat ./e2e/playwright/playwright-secrets.env
token=<dev.zoo.dev/account/api-tokens>
snapshottoken=<zoo.dev/account/api-tokens>
```
or use `export` to set the environment variables `token` and `snapshottoken`.
#### Snapshot tests (Google Chrome on Ubuntu only)
@ -294,17 +300,131 @@ Which will run our suite of [Vitest unit](https://vitest.dev/) and [React Testin
### Rust tests
Prepare these system dependencies:
**Dependencies**
- Set `$KITTYCAD_API_TOKEN` from https://zoo.dev/account/api-tokens
- Install `just` following [these instructions](https://just.systems/man/en/packages.html)
- `KITTYCAD_API_TOKEN`
- `cargo-nextest`
- `just`
then run tests that target the KCL language:
#### Setting KITTYCAD_API_TOKEN
Use the production zoo.dev token, set this environment variable before running the tests
#### Installing cargonextest
```
npm run test:rust
cd rust
cargo search cargo-nextest
cargo install cargo-nextest
```
#### just
install [`just`](https://github.com/casey/just?tab=readme-ov-file#pre-built-binaries)
#### Running the tests
```bash
# With just
# Make sure KITTYCAD_API_TOKEN=<prod zoo.dev token> is set
# Make sure you installed cargo-nextest
# Make sure you installed just
cd rust
just test
```
```bash
# Without just
# Make sure KITTYCAD_API_TOKEN=<prod zoo.dev token> is set
# Make sure you installed cargo-nextest
cd rust
export RUST_BRACKTRACE="full" && cargo nextest run --workspace --test-threads=1
```
Where `XXX` is an API token from the production engine (NOT the dev environment).
We recommend using [nextest](https://nexte.st/) to run the Rust tests (its faster and is used in CI). Once installed, run the tests using
```
cd rust
KITTYCAD_API_TOKEN=XXX cargo run nextest
```
### Mapping CI CD jobs to local commands
When you see the CI CD fail on jobs you may wonder three things
- Do I have a bug in my code?
- Is the test flaky?
- Is there a bug in `main`?
To answer these questions the following commands will give you confidence to locate the issue.
#### Static Analysis
Part of the CI CD pipeline performs static analysis on the code. Use the following commands to mimic the CI CD jobs.
The following set of commands should get us closer to one and done commands to instantly retest issues.
```
npm run test-setup
```
> Gotcha, are packages up to date and is the wasm built?
```
npm run tsc
npm run fmt:check
npm run lint
npm run test:unit:local
```
> Gotcha: Our unit tests have integration tests in them. You need to run a localhost server to run the unit tests.
#### E2E Tests
**Playwright Electron**
These E2E tests run in electron. There are tests that are skipped if they are ran in a windows, linux, or macos environment. We can use playwright tags to implement test skipping.
```
npm run test:playwright:electron:local
npm run test:playwright:electron:windows:local
npm run test:playwright:electron:macos:local
npm run test:playwright:electron:ubuntu:local
```
> Why does it say local? The CI CD commands that run in the pipeline cannot be ran locally. A single command will not properly setup the testing environment locally.
#### Some notes on CI
The tests are broken into snapshot tests and non-snapshot tests, and they run in that order, they automatically commit new snap shots, so if you see an image commit check it was an intended change. If we have non-determinism in the snapshots such that they are always committing new images, hopefully this annoyance makes us fix them asap, if you notice this happening let Kurt know. But for the odd occasion `git reset --hard HEAD~ && git push -f` is your friend.
How to interpret failing playwright tests?
If your tests fail, click through to the action and see that the tests failed on a line that includes `await page.getByTestId('loading').waitFor({ state: 'detached' })`, this means the test fail because the stream never started. It's you choice if you want to re-run the test, or ignore the failure.
We run on ubuntu and macos, because safari doesn't work on linux because of the dreaded "no RTCPeerConnection variable" error. But linux runs first and then macos for the same reason that we limit the number of parallel tests to 1 because we limit stream connections per user, so tests would start failing we if let them run together.
If something fails on CI you can download the artifact, unzip it and then open `playwright-report/data/<UUID>.zip` with https://trace.playwright.dev/ to see what happened.
#### Getting started writing a playwright test in our app
Besides following the instructions above and using the playwright docs, our app is weird because of the whole stream thing, which means our testing is weird. Because we've just figured out this stuff and therefore docs might go stale quick here's a 15min vid/tutorial
https://github.com/KittyCAD/modeling-app/assets/29681384/6f5e8e85-1003-4fd9-be7f-f36ce833942d
<details>
<summary>
PS: for the debug panel, the following JSON is useful for snapping the camera
</summary>
```JSON
{"type":"modeling_cmd_req","cmd_id":"054e5472-e5e9-4071-92d7-1ce3bac61956","cmd":{"type":"default_camera_look_at","center":{"x":15,"y":0,"z":0},"up":{"x":0,"y":0,"z":1},"vantage":{"x":30,"y":30,"z":30}}}
```
</details>
### Logging
To display logging (to the terminal or console) set `ZOO_LOG=1`. This will log some warnings and simple performance metrics. To view these in test runs, use `-- --nocapture`.

View File

@ -1,5 +1,5 @@
.PHONY: all
all: install check build
all: install build check
###############################################################################
# INSTALL
@ -106,7 +106,6 @@ test: test-unit test-e2e
.PHONY: test-unit
test-unit: install ## Run the unit tests
npm run test:rust
@ curl -fs localhost:3000 >/dev/null || ( echo "Error: localhost:3000 not available, 'make run-web' first" && exit 1 )
npm run test:unit

View File

@ -1,39 +0,0 @@
[files]
extend-exclude = [
"**/target",
"node_modules",
"build",
"dist",
"out",
"**/Cargo.lock",
"docs/**/*.md",
"docs/**/*.json",
"e2e/playwright/lib/console-error-whitelist.ts",
".package-lock.json",
"**/package-lock.json",
"openapi/*.json",
"packages/codemirror-lang-kcl/test/all.test.ts",
"public/kcl-samples",
"rust/kcl-lib/tests/kcl_samples",
"tsconfig.tsbuildinfo",
"src/lib/machine-api.d.ts",
"kcl-book/book",
]
[default.extend-words]
metalness = "metalness" # appearance API
Hom = "Hom" # short for homogenous
typ = "typ" # used to declare a variable named 'type' which is a reserved keyword in Rust
ue = "ue" # short for UnaryExpression
THRE = "THRE" # Weird bug that wrongly detects THREEjs as a typo
nwo = "nwo" # don't know what this is about tbh
"ot" = "ot" # some abbreviation, idk what
"oe" = "oe" # some abbreviation, idk what
[default]
extend-ignore-identifiers-re = [
"\\dnd", # e.g. 2nd
]
extend-ignore-re = [
"@xstate-layout .*",
]

View File

@ -1,53 +0,0 @@
---
title: "Arithmetic and logic"
excerpt: "Documentation of the KCL language for the Zoo Design Studio."
layout: manual
---
KCL supports the usual arithmetic operators on numbers and logic operators on booleans:
| Operator | Meaning |
|----------|---------|
| `+` | Addition |
| `-` | Subtraction or unary negation |
| `*` | Multiplication |
| `/` | Division |
| `%` | Modulus aka remainder |
| `^` | Power, e.g., `x ^ 2` means `x` squared |
| `&` | Logical 'and' |
| `|` | Logical 'or' |
| `!` | Unary logical 'not' |
KCL also supports comparsion operators which operate on numbers and produce booleans:
| Operator | Meaning |
|----------|---------|
| `==` | Equal |
| `!=` | Not equal |
| `<` | Less than |
| `>` | Greater than |
| `<=` | Less than or equal |
| `>=` | Greater than or equal |
Arithmetics and logic expressions can be arbitrairly combined with the usual rules of associativity and precedence, e.g.,
```
myMathExpression = 3 + 1 * 2 / 3 - 7
```
You can also nest expressions in parenthesis:
```
myMathExpression = 3 + (1 * 2 / (3 - 7))
```
KCL numbers are implemented using [floating point numbers](https://en.wikipedia.org/wiki/Floating-point_arithmetic). This means that there are occasionally representation and rounding issues, and some oddities such as supporting positive and negative zero.
Some operators can be applied to other types:
- `+` can be used to concatenate strings, e.g., `'hello' + ' ' + 'world!'`
- Unary `-` can be used with planes or line-like objects such as axes to produce an object with opposite orientation, e.g., `-XY` is a plain which is aligned with `XY` but whose normal aligns with the negative Z axis.
- The following operators can be used with solids as shorthand for CSG operations:
- `+` or `|` for [`union`](/docs/kcl-std/union).
- `-` for [`subtract`](/docs/kcl-std/subtract).
- `&` for [`intersect`](/docs/kcl-std/intersect)

View File

@ -1,30 +0,0 @@
---
title: "Attributes"
excerpt: "Documentation of the KCL language for the Zoo Design Studio."
layout: manual
---
Attributes are syntax which affects the language item they annotate. In KCL they are indicated using `@`. For example, `@settings` affects the file in which it appears.
There are two kinds of attributes: named and unnamed attributes. Named attributes (e.g., `@settings`) have a name immediately after the `@` (e.g., `settings`) and affect their surrounding scope. Unnamed attributes have no name and affect the following item, e.g.,
```kcl,norun
@(lengthUnit = ft, coords = opengl)
import "tests/inputs/cube.obj"
```
has an unnamed attribute on the `import` statement.
Named and unnamed attributes may take a parenthesized list of arguments (like a function). Named attributes may also appear without any arguments (e.g., `@no_std`).
## Named attributes
The `@settings` attribute affects the current file and accepts the following arguments: `defaultLengthUnit`, `defaultAngleUnit`, and `kclVersion`. See [settings](/docs/kcl-lang/settings) for details.
The `@no_std` attribute affects the current file, takes no arguments, and causes the standard library to not be implicitly available. It can still be used by being explicitly imported.
## Unnamed attributes
Unnamed attributes may be used on `import` statements when importing non-KCL files. See [projects, modules, and imports](/docs/kcl-lang/modules) for details.
Other unnamed attributes are used on functions inside the standard library, but these are not available in user code.

View File

@ -1,46 +0,0 @@
---
title: "Functions"
excerpt: "Documentation of the KCL language for the Zoo Design Studio."
layout: manual
---
We have support for defining your own functions. Functions can take in any
type of argument. Below is an example of the syntax:
```
fn myFn(x) {
return x
}
```
As you can see above `myFn` just returns whatever it is given.
KCL uses keyword arguments:
```
// If you declare a function like this
fn add(left, right) {
return left + right
}
// You can call it like this:
total = add(left = 1, right = 2)
```
Functions can also declare one *unlabeled* arg. If you do want to declare an unlabeled arg, it must
be the first arg declared.
```
// The @ indicates an argument is used without a label.
// Note that only the first argument can use @.
fn increment(@x) {
return x + 1
}
fn add(@x, delta) {
return x + delta
}
two = increment(1)
three = add(1, delta = 2)
```

View File

@ -1,20 +1,12 @@
---
title: "KCL Language Reference"
title: "KCL Language Guide"
excerpt: "Documentation of the KCL language for the Zoo Design Studio."
layout: manual
---
This is a reference for KCL. If you are learning KCL, you may prefer the [guide]() which explains
things in a more tutorial fashion.
## Topics
* [Pipelines](/docs/kcl-lang/pipelines)
* [Arithmetic and logic](/docs/kcl-lang/arithmetic)
* [Values and types](/docs/kcl-lang/types)
* [Numeric types and units](/docs/kcl-lang/numeric)
* [Functions](/docs/kcl-lang/functions)
* [Projects, modules, and imports](/docs/kcl-lang/modules)
* [Attributes](/docs/kcl-lang/attributes)
* [Settings](/docs/kcl-lang/settings)
* [Known Issues](/docs/kcl-lang/known-issues)
* [`Types`](/docs/kcl-lang/types)
* [`Modules`](/docs/kcl-lang/modules)
* [`Settings`](/docs/kcl-lang/settings)
* [`Known Issues`](/docs/kcl-lang/known-issues)

View File

@ -1,5 +1,5 @@
---
title: "Known Issues"
title: "KCL Known Issues"
excerpt: "Known issues with the KCL standard library for the Zoo Design Studio."
layout: manual
---
@ -15,6 +15,12 @@ once fixed in engine will just start working here with no language changes.
- **Import**: Right now you can import a file, even if that file has brep data
you cannot edit it, after v1, the engine will account for this.
- **Fillets**: Fillets cannot intersect, you will get an error. Only simple fillet
cases work currently.
- **Chamfers**: Chamfers cannot intersect, you will get an error. Only simple
chamfer cases work currently.
- **Appearance**: Changing the appearance on a loft does not work.
- **CSG Booleans**: Coplanar (bodies that share a plane) unions, subtractions, and intersections are not currently supported.

View File

@ -1,6 +1,6 @@
---
title: "Modules"
excerpt: "Documentation of the KCL language for the Zoo Design Studio."
title: "KCL Modules"
excerpt: "Documentation of modules for the KCL language for the Zoo Design Studio."
layout: manual
---

View File

@ -1,46 +0,0 @@
---
title: "Numeric types and units"
excerpt: "Documentation of the KCL language for the Zoo Design Studio."
layout: manual
---
Numbers and numeric types in KCL include information about the units of the numbers. So rather than just having a number like `42`, we always have information about the units so we don't confuse 42 mm with 42 inches.
## Numeric literals
When writing a number literal, you can use a unit suffix to explicitly state the unit, e.g., `42mm`. The following units are available:
- Length units:
- metric: `mm`, `cm`, `m`
- imperial: `in`, `ft`, `yd`
- Angle units: `deg`, `rad`
- `_` to indicate a unitless number such as a count or ratio.
If you write a numeric literal without a suffix, then the defaults for the current file are used. These defaults are specified using the `@settings` attribute, see [settings](/docs/kcl-lang/settings) for details. Note that if using the defaults, the KCL interpreter won't know whether you intend the number to be a length, angle, or count and will treat it as being possibly any of them.
## Numeric types
Just like numbers carry units information, the `number` type also includes units information. Units are written in parentheses after the type, e.g., `number(mm)`.
Any of the suffixes described above can be used meaning that values with that type have the supplied units. E.g., `number(mm)` is the type of number values with mm units and `number(_)` is the type of number values with no units.
You can also use `number(Length)`, `number(Angle)`, or `number(Count)`. These types mean a number with any length, angle, or unitless (count) units, respectively (note that `number(_)` and `number(Count)` are equivalent since there is only one kind of unitless-ness).
## Function calls
When calling a function with an argument with numeric type, the declared numeric type in the function signature and the units of the argument value used in the function call must be compatible. Units are adjusted automatically. For example, if a function requires an argument with type `number(mm)`, then you can call it with `2in` and the units will be automatically adjusted, but calling it with `90deg` will cause an error.
## Mixing units with arithmetic
When doing arithmetic or comparisons, units will be adjusted as necessary if possible. However, often arithmetic expressions exceed the ability of KCL to accurately choose units which can result in warnings in your code or sometimes errors. In these cases, you will need to give KCL more information. Sometimes this can be done by making units explicit using suffixes. If not, then you will need to use *type ascription*, which asserts that an expression has the supplied type. For example, `(x * y): number(mm)` tells KCL that the units of `x * y` is mm. Note that type ascription does not do any adjustment of the numbers, e.g., `2mm: number(in)` has the value `2in` (note that this would be a very non-idiomatic way to use numeric type ascription, you could simply write `2in`. Usually type ascription is only necessary for supplying type information about the result of computation).
KCL has no support for area, volume, or other higher dimension units. When internal unit tracking requires multiple dimensions, KCL essentially gives up. This is usually where the extra type information described above is needed. If doing computation with higher dimensioned units, you must ensure that all adjustments occur before any computation. E.g., if you want to compute an area with unknown units, you must convert all numbers to the same unit before starting.
## Explicit conversions
You might sometimes need to convert from one unit to another for some calculation. You can do this implicitly when calling a function (see above), but if you can't or don't want to, then you can use the explicit conversion functions in the [`std::units`](/docs/kcl-std/modules/std-units) module.

View File

@ -1,66 +0,0 @@
---
title: "Pipelines"
excerpt: "Documentation of the KCL language for the Zoo Design Studio."
layout: manual
---
It can be hard to read repeated function calls, because of all the nested brackets.
```norun
i = 1
x = h(g(f(i)))
```
You can make this easier to read by breaking it into many declarations, but that is a bit annoying.
```norun
i = 1
x0 = f(i)
x1 = g(x0)
x = h(x1)
```
Instead, you can use the pipeline operator (`|>`) to simplify this.
Basically, `x |> f(%)` is a shorthand for `f(x)`. The left-hand side of the `|>` gets put into
the `%` in the right-hand side.
So, this means `x |> f(%) |> g(%)` is shorthand for `g(f(x))`. The code example above, with its
somewhat-clunky `x0` and `x1` constants could be rewritten as
```norun
i = 1
x = i
|> f(%)
|> g(%)
|> h(%)
```
This helps keep your code neat and avoid unnecessary declarations.
## Pipelines and keyword arguments
Say you have a long pipeline of sketch functions, like this:
```norun
startSketchOn(XZ)
|> line(%, end = [3, 4])
|> line(%, end = [10, 10])
|> line(%, end = [-13, -14])
|> close(%)
```
In this example, each function call outputs a sketch, and it gets put into the next function call via
the `%`, into the first (unlabeled) argument.
If a function call uses an unlabeled first parameter, it will default to `%` if it's not given. This
means that `|> line(%, end = [3, 4])` and `|> line(end = [3, 4])` are equivalent! So the above
could be rewritten as
```norun
startSketchOn(XZ)
|> line(end = [3, 4])
|> line(end = [10, 10])
|> line(end = [-13, -14])
|> close()
```

View File

@ -1,6 +1,6 @@
---
title: "Settings"
excerpt: "Documentation of the KCL language for the Zoo Design Studio."
title: "KCL Settings"
excerpt: "Documentation of settings for the KCL language and Zoo Design Studio."
layout: manual
---
@ -8,16 +8,16 @@ layout: manual
There are three levels of settings available in Zoo Design Studio:
1. [User Settings](/docs/kcl-lang/settings/user): Global settings that apply to all projects, stored in `user.toml`
2. [Project Settings](/docs/kcl-lang/settings/project): Settings specific to a project, stored in `project.toml`
1. [User Settings](/docs/kcl/settings-user): Global settings that apply to all projects, stored in `user.toml`
2. [Project Settings](/docs/kcl/settings-project): Settings specific to a project, stored in `project.toml`
3. Per-file Settings: Settings that apply to a single KCL file, specified using the `@settings` attribute
## Configuration Files
Zoo Design Studio uses TOML files for configuration:
* **User Settings**: `user.toml` - See [complete documentation](/docs/kcl-lang/settings/user)
* **Project Settings**: `project.toml` - See [complete documentation](/docs/kcl-lang/settings/project)
* **User Settings**: `user.toml` - See [complete documentation](/docs/kcl/settings-user)
* **Project Settings**: `project.toml` - See [complete documentation](/docs/kcl/settings-project)
## Per-file settings

View File

@ -1,6 +1,6 @@
---
title: "Values and types"
excerpt: "Documentation of the KCL language for the Zoo Design Studio."
title: "KCL Types"
excerpt: "Documentation of types for the KCL standard library for the Zoo Design Studio."
layout: manual
---
@ -52,6 +52,131 @@ their internal components. See the [modules and imports docs](modules) for more
detail on importing geometry.
## Binary expressions
You can also do math! Let's show an example below:
```
myMathExpression = 3 + 1 * 2 / 3 - 7
```
You can nest expressions in parenthesis as well:
```
myMathExpression = 3 + (1 * 2 / (3 - 7))
```
## Functions
We also have support for defining your own functions. Functions can take in any
type of argument. Below is an example of the syntax:
```
fn myFn(x) {
return x
}
```
As you can see above `myFn` just returns whatever it is given.
KCL's early drafts used positional arguments, but we now use keyword arguments:
```
// If you declare a function like this
fn add(left, right) {
return left + right
}
// You can call it like this:
total = add(left = 1, right = 2)
```
Functions can also declare one *unlabeled* arg. If you do want to declare an unlabeled arg, it must
be the first arg declared.
```
// The @ indicates an argument can be used without a label.
// Note that only the first argument can use @.
fn increment(@x) {
return x + 1
}
fn add(@x, delta) {
return x + delta
}
two = increment(1)
three = add(1, delta = 2)
```
## Pipelines
It can be hard to read repeated function calls, because of all the nested brackets.
```norun
i = 1
x = h(g(f(i)))
```
You can make this easier to read by breaking it into many declarations, but that is a bit annoying.
```norun
i = 1
x0 = f(i)
x1 = g(x0)
x = h(x1)
```
Instead, you can use the pipeline operator (`|>`) to simplify this.
Basically, `x |> f(%)` is a shorthand for `f(x)`. The left-hand side of the `|>` gets put into
the `%` in the right-hand side.
So, this means `x |> f(%) |> g(%)` is shorthand for `g(f(x))`. The code example above, with its
somewhat-clunky `x0` and `x1` constants could be rewritten as
```norun
i = 1
x = i
|> f(%)
|> g(%)
|> h(%)
```
This helps keep your code neat and avoid unnecessary declarations.
## Pipelines and keyword arguments
Say you have a long pipeline of sketch functions, like this:
```norun
startSketchOn(XZ)
|> line(%, end = [3, 4])
|> line(%, end = [10, 10])
|> line(%, end = [-13, -14])
|> close(%)
```
In this example, each function call outputs a sketch, and it gets put into the next function call via
the `%`, into the first (unlabeled) argument.
If a function call uses an unlabeled first parameter, it will default to `%` if it's not given. This
means that `|> line(%, end = [3, 4])` and `|> line(end = [3, 4])` are equivalent! So the above
could be rewritten as
```norun
startSketchOn(XZ)
|> line(end = [3, 4])
|> line(end = [10, 10])
|> line(end = [-13, -14])
|> close()
```
Note that we are still in the process of migrating KCL's standard library to use keyword arguments. So some
functions are still unfortunately using positional arguments. We're moving them over, so keep checking back.
Some functions are still using the old positional argument syntax.
Check the docs page for each function and look at its examples to see.
## Tags
Tags are used to give a name (tag) to a specific path.
@ -166,6 +291,7 @@ See how we use the tag `rectangleSegmentA001` in the `fillet` function outside
the `rect` function. This is because the `rect` function is returning the
sketch group that contains the tags.
---
If you find any issues using any of the above expressions or syntax,

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,6 +1,6 @@
---
title: "END"
subtitle: "Constant in std"
subtitle: "Constant in prelude"
excerpt: "Identifies the ending face of an extrusion. I.e., the new face created by an extrusion."
layout: manual
---

View File

@ -1,6 +1,6 @@
---
title: "START"
subtitle: "Constant in std"
subtitle: "Constant in prelude"
excerpt: "Identifies the starting face of an extrusion. I.e., the face which is extruded."
layout: manual
---

View File

@ -1,11 +1,11 @@
---
title: "X"
subtitle: "Constant in std"
excerpt: "The X-axis (can be used in both 2d and 3d contexts)."
subtitle: "Constant in prelude"
excerpt: ""
layout: manual
---
The X-axis (can be used in both 2d and 3d contexts).
```kcl
X

View File

@ -1,11 +1,11 @@
---
title: "XY"
subtitle: "Constant in std"
excerpt: "An abstract 3d plane aligned with the X and Y axes. Its normal is the positive Z axis."
subtitle: "Constant in prelude"
excerpt: ""
layout: manual
---
An abstract 3d plane aligned with the X and Y axes. Its normal is the positive Z axis.
```kcl
XY

View File

@ -1,11 +1,11 @@
---
title: "XZ"
subtitle: "Constant in std"
excerpt: "An abstract 3d plane aligned with the X and Z axes. Its normal is the negative Y axis."
subtitle: "Constant in prelude"
excerpt: ""
layout: manual
---
An abstract 3d plane aligned with the X and Z axes. Its normal is the negative Y axis.
```kcl
XZ

View File

@ -1,11 +1,11 @@
---
title: "Y"
subtitle: "Constant in std"
excerpt: "The Y-axis (can be used in both 2d and 3d contexts)."
subtitle: "Constant in prelude"
excerpt: ""
layout: manual
---
The Y-axis (can be used in both 2d and 3d contexts).
```kcl
Y

View File

@ -1,11 +1,11 @@
---
title: "YZ"
subtitle: "Constant in std"
excerpt: "An abstract 3d plane aligned with the Y and Z axes. Its normal is the positive X axis."
subtitle: "Constant in prelude"
excerpt: ""
layout: manual
---
An abstract 3d plane aligned with the Y and Z axes. Its normal is the positive X axis.
```kcl
YZ

View File

@ -1,11 +1,11 @@
---
title: "Z"
subtitle: "Constant in std"
excerpt: "The 3D Z-axis."
subtitle: "Constant in prelude"
excerpt: ""
layout: manual
---
The 3D Z-axis.
```kcl
Z

View File

@ -1,6 +1,6 @@
---
title: "E"
subtitle: "Constant in std::math"
subtitle: "Constant in math"
excerpt: "The value of Eulers number `e`."
layout: manual
---

View File

@ -1,6 +1,6 @@
---
title: "PI"
subtitle: "Constant in std::math"
subtitle: "Constant in math"
excerpt: "The value of `pi`, Archimedes constant (π)."
layout: manual
---

View File

@ -1,6 +1,6 @@
---
title: "TAU"
subtitle: "Constant in std::math"
subtitle: "Constant in math"
excerpt: "The value of `tau`, the full circle constant (τ). Equal to 2π."
layout: manual
---

View File

@ -1,11 +1,11 @@
---
title: "turns::HALF_TURN"
subtitle: "Constant in std::turns"
excerpt: "A half turn, 180 degrees or π radians."
subtitle: "Constant in turns"
excerpt: ""
layout: manual
---
A half turn, 180 degrees or π radians.
```kcl
turns::HALF_TURN: number(deg) = 180deg

View File

@ -1,11 +1,11 @@
---
title: "turns::QUARTER_TURN"
subtitle: "Constant in std::turns"
excerpt: "A quarter turn, 90 degrees or π/2 radians."
subtitle: "Constant in turns"
excerpt: ""
layout: manual
---
A quarter turn, 90 degrees or π/2 radians.
```kcl
turns::QUARTER_TURN: number(deg) = 90deg

View File

@ -1,11 +1,11 @@
---
title: "turns::THREE_QUARTER_TURN"
subtitle: "Constant in std::turns"
excerpt: "Three quarters of a turn, 270 degrees or 1.5*π radians."
subtitle: "Constant in turns"
excerpt: ""
layout: manual
---
Three quarters of a turn, 270 degrees or 1.5*π radians.
```kcl
turns::THREE_QUARTER_TURN: number(deg) = 270deg

View File

@ -1,11 +1,11 @@
---
title: "turns::ZERO"
subtitle: "Constant in std::turns"
excerpt: "No turn, zero degrees/radians."
subtitle: "Constant in turns"
excerpt: ""
layout: manual
---
No turn, zero degrees/radians.
```kcl
turns::ZERO: number = 0

File diff suppressed because one or more lines are too long

View File

@ -1,6 +1,6 @@
---
title: "abs"
subtitle: "Function in std::math"
subtitle: "Function in math"
excerpt: "Compute the absolute value of a number."
layout: manual
---
@ -17,11 +17,11 @@ abs(@input: number): number
| Name | Type | Description | Required |
|----------|------|-------------|----------|
| `input` | [`number`](/docs/kcl-std/types/std-types-number) | A number. | Yes |
| `input` | [`number`](/docs/kcl-std/types/std-types-number) | A number | Yes |
### Returns
[`number`](/docs/kcl-std/types/std-types-number) - A number.
[`number`](/docs/kcl-std/types/std-types-number) - A number
### Examples

View File

@ -1,6 +1,6 @@
---
title: "acos"
subtitle: "Function in std::math"
subtitle: "Function in math"
excerpt: "Compute the arccosine of a number."
layout: manual
---
@ -17,11 +17,11 @@ acos(@num: number(_)): number(rad)
| Name | Type | Description | Required |
|----------|------|-------------|----------|
| `num` | [`number(_)`](/docs/kcl-std/types/std-types-number) | A number. | Yes |
| `num` | `number(_)` | | Yes |
### Returns
[`number(rad)`](/docs/kcl-std/types/std-types-number) - A number.
`number(rad)`
### Examples

View File

@ -1,6 +1,6 @@
---
title: "asin"
subtitle: "Function in std::math"
subtitle: "Function in math"
excerpt: "Compute the arcsine of a number."
layout: manual
---
@ -17,11 +17,11 @@ asin(@num: number(_)): number(rad)
| Name | Type | Description | Required |
|----------|------|-------------|----------|
| `num` | [`number(_)`](/docs/kcl-std/types/std-types-number) | A number. | Yes |
| `num` | `number(_)` | | Yes |
### Returns
[`number(rad)`](/docs/kcl-std/types/std-types-number) - A number.
`number(rad)`
### Examples

View File

@ -1,6 +1,6 @@
---
title: "atan"
subtitle: "Function in std::math"
subtitle: "Function in math"
excerpt: "Compute the arctangent of a number."
layout: manual
---
@ -17,11 +17,11 @@ Consider using `atan2()` instead for the true inverse of tangent.
| Name | Type | Description | Required |
|----------|------|-------------|----------|
| `num` | [`number(_)`](/docs/kcl-std/types/std-types-number) | A number. | Yes |
| `num` | `number(_)` | | Yes |
### Returns
[`number(rad)`](/docs/kcl-std/types/std-types-number) - A number.
`number(rad)`
### Examples

View File

@ -1,6 +1,6 @@
---
title: "atan2"
subtitle: "Function in std::math"
subtitle: "Function in math"
excerpt: "Compute the four quadrant arctangent of Y and X."
layout: manual
---
@ -20,12 +20,12 @@ atan2(
| Name | Type | Description | Required |
|----------|------|-------------|----------|
| `y` | [`number(Length)`](/docs/kcl-std/types/std-types-number) | A number. | Yes |
| `x` | [`number(Length)`](/docs/kcl-std/types/std-types-number) | A number. | Yes |
| `y` | `number(Length)` | | Yes |
| `x` | `number(Length)` | | Yes |
### Returns
[`number(rad)`](/docs/kcl-std/types/std-types-number) - A number.
`number(rad)`
### Examples

View File

@ -1,6 +1,6 @@
---
title: "ceil"
subtitle: "Function in std::math"
subtitle: "Function in math"
excerpt: "Compute the smallest integer greater than or equal to a number."
layout: manual
---
@ -17,11 +17,11 @@ ceil(@input: number): number
| Name | Type | Description | Required |
|----------|------|-------------|----------|
| `input` | [`number`](/docs/kcl-std/types/std-types-number) | A number. | Yes |
| `input` | [`number`](/docs/kcl-std/types/std-types-number) | A number | Yes |
### Returns
[`number`](/docs/kcl-std/types/std-types-number) - A number.
[`number`](/docs/kcl-std/types/std-types-number) - A number
### Examples

View File

@ -1,6 +1,6 @@
---
title: "cos"
subtitle: "Function in std::math"
subtitle: "Function in math"
excerpt: "Compute the cosine of a number."
layout: manual
---
@ -17,11 +17,11 @@ cos(@num: number(Angle)): number(_)
| Name | Type | Description | Required |
|----------|------|-------------|----------|
| `num` | [`number(Angle)`](/docs/kcl-std/types/std-types-number) | A number. | Yes |
| `num` | `number(Angle)` | | Yes |
### Returns
[`number(_)`](/docs/kcl-std/types/std-types-number) - A number.
`number(_)`
### Examples

View File

@ -1,6 +1,6 @@
---
title: "floor"
subtitle: "Function in std::math"
subtitle: "Function in math"
excerpt: "Compute the largest integer less than or equal to a number."
layout: manual
---
@ -17,11 +17,11 @@ floor(@input: number): number
| Name | Type | Description | Required |
|----------|------|-------------|----------|
| `input` | [`number`](/docs/kcl-std/types/std-types-number) | A number. | Yes |
| `input` | [`number`](/docs/kcl-std/types/std-types-number) | A number | Yes |
### Returns
[`number`](/docs/kcl-std/types/std-types-number) - A number.
[`number`](/docs/kcl-std/types/std-types-number) - A number
### Examples

View File

@ -1,6 +1,6 @@
---
title: "ln"
subtitle: "Function in std::math"
subtitle: "Function in math"
excerpt: "Compute the natural logarithm of the number."
layout: manual
---
@ -17,11 +17,11 @@ ln(@input: number): number
| Name | Type | Description | Required |
|----------|------|-------------|----------|
| `input` | [`number`](/docs/kcl-std/types/std-types-number) | A number. | Yes |
| `input` | [`number`](/docs/kcl-std/types/std-types-number) | A number | Yes |
### Returns
[`number`](/docs/kcl-std/types/std-types-number) - A number.
[`number`](/docs/kcl-std/types/std-types-number) - A number
### Examples

View File

@ -1,6 +1,6 @@
---
title: "log"
subtitle: "Function in std::math"
subtitle: "Function in math"
excerpt: "Compute the logarithm of the number with respect to an arbitrary base."
layout: manual
---
@ -23,11 +23,11 @@ and `log10` can produce more accurate results for base 10.
| Name | Type | Description | Required |
|----------|------|-------------|----------|
| `input` | [`number`](/docs/kcl-std/types/std-types-number) | The number to compute the logarithm of. | Yes |
| `base` | [`number(_)`](/docs/kcl-std/types/std-types-number) | The base of the logarithm. | Yes |
| `base` | `number(_)` | The base of the logarithm. | Yes |
### Returns
[`number`](/docs/kcl-std/types/std-types-number) - A number.
[`number`](/docs/kcl-std/types/std-types-number) - A number
### Examples

View File

@ -1,6 +1,6 @@
---
title: "log10"
subtitle: "Function in std::math"
subtitle: "Function in math"
excerpt: "Compute the base 10 logarithm of the number."
layout: manual
---
@ -17,11 +17,11 @@ log10(@input: number): number
| Name | Type | Description | Required |
|----------|------|-------------|----------|
| `input` | [`number`](/docs/kcl-std/types/std-types-number) | A number. | Yes |
| `input` | [`number`](/docs/kcl-std/types/std-types-number) | A number | Yes |
### Returns
[`number`](/docs/kcl-std/types/std-types-number) - A number.
[`number`](/docs/kcl-std/types/std-types-number) - A number
### Examples

View File

@ -1,6 +1,6 @@
---
title: "log2"
subtitle: "Function in std::math"
subtitle: "Function in math"
excerpt: "Compute the base 2 logarithm of the number."
layout: manual
---
@ -17,11 +17,11 @@ log2(@input: number): number
| Name | Type | Description | Required |
|----------|------|-------------|----------|
| `input` | [`number`](/docs/kcl-std/types/std-types-number) | A number. | Yes |
| `input` | [`number`](/docs/kcl-std/types/std-types-number) | A number | Yes |
### Returns
[`number`](/docs/kcl-std/types/std-types-number) - A number.
[`number`](/docs/kcl-std/types/std-types-number) - A number
### Examples

View File

@ -1,6 +1,6 @@
---
title: "max"
subtitle: "Function in std::math"
subtitle: "Function in math"
excerpt: "Compute the maximum of the given arguments."
layout: manual
---
@ -21,7 +21,7 @@ max(@input: [number; 1+]): number
### Returns
[`number`](/docs/kcl-std/types/std-types-number) - A number.
[`number`](/docs/kcl-std/types/std-types-number) - A number
### Examples

View File

@ -1,6 +1,6 @@
---
title: "min"
subtitle: "Function in std::math"
subtitle: "Function in math"
excerpt: "Compute the minimum of the given arguments."
layout: manual
---
@ -21,7 +21,7 @@ min(@input: [number; 1+]): number
### Returns
[`number`](/docs/kcl-std/types/std-types-number) - A number.
[`number`](/docs/kcl-std/types/std-types-number) - A number
### Examples

View File

@ -1,6 +1,6 @@
---
title: "polar"
subtitle: "Function in std::math"
subtitle: "Function in math"
excerpt: ""
layout: manual
---
@ -21,8 +21,8 @@ cartesian (x/y/z grid) coordinates.
| Name | Type | Description | Required |
|----------|------|-------------|----------|
| `angle` | [`number(rad)`](/docs/kcl-std/types/std-types-number) | A number. | Yes |
| `length` | [`number(Length)`](/docs/kcl-std/types/std-types-number) | A number. | Yes |
| `angle` | `number(rad)` | | Yes |
| `length` | `number(Length)` | | Yes |
### Returns

View File

@ -1,6 +1,6 @@
---
title: "pow"
subtitle: "Function in std::math"
subtitle: "Function in math"
excerpt: "Compute the number to a power."
layout: manual
---
@ -21,11 +21,11 @@ pow(
| Name | Type | Description | Required |
|----------|------|-------------|----------|
| `input` | [`number`](/docs/kcl-std/types/std-types-number) | The number to raise. | Yes |
| `exp` | [`number(_)`](/docs/kcl-std/types/std-types-number) | The power to raise to. | Yes |
| `exp` | `number(_)` | The power to raise to. | Yes |
### Returns
[`number`](/docs/kcl-std/types/std-types-number) - A number.
[`number`](/docs/kcl-std/types/std-types-number) - A number
### Examples

View File

@ -1,6 +1,6 @@
---
title: "rem"
subtitle: "Function in std::math"
subtitle: "Function in math"
excerpt: ""
layout: manual
---
@ -26,7 +26,7 @@ If `num` is negative, the result will be too.
### Returns
[`number`](/docs/kcl-std/types/std-types-number) - A number.
[`number`](/docs/kcl-std/types/std-types-number) - A number
### Examples

View File

@ -1,6 +1,6 @@
---
title: "round"
subtitle: "Function in std::math"
subtitle: "Function in math"
excerpt: "Round a number to the nearest integer."
layout: manual
---
@ -17,11 +17,11 @@ round(@input: number): number
| Name | Type | Description | Required |
|----------|------|-------------|----------|
| `input` | [`number`](/docs/kcl-std/types/std-types-number) | A number. | Yes |
| `input` | [`number`](/docs/kcl-std/types/std-types-number) | A number | Yes |
### Returns
[`number`](/docs/kcl-std/types/std-types-number) - A number.
[`number`](/docs/kcl-std/types/std-types-number) - A number
### Examples

View File

@ -1,6 +1,6 @@
---
title: "sin"
subtitle: "Function in std::math"
subtitle: "Function in math"
excerpt: "Compute the sine of a number."
layout: manual
---
@ -17,11 +17,11 @@ sin(@num: number(Angle)): number(_)
| Name | Type | Description | Required |
|----------|------|-------------|----------|
| `num` | [`number(Angle)`](/docs/kcl-std/types/std-types-number) | A number. | Yes |
| `num` | `number(Angle)` | | Yes |
### Returns
[`number(_)`](/docs/kcl-std/types/std-types-number) - A number.
`number(_)`
### Examples

View File

@ -1,6 +1,6 @@
---
title: "sqrt"
subtitle: "Function in std::math"
subtitle: "Function in math"
excerpt: "Compute the square root of a number."
layout: manual
---
@ -17,11 +17,11 @@ sqrt(@input: number): number
| Name | Type | Description | Required |
|----------|------|-------------|----------|
| `input` | [`number`](/docs/kcl-std/types/std-types-number) | A number. | Yes |
| `input` | [`number`](/docs/kcl-std/types/std-types-number) | A number | Yes |
### Returns
[`number`](/docs/kcl-std/types/std-types-number) - A number.
[`number`](/docs/kcl-std/types/std-types-number) - A number
### Examples

View File

@ -1,6 +1,6 @@
---
title: "tan"
subtitle: "Function in std::math"
subtitle: "Function in math"
excerpt: "Compute the tangent of a number."
layout: manual
---
@ -17,11 +17,11 @@ tan(@num: number(Angle)): number(_)
| Name | Type | Description | Required |
|----------|------|-------------|----------|
| `num` | [`number(Angle)`](/docs/kcl-std/types/std-types-number) | A number. | Yes |
| `num` | `number(Angle)` | | Yes |
### Returns
[`number(_)`](/docs/kcl-std/types/std-types-number) - A number.
`number(_)`
### Examples

View File

@ -1,6 +1,6 @@
---
title: "offsetPlane"
subtitle: "Function in std"
subtitle: "Function in prelude"
excerpt: "Offset a plane by a distance along its normal."
layout: manual
---
@ -22,11 +22,11 @@ plane and 10 units away from it.
| Name | Type | Description | Required |
|----------|------|-------------|----------|
| `plane` | [`Plane`](/docs/kcl-std/types/std-types-Plane) | The plane (e.g. `XY`) which this new plane is created from. | Yes |
| `offset` | [`number(Length)`](/docs/kcl-std/types/std-types-number) | Distance from the standard plane this new plane will be created at. | Yes |
| `offset` | `number(Length)` | Distance from the standard plane this new plane will be created at. | Yes |
### Returns
[`Plane`](/docs/kcl-std/types/std-types-Plane) - An abstract plane.
[`Plane`](/docs/kcl-std/types/std-types-Plane) - A plane.
### Examples

View File

@ -1,6 +1,6 @@
---
title: "circle"
subtitle: "Function in std::sketch"
subtitle: "Function in sketch"
excerpt: ""
layout: manual
---
@ -25,7 +25,7 @@ the provided (x, y) origin point.
|----------|------|-------------|----------|
| `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 |
| `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. | Yes |
| `radius` | `number(Length)` | The radius of the circle. | Yes |
| [`tag`](/docs/kcl-std/types/std-types-tag) | [`tag`](/docs/kcl-std/types/std-types-tag) | Create a new tag which refers to this circle. | No |
### Returns

View File

@ -1,6 +1,6 @@
---
title: "revolve"
subtitle: "Function in std::sketch"
subtitle: "Function in sketch"
excerpt: "Rotate a sketch around some provided axis, creating a solid from its extent."
layout: manual
---
@ -37,16 +37,16 @@ revolved around the same axis.
|----------|------|-------------|----------|
| `sketches` | [`[Sketch; 1+]`](/docs/kcl-std/types/std-types-Sketch) | The sketch or set of sketches that should be revolved | Yes |
| `axis` | [`Axis2d`](/docs/kcl-std/types/std-types-Axis2d) or [`Edge`](/docs/kcl-std/types/std-types-Edge) | Axis of revolution. | Yes |
| `angle` | [`number(Angle)`](/docs/kcl-std/types/std-types-number) | Angle to revolve (in degrees). Default is 360. | No |
| `tolerance` | [`number(Length)`](/docs/kcl-std/types/std-types-number) | Tolerance for the revolve operation. | No |
| `angle` | `number(Angle)` | Angle to revolve (in degrees). Default is 360. | No |
| `tolerance` | `number(Length)` | Tolerance for the revolve operation. | 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 |
| `bidirectionalAngle` | [`number(Angle)`](/docs/kcl-std/types/std-types-number) | If specified, will also revolve in the opposite direction to 'angle' to the specified angle. If 'symmetric' is true, this value is ignored. | No |
| `bidirectionalAngle` | `number(Angle)` | If specified, will also revolve in the opposite direction to 'angle' to the specified angle. If 'symmetric' is true, this value is ignored. | No |
| `tagStart` | [`tag`](/docs/kcl-std/types/std-types-tag) | A named tag for the face at the start of the revolve, i.e. the original sketch. | No |
| `tagEnd` | [`tag`](/docs/kcl-std/types/std-types-tag) | A named tag for the face at the end of the revolve. | No |
### Returns
[`Solid`](/docs/kcl-std/types/std-types-Solid) - A solid is a collection of extruded surfaces.
[`Solid`](/docs/kcl-std/types/std-types-Solid) - A solid is a collection of extrude surfaces.
### Examples

File diff suppressed because one or more lines are too long

View File

@ -1,6 +1,6 @@
---
title: "fillet"
subtitle: "Function in std::solid"
subtitle: "Function in solid"
excerpt: "Blend a transitional edge along a tagged path, smoothing the sharp edge."
layout: manual
---
@ -26,14 +26,14 @@ will smoothly blend the transition.
| Name | Type | Description | Required |
|----------|------|-------------|----------|
| `solid` | [`Solid`](/docs/kcl-std/types/std-types-Solid) | The solid whose edges should be filletted | Yes |
| `radius` | [`number(Length)`](/docs/kcl-std/types/std-types-number) | The radius of the fillet | Yes |
| `radius` | `number(Length)` | The radius of the fillet | Yes |
| `tags` | [`[Edge; 1+]`](/docs/kcl-std/types/std-types-Edge) | The paths you want to fillet | Yes |
| `tolerance` | [`number(Length)`](/docs/kcl-std/types/std-types-number) | The tolerance for this fillet | No |
| `tolerance` | `number(Length)` | The tolerance for this fillet | No |
| [`tag`](/docs/kcl-std/types/std-types-tag) | [`tag`](/docs/kcl-std/types/std-types-tag) | Create a new tag which refers to this fillet | No |
### Returns
[`Solid`](/docs/kcl-std/types/std-types-Solid) - A solid is a collection of extruded surfaces.
[`Solid`](/docs/kcl-std/types/std-types-Solid) - A solid is a collection of extrude surfaces.
### Examples

View File

@ -1,6 +1,6 @@
---
title: "hollow"
subtitle: "Function in std::solid"
subtitle: "Function in solid"
excerpt: "Make the inside of a 3D object hollow."
layout: manual
---
@ -22,11 +22,11 @@ provided thickness remains around the exterior of the shape.
| Name | Type | Description | Required |
|----------|------|-------------|----------|
| `solid` | [`Solid`](/docs/kcl-std/types/std-types-Solid) | Which solid to hollow out | Yes |
| `thickness` | [`number(Length)`](/docs/kcl-std/types/std-types-number) | The thickness of the remaining shell | Yes |
| `thickness` | `number(Length)` | The thickness of the remaining shell | Yes |
### Returns
[`Solid`](/docs/kcl-std/types/std-types-Solid) - A solid is a collection of extruded surfaces.
[`Solid`](/docs/kcl-std/types/std-types-Solid) - A solid is a collection of extrude surfaces.
### Examples

View File

@ -1,6 +1,6 @@
---
title: "shell"
subtitle: "Function in std::solid"
subtitle: "Function in solid"
excerpt: ""
layout: manual
---
@ -23,7 +23,7 @@ provided thickness remains, taking volume starting at the providedface, leaving
| Name | Type | Description | Required |
|----------|------|-------------|----------|
| `solids` | [`[Solid; 1+]`](/docs/kcl-std/types/std-types-Solid) | Which solid (or solids) to shell out | Yes |
| `thickness` | [`number(Length)`](/docs/kcl-std/types/std-types-number) | The thickness of the shell | Yes |
| `thickness` | `number(Length)` | The thickness of the shell | Yes |
| `faces` | [`[tag; 1+]`](/docs/kcl-std/types/std-types-tag) | The faces you want removed | Yes |
### Returns

View File

@ -1,6 +1,6 @@
---
title: "mirror2d"
subtitle: "Function in std::transform"
subtitle: "Function in transform"
excerpt: "Mirror a sketch."
layout: manual
---

View File

@ -1,6 +1,6 @@
---
title: "units::toCentimeters"
subtitle: "Function in std::units"
subtitle: "Function in units"
excerpt: "Convert a number to centimeters from its current units."
layout: manual
---
@ -17,11 +17,11 @@ units::toCentimeters(@num: number(cm)): number(cm)
| Name | Type | Description | Required |
|----------|------|-------------|----------|
| `num` | [`number(cm)`](/docs/kcl-std/types/std-types-number) | A number. | Yes |
| `num` | `number(cm)` | | Yes |
### Returns
[`number(cm)`](/docs/kcl-std/types/std-types-number) - A number.
`number(cm)`

View File

@ -1,6 +1,6 @@
---
title: "units::toDegrees"
subtitle: "Function in std::units"
subtitle: "Function in units"
excerpt: "Converts a number to degrees from its current units."
layout: manual
---
@ -17,11 +17,11 @@ units::toDegrees(@num: number(deg)): number(deg)
| Name | Type | Description | Required |
|----------|------|-------------|----------|
| `num` | [`number(deg)`](/docs/kcl-std/types/std-types-number) | A number. | Yes |
| `num` | `number(deg)` | | Yes |
### Returns
[`number(deg)`](/docs/kcl-std/types/std-types-number) - A number.
`number(deg)`
### Examples

View File

@ -1,6 +1,6 @@
---
title: "units::toFeet"
subtitle: "Function in std::units"
subtitle: "Function in units"
excerpt: "Convert a number to feet from its current units."
layout: manual
---
@ -17,11 +17,11 @@ units::toFeet(@num: number(ft)): number(ft)
| Name | Type | Description | Required |
|----------|------|-------------|----------|
| `num` | [`number(ft)`](/docs/kcl-std/types/std-types-number) | A number. | Yes |
| `num` | `number(ft)` | | Yes |
### Returns
[`number(ft)`](/docs/kcl-std/types/std-types-number) - A number.
`number(ft)`

View File

@ -1,6 +1,6 @@
---
title: "units::toInches"
subtitle: "Function in std::units"
subtitle: "Function in units"
excerpt: "Convert a number to inches from its current units."
layout: manual
---
@ -17,11 +17,11 @@ units::toInches(@num: number(in)): number(in)
| Name | Type | Description | Required |
|----------|------|-------------|----------|
| `num` | [`number(in)`](/docs/kcl-std/types/std-types-number) | A number. | Yes |
| `num` | `number(in)` | | Yes |
### Returns
[`number(in)`](/docs/kcl-std/types/std-types-number) - A number.
`number(in)`

View File

@ -1,6 +1,6 @@
---
title: "units::toMeters"
subtitle: "Function in std::units"
subtitle: "Function in units"
excerpt: "Convert a number to meters from its current units."
layout: manual
---
@ -17,11 +17,11 @@ units::toMeters(@num: number(m)): number(m)
| Name | Type | Description | Required |
|----------|------|-------------|----------|
| `num` | [`number(m)`](/docs/kcl-std/types/std-types-number) | A number. | Yes |
| `num` | `number(m)` | | Yes |
### Returns
[`number(m)`](/docs/kcl-std/types/std-types-number) - A number.
`number(m)`

View File

@ -1,6 +1,6 @@
---
title: "units::toMillimeters"
subtitle: "Function in std::units"
subtitle: "Function in units"
excerpt: "Convert a number to millimeters from its current units."
layout: manual
---
@ -17,11 +17,11 @@ units::toMillimeters(@num: number(mm)): number(mm)
| Name | Type | Description | Required |
|----------|------|-------------|----------|
| `num` | [`number(mm)`](/docs/kcl-std/types/std-types-number) | A number. | Yes |
| `num` | `number(mm)` | | Yes |
### Returns
[`number(mm)`](/docs/kcl-std/types/std-types-number) - A number.
`number(mm)`

View File

@ -1,6 +1,6 @@
---
title: "units::toRadians"
subtitle: "Function in std::units"
subtitle: "Function in units"
excerpt: "Converts a number to radians from its current units."
layout: manual
---
@ -17,11 +17,11 @@ units::toRadians(@num: number(rad)): number(rad)
| Name | Type | Description | Required |
|----------|------|-------------|----------|
| `num` | [`number(rad)`](/docs/kcl-std/types/std-types-number) | A number. | Yes |
| `num` | `number(rad)` | | Yes |
### Returns
[`number(rad)`](/docs/kcl-std/types/std-types-number) - A number.
`number(rad)`
### Examples

View File

@ -1,6 +1,6 @@
---
title: "units::toYards"
subtitle: "Function in std::units"
subtitle: "Function in units"
excerpt: "Converts a number to yards from its current units."
layout: manual
---
@ -17,11 +17,11 @@ units::toYards(@num: number(yd)): number(yd)
| Name | Type | Description | Required |
|----------|------|-------------|----------|
| `num` | [`number(yd)`](/docs/kcl-std/types/std-types-number) | A number. | Yes |
| `num` | `number(yd)` | | Yes |
### Returns
[`number(yd)`](/docs/kcl-std/types/std-types-number) - A number.
`number(yd)`

View File

@ -21,7 +21,7 @@ lastSegX(@sketch: Sketch): number
### Returns
[`number`](/docs/kcl-std/types/std-types-number) - A number.
[`number`](/docs/kcl-std/types/std-types-number) - A number
### Examples

View File

@ -21,7 +21,7 @@ lastSegY(@sketch: Sketch): number
### Returns
[`number`](/docs/kcl-std/types/std-types-number) - A number.
[`number`](/docs/kcl-std/types/std-types-number) - A number
### Examples

View File

@ -25,7 +25,7 @@ legAngX(
### Returns
[`number`](/docs/kcl-std/types/std-types-number) - A number.
[`number`](/docs/kcl-std/types/std-types-number) - A number
### Examples

View File

@ -25,7 +25,7 @@ legAngY(
### Returns
[`number`](/docs/kcl-std/types/std-types-number) - A number.
[`number`](/docs/kcl-std/types/std-types-number) - A number
### Examples

View File

@ -25,7 +25,7 @@ legLen(
### Returns
[`number`](/docs/kcl-std/types/std-types-number) - A number.
[`number`](/docs/kcl-std/types/std-types-number) - A number
### Examples

View File

@ -35,7 +35,7 @@ The sketches need to closed and on the same plane.
### Returns
[`Solid`](/docs/kcl-std/types/std-types-Solid) - A solid is a collection of extruded surfaces.
[`Solid`](/docs/kcl-std/types/std-types-Solid) - A solid is a collection of extrude surfaces.
### Examples

View File

@ -50,7 +50,7 @@ r = 10 // radius
// Call `map`, using an anonymous function instead of a named one.
circles = map(
[1..3],
f = fn(@id) {
f = fn(id) {
return startSketchOn(XY)
|> circle(center = [id * 2 * r, 0], radius = r)
},

View File

@ -1,19 +1,13 @@
---
title: "array"
subtitle: "Module in std"
excerpt: "Functions for manipulating arrays of values. "
excerpt: ""
layout: manual
---
Functions for manipulating arrays of values.
## Functions and constants
* [`map`](/docs/kcl-std/map)
* [`pop`](/docs/kcl-std/pop)
* [`push`](/docs/kcl-std/push)
* [`reduce`](/docs/kcl-std/reduce)

View File

@ -1,11 +1,11 @@
---
title: "math"
subtitle: "Module in std"
excerpt: "Functions for mathematical operations and some useful constants. "
excerpt: ""
layout: manual
---
Functions for mathematical operations and some useful constants.
@ -23,9 +23,6 @@ Functions for mathematical operations and some useful constants.
* [`ceil`](/docs/kcl-std/functions/std-math-ceil)
* [`cos`](/docs/kcl-std/functions/std-math-cos)
* [`floor`](/docs/kcl-std/functions/std-math-floor)
* [`legAngX`](/docs/kcl-std/legAngX)
* [`legAngY`](/docs/kcl-std/legAngY)
* [`legLen`](/docs/kcl-std/legLen)
* [`ln`](/docs/kcl-std/functions/std-math-ln)
* [`log`](/docs/kcl-std/functions/std-math-log)
* [`log10`](/docs/kcl-std/functions/std-math-log10)

View File

@ -1,55 +1,17 @@
---
title: "sketch"
subtitle: "Module in std"
excerpt: "Sketching is the foundational activity for most KCL programs. A sketch is a two-dimensional drawing made from paths or shapes. A sketch is always drawn on a surface (either an abstract plane of a face of a solid). A sketch can be made into a solid by extruding it (or revolving, etc.). "
excerpt: ""
layout: manual
---
Sketching is the foundational activity for most KCL programs. A sketch is a two-dimensional drawing made from paths or shapes. A sketch is always drawn on a surface (either an abstract plane of a face of a solid). A sketch can be made into a solid by extruding it (or revolving, etc.).
This module contains functions for creating and manipulating sketches, and making them into solids.
## Functions and constants
* [`angledLine`](/docs/kcl-std/angledLine)
* [`angledLineThatIntersects`](/docs/kcl-std/angledLineThatIntersects)
* [`arc`](/docs/kcl-std/arc)
* [`bezierCurve`](/docs/kcl-std/bezierCurve)
* [`circle`](/docs/kcl-std/functions/std-sketch-circle)
* [`circleThreePoint`](/docs/kcl-std/circleThreePoint)
* [`close`](/docs/kcl-std/close)
* [`extrude`](/docs/kcl-std/extrude)
* [`getCommonEdge`](/docs/kcl-std/getCommonEdge)
* [`getNextAdjacentEdge`](/docs/kcl-std/getNextAdjacentEdge)
* [`getOppositeEdge`](/docs/kcl-std/getOppositeEdge)
* [`getPreviousAdjacentEdge`](/docs/kcl-std/getPreviousAdjacentEdge)
* [`involuteCircular`](/docs/kcl-std/involuteCircular)
* [`lastSegX`](/docs/kcl-std/lastSegX)
* [`lastSegY`](/docs/kcl-std/lastSegY)
* [`line`](/docs/kcl-std/line)
* [`loft`](/docs/kcl-std/loft)
* [`patternCircular2d`](/docs/kcl-std/patternCircular2d)
* [`patternTransform2d`](/docs/kcl-std/patternTransform2d)
* [`polygon`](/docs/kcl-std/polygon)
* [`profileStart`](/docs/kcl-std/profileStart)
* [`profileStartX`](/docs/kcl-std/profileStartX)
* [`profileStartY`](/docs/kcl-std/profileStartY)
* [`revolve`](/docs/kcl-std/functions/std-sketch-revolve)
* [`segAng`](/docs/kcl-std/segAng)
* [`segEnd`](/docs/kcl-std/segEnd)
* [`segEndX`](/docs/kcl-std/segEndX)
* [`segEndY`](/docs/kcl-std/segEndY)
* [`segLen`](/docs/kcl-std/segLen)
* [`segStart`](/docs/kcl-std/segStart)
* [`segStartX`](/docs/kcl-std/segStartX)
* [`segStartY`](/docs/kcl-std/segStartY)
* [`startProfile`](/docs/kcl-std/startProfile)
* [`startSketchOn`](/docs/kcl-std/startSketchOn)
* [`subtract2d`](/docs/kcl-std/subtract2d)
* [`sweep`](/docs/kcl-std/sweep)
* [`tangentToEnd`](/docs/kcl-std/tangentToEnd)
* [`tangentialArc`](/docs/kcl-std/tangentialArc)
* [`xLine`](/docs/kcl-std/xLine)
* [`yLine`](/docs/kcl-std/yLine)

View File

@ -1,11 +1,11 @@
---
title: "solid"
subtitle: "Module in std"
excerpt: "This module contains functions for modifying solids, e.g., by adding a fillet or chamfer, or removing part of a solid. "
excerpt: ""
layout: manual
---
This module contains functions for modifying solids, e.g., by adding a fillet or chamfer, or removing part of a solid.
@ -15,11 +15,5 @@ This module contains functions for modifying solids, e.g., by adding a fillet or
* [`chamfer`](/docs/kcl-std/functions/std-solid-chamfer)
* [`fillet`](/docs/kcl-std/functions/std-solid-fillet)
* [`hollow`](/docs/kcl-std/functions/std-solid-hollow)
* [`intersect`](/docs/kcl-std/intersect)
* [`patternCircular3d`](/docs/kcl-std/patternCircular3d)
* [`patternLinear3d`](/docs/kcl-std/patternLinear3d)
* [`patternTransform`](/docs/kcl-std/patternTransform)
* [`shell`](/docs/kcl-std/functions/std-solid-shell)
* [`subtract`](/docs/kcl-std/subtract)
* [`union`](/docs/kcl-std/union)

View File

@ -1,11 +1,11 @@
---
title: "transform"
subtitle: "Module in std"
excerpt: "This module contains functions for transforming sketches and solids. "
excerpt: ""
layout: manual
---
This module contains functions for transforming sketches and solids.
@ -13,7 +13,4 @@ This module contains functions for transforming sketches and solids.
## Functions and constants
* [`mirror2d`](/docs/kcl-std/functions/std-transform-mirror2d)
* [`rotate`](/docs/kcl-std/rotate)
* [`scale`](/docs/kcl-std/scale)
* [`translate`](/docs/kcl-std/translate)

View File

@ -1,11 +1,11 @@
---
title: "turns"
subtitle: "Module in std"
excerpt: "This module contains a few handy constants for defining turns. "
excerpt: ""
layout: manual
---
This module contains a few handy constants for defining turns.

View File

@ -1,13 +1,13 @@
---
title: "types"
subtitle: "Module in std"
excerpt: "KCL types. This module contains fundamental types like `number`, `string`, `Solid`, and `Sketch`. "
excerpt: ""
layout: manual
---
KCL types. This module contains fundamental types like `number`, `string`, `Solid`, and `Sketch`.
Types can (optionally) be used to describe a function's arguments and returned value. They are checked when a program runs and can help avoid errors. They are also useful to help document what a function does.

View File

@ -7,9 +7,7 @@ layout: manual
Functions for converting numbers to different units.
All numbers in KCL include units, e.g., the number `42` is always '42 mm' or '42 degrees', etc. it is never just '42'. For more information, see [numeric types](/docs/kcl-lang/numeric).
Note that you only need to explicitly convert the units of a number if you need a specific unit for your own calculations. When calling a function, KCL will convert a number to the required units automatically (where possible, and give an error or warning if it's not possible).
## Functions and constants

View File

@ -1,6 +1,6 @@
---
title: "std"
subtitle: "Module in std::"
title: "prelude"
subtitle: "Module in "
excerpt: "The KCL standard library "
layout: manual
---
@ -9,8 +9,6 @@ The KCL standard library
Contains frequently used constants, functions for interacting with the KittyCAD servers to create sketches and geometry, and utility functions.
The standard library is organised into modules (listed below), but most things are always available in KCL programs.
## Modules
* [`array`](/docs/kcl-std/modules/std-array)
@ -32,11 +30,6 @@ The standard library is organised into modules (listed below), but most things a
* [`Y`](/docs/kcl-std/consts/std-Y)
* [`YZ`](/docs/kcl-std/consts/std-YZ)
* [`Z`](/docs/kcl-std/consts/std-Z)
* [`appearance`](/docs/kcl-std/appearance)
* [`assert`](/docs/kcl-std/assert)
* [`assertIs`](/docs/kcl-std/assertIs)
* [`clone`](/docs/kcl-std/clone)
* [`helix`](/docs/kcl-std/functions/std-helix)
* [`offsetPlane`](/docs/kcl-std/functions/std-offsetPlane)
* [`patternLinear2d`](/docs/kcl-std/patternLinear2d)

View File

@ -1,11 +1,11 @@
---
title: "patternCircular2d"
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: "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 orentation of the solid with respect to the center of the circle is maintained."
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.
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 orentation of the solid with respect to the center of the circle is maintained.
```kcl
patternCircular2d(

View File

@ -1,11 +1,11 @@
---
title: "patternCircular3d"
subtitle: "Function in std::solid"
excerpt: "Repeat a 3-dimensional solid 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: "Repeat a 3-dimensional solid 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 orentation of the solid with respect to the center of the circle is maintained."
layout: manual
---
Repeat a 3-dimensional solid 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.
Repeat a 3-dimensional solid 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 orentation of the solid with respect to the center of the circle is maintained.
```kcl
patternCircular3d(

View File

@ -21,7 +21,7 @@ profileStartX(@profile: Sketch): number
### Returns
[`number`](/docs/kcl-std/types/std-types-number) - A number.
[`number`](/docs/kcl-std/types/std-types-number) - A number
### Examples

View File

@ -21,7 +21,7 @@ profileStartY(@profile: Sketch): number
### Returns
[`number`](/docs/kcl-std/types/std-types-number) - A number.
[`number`](/docs/kcl-std/types/std-types-number) - A number
### Examples

View File

@ -34,8 +34,8 @@ reduce(
```kcl
// This function adds two numbers.
fn add(@a, accum) {
return a + accum
fn add(a, b) {
return a + b
}
// This function adds an array of numbers.
@ -49,7 +49,7 @@ fn sum(@arr) {
fn sum(arr):
sumSoFar = 0
for i in arr:
sumSoFar = add(i, sumSoFar)
sumSoFar = add(sumSoFar, i)
return sumSoFar */
// We use `assert` to check that our `sum` function gives the
@ -72,8 +72,8 @@ arr = [1, 2, 3]
sum = reduce(
arr,
initial = 0,
f = fn(@i, accum) {
return i + accum
f = fn(i, result_so_far) {
return i + result_so_far
},
)
@ -105,11 +105,11 @@ fn decagon(@radius) {
fullDecagon = reduce(
[1..10],
initial = startOfDecagonSketch,
f = fn(@i, accum) {
f = fn(i, partialDecagon) {
// Draw one edge of the decagon.
x = cos(stepAngle * i) * radius
y = sin(stepAngle * i) * radius
return line(accum, end = [x, y])
return line(partialDecagon, end = [x, y])
},
)

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

Some files were not shown because too many files have changed in this diff Show More