### Setup for Unit and Integration Tests Source: https://github.com/kittycad/modeling-app/blob/main/CONTRIBUTING.md Commands to set up the project for running unit and integration tests. This includes installing dependencies, building WebAssembly modules, and starting the application. ```bash npm ``` ```bash npm run build:wasm ``` ```bash npm start ``` -------------------------------- ### Start a profile and create a square Source: https://github.com/kittycad/modeling-app/blob/main/docs/kcl-std/functions/std-sketch-startProfile.md This example demonstrates starting a profile on the XZ plane, drawing a square, and then extruding it. Note that startProfile is deprecated. ```kcl exampleSketch = startSketchOn(XZ) |> startProfile(at = [0, 0]) |> line(end = [10, 0]) |> line(end = [0, 10]) |> line(end = [-10, 0]) |> close() example = extrude(exampleSketch, length = 5) ``` -------------------------------- ### Start a profile with negative coordinates Source: https://github.com/kittycad/modeling-app/blob/main/docs/kcl-std/functions/std-sketch-startProfile.md This example demonstrates starting a profile on the negative XZ plane at a specific negative coordinate, drawing a square, and extruding it. Remember that startProfile is deprecated. ```kcl exampleSketch = startSketchOn(-XZ) |> startProfile(at = [-10, 23]) |> line(end = [10, 0]) |> line(end = [0, 10]) |> line(end = [-10, 0]) |> close() example = extrude(exampleSketch, length = 5) ``` -------------------------------- ### Start Development Server with Electron Source: https://github.com/kittycad/modeling-app/blob/main/CONTRIBUTING.md Starts the desktop application in development mode with hot-reloading. Ensure `npm install` and `npm run build:wasm` have been completed first. ```bash npm run tron:start ``` -------------------------------- ### Starting multiple profiles on the same sketch plane Source: https://github.com/kittycad/modeling-app/blob/main/docs/kcl-std/functions/std-sketch-startProfile.md This example illustrates how to create a sketch plane and then start two separate profiles on it using the deprecated startProfile function, each defining a square. The `at` argument specifies the starting point for each profile. ```kcl // Create a sketch plane. mySketch = startSketchOn(XY) // Start a profile on the sketch plane. squareProfile1 = startProfile(mySketch, at = [0, 0]) |> line(end = [10, 0]) |> line(end = [0, 10]) |> line(end = [-10, 0]) |> close() // Start another profile on the same sketch plane. squareProfile2 = startProfile(mySketch, at = [20, 0]) |> line(end = [10, 0]) |> line(end = [0, 10]) |> line(end = [-10, 0]) |> close() ``` -------------------------------- ### Development Setup for kcl-lsp Source: https://github.com/kittycad/modeling-app/blob/main/rust/kcl-language-server/README.md Commands to set up the development environment for kcl-lsp. This includes installing npm dependencies, building the project with Cargo, and opening the project in VSCode. ```bash $ npm install $ cargo build $ code . ``` -------------------------------- ### Start a profile on a negative XZ plane Source: https://github.com/kittycad/modeling-app/blob/main/docs/kcl-std/functions/std-sketch-startProfile.md This example shows how to start a profile on the negative XZ plane, draw a square, and extrude it. The startProfile function is deprecated. ```kcl exampleSketch = startSketchOn(-XZ) |> startProfile(at = [10, 10]) |> line(end = [10, 0]) |> line(end = [0, 10]) |> line(end = [-10, 0]) |> close() example = extrude(exampleSketch, length = 5) ``` -------------------------------- ### Slice Example 3: Using negative start index Source: https://github.com/kittycad/modeling-app/blob/main/docs/kcl-std/functions/std-array-slice.md Shows how to slice an array using a negative index for the start. ```APIDOC ## Example: Slice with negative start index ### Code ```kcl s = slice([1, 2, 3, 4, 5], start = -2) assert(s[0], isEqualTo = 4) assert(s[1], isEqualTo = 5) assert(count(s), isEqualTo = 2) ``` ``` -------------------------------- ### Example Usage of Snapshot and Export Command Source: https://github.com/kittycad/modeling-app/blob/main/public/kcl-samples/README.md This is an example of how to use the 'overwrite-sim-test-sample' command with a specific sample name. ```bash just overwrite-sim-test-sample angle-gauge ``` -------------------------------- ### Extracting Profile Start Point in KCL Source: https://github.com/kittycad/modeling-app/blob/main/docs/kcl-std/functions/std-sketch-profileStart.md This example demonstrates how to use the profileStart function to get the origin of a sketch's profile. The profile is defined using a series of sketch operations, and profileStart is used to close the sketch by connecting the last segment to the starting point. ```kcl sketch001 = startSketchOn(XY) |> startProfile(at = [5, 2]) |> angledLine(angle = 120deg, length = 50, tag = $seg01) |> angledLine(angle = segAng(seg01) + 120deg, length = 50) |> line(end = profileStart(%)) |> close() |> extrude(length = 20) ``` -------------------------------- ### Example Usage of segStart in Cylinder Function Source: https://github.com/kittycad/modeling-app/blob/main/docs/kcl-std/functions/std-sketch-segStart.md Demonstrates how segStart can be used within a function to define the center of a circle based on the start of a tagged line segment. This example constructs a cylinder using the result. ```kcl w = 15 cube = startSketchOn(XY) |> startProfile(at = [0, 0]) |> line(end = [w, 0], tag = $line1) |> line(end = [0, w], tag = $line2) |> line(end = [-w, 0], tag = $line3) |> line(end = [0, -w], tag = $line4) |> close() |> extrude(length = 5) fn cylinder(radius, tag) { return startSketchOn(XY) |> startProfile(at = [0, 0]) |> circle(radius = radius, center = segStart(tag)) |> extrude(length = radius) } cylinder(radius = 1, tag = line1) cylinder(radius = 2, tag = line2) cylinder(radius = 3, tag = line3) cylinder(radius = 4, tag = line4) ``` -------------------------------- ### Install Project Dependencies Source: https://github.com/kittycad/modeling-app/blob/main/CONTRIBUTING.md Installs all necessary Node.js dependencies for the project. This should be run after installing system dependencies. ```bash npm install ``` -------------------------------- ### Install Rust Toolchain Source: https://github.com/kittycad/modeling-app/blob/main/CONTRIBUTING.md Installs the Rust toolchain required for the project. Use the appropriate command for your operating system. ```bash # macOS/Linux npm run install:rust # Windows npm run install:rust:windows ``` -------------------------------- ### Example Usage of solver::diameter Source: https://github.com/kittycad/modeling-app/blob/main/docs/kcl-std/functions/std-solver-diameter.md This example demonstrates how to use the diameter constraint within a sketch to define a circular profile. The diameter of the guide circle is set to 4mm, and then a rectangular profile is drawn and constrained to the sketch. ```kcl profile = sketch(on = XY) { guide = circle(start = [var 2mm, var 0mm], center = [var 0mm, var 0mm], construction = true) diameter(guide) == 4mm edge1 = line(start = [var -3mm, var -2mm], end = [var 3mm, var -2mm]) edge2 = line(start = [var 3mm, var -2mm], end = [var 3mm, var 2mm]) edge3 = line(start = [var 3mm, var 2mm], end = [var -3mm, var 2mm]) edge4 = line(start = [var -3mm, var 2mm], end = [var -3mm, var -2mm]) coincident([edge1.end, edge2.start]) coincident([edge2.end, edge3.start]) coincident([edge3.end, edge4.start]) coincident([edge4.end, edge1.start]) } solid = extrude(region(point = [0mm, 0mm], sketch = profile), length = 2) ``` -------------------------------- ### Install System Dependencies with asdf Source: https://github.com/kittycad/modeling-app/blob/main/CONTRIBUTING.md Installs and configures system dependencies using asdf version manager. Ensure asdf is installed before running. ```bash asdf plugin add just asdf plugin add nodejs asdf plugin add python asdf install ``` -------------------------------- ### Example: Cutting a Hole with hole::holeAt (with units) Source: https://github.com/kittycad/modeling-app/blob/main/docs/kcl-std/functions/std-hole-holeAt.md This example shows how to cut a counterbored hole using hole::holeAt, similar to the previous example, but utilizes explicit units (mm) for dimensions. It models a cube using a detailed sketch definition. ```kcl // Model a cube. cubeProfile = sketch(on = XY) { line1 = line(start = [var -1.5mm, var -1.5mm], end = [var 1.5mm, var -1.5mm]) line2 = line(start = [var 1.5mm, var -1.5mm], end = [var 1.5mm, var 1.5mm]) line3 = line(start = [var 1.5mm, var 1.5mm], end = [var -1.5mm, var 1.5mm]) line4 = line(start = [var -1.5mm, var 1.5mm], end = [var -1.5mm, var -1.5mm]) coincident([line1.end, line2.start]) coincident([line2.end, line3.start]) coincident([line3.end, line4.start]) coincident([line4.end, line1.start]) parallel([line2, line4]) parallel([line3, line1]) perpendicular([line1, line2]) horizontal(line3) equalLength([line2, line3]) distance([line2.start, line2.end]) == 3mm } cube1 = extrude(region(point = [0mm, 0mm], sketch = cubeProfile), length = 3mm) // Define a custom plane, into which a hole will be cut. customPlane = { origin = { x = 1.5, y = -1.5, z = 3 }, xAxis = { x = -0.5, y = -0.5, z = 0 }, yAxis = { x = 0, y = 0.5, z = 0.5 } } // Cut the hole through the cube, into the plane. hole::holeAt( [cube1], plane = customPlane, holeBottom = hole::flat(), holeBody = hole::blind(depth = 2, diameter = 1), holeType = hole::counterbore(diameter = 1.4, depth = 1), ) ``` -------------------------------- ### Example 4: Opening a box by deleting the top face Source: https://github.com/kittycad/modeling-app/blob/main/docs/kcl-std/functions/std-solid-deleteFace.md This example demonstrates how to create an open box by deleting the top face of a solid box. ```APIDOC ## Example: Opening a box by deleting the top face ```kcl boxProfile = sketch(on = XY) { edge1 = line(start = [var 0mm, var 0mm], end = [var 5mm, var 0mm]) edge2 = line(start = [var 5mm, var 0mm], end = [var 5mm, var 5mm]) edge3 = line(start = [var 5mm, var 5mm], end = [var 0mm, var 5mm]) edge4 = line(start = [var 0mm, var 5mm], end = [var 0mm, var 0mm]) coincident([edge1.end, edge2.start]) coincident([edge2.end, edge3.start]) coincident([edge3.end, edge4.start]) coincident([edge4.end, edge1.start]) horizontal(edge1) vertical(edge2) horizontal(edge3) vertical(edge4) } box = extrude(region(point = [2mm, 2mm], sketch = boxProfile), length = 4mm, tagEnd = $top) openBox = deleteFace(box, faces = [top]) ``` ``` -------------------------------- ### Example 1: Delete faces using tags Source: https://github.com/kittycad/modeling-app/blob/main/docs/kcl-std/functions/std-solid-deleteFace.md This example demonstrates how to use deleteFace by specifying faces using their tags. ```APIDOC ## Example: Delete faces using tags ```kcl // Make an extruded triangle. startSketchOn(XY) |> startProfile(at = [0, 15]) |> xLine(length = 10, tag = $a) |> yLine(length = 8) |> close() |> extrude(length = 2) // Delete some faces. |> deleteFace(faces = [a, END]) ``` ``` -------------------------------- ### log10 Usage Example Source: https://github.com/kittycad/modeling-app/blob/main/docs/kcl-std/functions/std-math-log10.md An example demonstrating the usage of the log10 function within a KCL sketch. ```APIDOC ## Example Usage ```kcl exampleSketch = startSketchOn(XZ) |> startProfile(at = [0, 0]) |> line(end = [log10(100), 0]) |> line(end = [5, 8]) |> line(end = [-10, 0]) |> close() example = extrude(exampleSketch, length = 5) ``` ``` -------------------------------- ### Install FUSE on Ubuntu Source: https://github.com/kittycad/modeling-app/blob/main/INSTALL.md Installs the FUSE library required for AppImage format on Ubuntu. Ensure `zlib1g-dev` is also installed on ARM architectures if needed. ```bash sudo apt update sudo apt install libfuse2 ``` -------------------------------- ### Install Playwright Browser Binaries Source: https://github.com/kittycad/modeling-app/blob/main/CONTRIBUTING.md Installs the necessary browser binaries for Playwright, specifically Chromium, for end-to-end testing on desktop. ```bash npm run playwright -- install chromium ``` -------------------------------- ### Creating an Open Box and Shelling It Source: https://github.com/kittycad/modeling-app/blob/main/docs/kcl-std/functions/std-solid-shell.md This example shows how to create a solid box using a sketched profile and then apply the `shell` function to make it an open box with a specified thickness. The `shell` function is applied to the `END` face. ```kcl boxProfile = sketch(on = XY) { edge1 = line(start = [var 0mm, var 0mm], end = [var 6mm, var 0mm]) edge2 = line(start = [var 6mm, var 0mm], end = [var 6mm, var 4mm]) edge3 = line(start = [var 6mm, var 4mm], end = [var 0mm, var 4mm]) edge4 = line(start = [var 0mm, var 4mm], end = [var 0mm, var 0mm]) coincident([edge1.end, edge2.start]) coincident([edge2.end, edge3.start]) coincident([edge3.end, edge4.start]) coincident([edge4.end, edge1.start]) horizontal(edge1) vertical(edge2) horizontal(edge3) vertical(edge4) } box = extrude(region(point = [3mm, 2mm], sketch = boxProfile), length = 4mm) openBox = shell(box, faces = [END], thickness = 0.5mm) ``` -------------------------------- ### Slice Example 1: Specifying start and end Source: https://github.com/kittycad/modeling-app/blob/main/docs/kcl-std/functions/std-array-slice.md Demonstrates slicing an array with explicit start and end indices. ```APIDOC ## Example: Slice with start and end ### Code ```kcl s = slice([1, 2, 3, 4, 5], start = 1, end = 3) assert(s[0], isEqualTo = 2) assert(s[1], isEqualTo = 3) assert(count(s), isEqualTo = 2) ``` ``` -------------------------------- ### faceOf Example 1 Source: https://github.com/kittycad/modeling-app/blob/main/docs/kcl-std/functions/std-sketch-faceOf.md This example demonstrates how to use the faceOf function to get a specific face from an extruded triangle. ```APIDOC ## Example 1: Get a side face from an extruded triangle ### Code ```kcl triangle = startSketchOn(XY) |> startProfile(at = [0, 0]) |> line(end = [2, 0]) |> line(end = [0, 2], tag = $side) |> line(end = [-2, -2]) |> close() |> extrude(length = 2) // Get the face of the triangle's side face. sideFace = faceOf(triangle, face = side) // Create a new sketch, on the triangle's side face. // sketch(on = sideFace) {} ``` ``` -------------------------------- ### faceOf Example 2 Source: https://github.com/kittycad/modeling-app/blob/main/docs/kcl-std/functions/std-sketch-faceOf.md This example shows how to use faceOf with a tagged region from a sketch to get a face from an extruded prism. ```APIDOC ## Example 2: Get a face using a tagged region from a prism ### Code ```kcl triangle = sketch(on = XY) { line1 = line(start = [var -0.05mm, var -0.01mm], end = [var 3.88mm, var 0.81mm]) line2 = line(start = [var 3.88mm, var 0.81mm], end = [var 0.92mm, var 4.67mm]) coincident([line1.end, line2.start]) line3 = line(start = [var 0.92mm, var 4.67mm], end = [var -0.03mm, var -0.04mm]) coincident([line2.end, line3.start]) coincident([line1.start, line3.end]) horizontal(line1) equalLength([line2, line3]) } triangleRegion = region(point = [1.86mm, 3.82mm], sketch = triangle) prism = extrude(triangleRegion, length = 2) face001 = faceOf(prism, face = triangleRegion.tags.line1) ``` ``` -------------------------------- ### Example: Sketching a profile with perpendicular constraints Source: https://github.com/kittycad/modeling-app/blob/main/docs/kcl-std/functions/std-solver-perpendicular.md This example demonstrates how to create a sketch with four edges and then apply a perpendicular constraint between the first two edges using solver::perpendicular. The resulting profile is then used to create a solid. ```kcl profile = sketch(on = XY) { edge1 = line(start = [var 0mm, var 0mm], end = [var 4mm, var 0mm]) edge2 = line(start = [var 4mm, var 0mm], end = [var 4mm, var 3mm]) edge3 = line(start = [var 4mm, var 3mm], end = [var 0mm, var 3mm]) edge4 = line(start = [var 0mm, var 3mm], end = [var 0mm, var 0mm]) coincident([edge1.end, edge2.start]) coincident([edge2.end, edge3.start]) coincident([edge3.end, edge4.start]) coincident([edge4.end, edge1.start]) perpendicular([edge1, edge2]) } solid = extrude(region(point = [2mm, 1mm], sketch = profile), length = 2) ``` -------------------------------- ### Shelling by Removing the Start Face Source: https://github.com/kittycad/modeling-app/blob/main/docs/kcl-std/functions/std-solid-shell.md This example demonstrates how to use the shell function to remove the start face of an extruded solid. The faces parameter accepts constants like START to specify which face to remove. ```kcl // Remove the start face for the extrusion. firstSketch = startSketchOn(-XZ) |> startProfile(at = [-12, 12]) |> line(end = [24, 0]) |> line(end = [0, -24]) |> line(end = [-24, 0]) |> close() |> extrude(length = 6) // Remove the start face for the extrusion. shell(firstSketch, faces = [START], thickness = 0.25) ``` -------------------------------- ### Example: Creating a Cube and Adding a Flat-Bottomed Hole Source: https://github.com/kittycad/modeling-app/blob/main/docs/kcl-std/functions/std-hole-flat.md This example demonstrates how to create a cube and then add a hole with a flat bottom using `hole::flat()` in combination with `hole::hole` and `hole::blind`. ```kcl cubeLen = 20 bigCube = startSketchOn(XY) |> startProfile(at = [-cubeLen / 2, -cubeLen / 2 + 10]) |> line(end = [cubeLen, 0], tag = $a) |> line(end = [0, cubeLen], tag = $b) |> line(end = [-cubeLen, 0], tag = $c) |> line(end = [0, -cubeLen], tag = $d) |> close() |> extrude(length = cubeLen, symmetric = true) // Add a hole with a flat bottom. bigCube |> hole::hole( face = a, cutAt = [0, 0], holeBottom = hole::flat(), holeBody = hole::blind(depth = 2, diameter = 8), holeType = hole::simple(), ) ``` -------------------------------- ### Get Line Segment Start Point Source: https://github.com/kittycad/modeling-app/blob/main/docs/kcl-std/functions/std-sketch-segStart.md Use segStart to retrieve the starting point of a tagged line segment. This is often used in subsequent geometric operations. ```kcl segStart(@tag: TaggedEdge): Point2d ``` -------------------------------- ### Migration Script Example Source: https://github.com/kittycad/modeling-app/blob/main/rust/kcl-lib/src/bin/README.md This bash script snippet demonstrates how to use the transpile binary to convert KCL files, likely for migrating samples to a new Sketch version. ```bash "$transpile_bin" convert "public/kcl-samples/$file" > "$out_file" ``` -------------------------------- ### Run Storybook for UI Components Source: https://github.com/kittycad/modeling-app/blob/main/packages/ui-components/README.md Launches the Storybook environment for the `@kittycad/ui-components` package. Use this to view and interact with individual components in isolation. ```bash npm run storybook -w @kittycad/ui-components ``` -------------------------------- ### Create a Solid Cube from Surfaces using split Source: https://github.com/kittycad/modeling-app/blob/main/docs/kcl-std/functions/std-solid-split.md This example demonstrates creating a solid cube from six square surfaces by using the split function with merge enabled. It then applies an appearance to the resulting solid. ```kcl sideLen = 4 // Helper function to make a square surface body. fn square(@plane, offset, y) { at = if y { [-offset, 0] } else { [0, offset] } return startSketchOn(plane) |> startProfile(at) |> if y { yLine(length = sideLen) } else { xLine(length = sideLen) } |> extrude( length = if y { -sideLen } else { sideLen }, bodyType = SURFACE, ) } // Make a cube polysurface from 6 squares. cube = [ square(XY, offset = 0, y = false), square(XZ, offset = 0, y = true) |> flipSurface(), square(YZ, offset = 0, y = false), square(XY, offset = sideLen, y = false), square(XZ, offset = -sideLen, y = true), square(YZ, offset = sideLen, y = false) ] // Via split + merge, create a solid cube from the 6 square surfaces (faces of the cube). cubeSolid = split(cube, merge = true) // To prove it's solid, we can set the whole cube's appearance. appearance( cubeSolid, color = "#da4333", roughness = 50, metalness = 90, ) ``` -------------------------------- ### Build Storybook for UI Components Source: https://github.com/kittycad/modeling-app/blob/main/packages/ui-components/README.md Builds a static version of the Storybook documentation for the `@kittycad/ui-components` package. This is useful for deployment or sharing. ```bash npm run build-storybook -w @kittycad/ui-components ``` -------------------------------- ### Build Desktop App (Production) Source: https://github.com/kittycad/modeling-app/blob/main/CONTRIBUTING.md Builds the desktop application using electron-builder, targeting production infrastructure. Artifacts are placed in the 'out' directory. ```bash npm run tronb:package:prod ``` -------------------------------- ### Example using relative control points Source: https://github.com/kittycad/modeling-app/blob/main/docs/kcl-std/functions/std-sketch-bezierCurve.md This example demonstrates drawing a Bezier curve using relative control points. It starts a sketch, draws a line, then the Bezier curve, another line, and closes the profile before extruding. ```kcl // Example using relative control points. exampleSketch = startSketchOn(XZ) |> startProfile(at = [0, 0]) |> line(end = [0, 10]) |> bezierCurve(control1 = [5, 0], control2 = [5, 10], end = [10, 10]) |> line(endAbsolute = [10, 0]) |> close() example = extrude(exampleSketch, length = 10) ``` -------------------------------- ### Sketch and Extrude with Tagging Source: https://github.com/kittycad/modeling-app/blob/main/docs/kcl-lang/types.md This example demonstrates defining a sketch with named lines, creating a region from the sketch, extruding the region, and tagging the end face. It also shows how to apply a fillet using the tagged face. ```kcl @settings(kclVersion = 2.0) sketch001 = sketch(on = XZ) { line1 = line(start = [var -2.17mm, var -0.91mm], end = [var 3.01mm, var -1.57mm]) line2 = line(start = [var 3.01mm, var -1.57mm], end = [var 3.13mm, var 3.12mm]) coincident([line1.end, line2.start]) line3 = line(start = [var 3.13mm, var 3.12mm], end = [var -2.26mm, var 2.4mm]) coincident([line2.end, line3.start]) line4 = line(start = [var -2.26mm, var 2.4mm], end = [var -2.17mm, var -0.91mm]) coincident([line3.end, line4.start]) coincident([line4.end, line1.start]) } region001 = region(point = [0.4203mm, -1.2375mm], sketch = sketch001) extrude001 = extrude(region001, length = 5, tagEnd = $capEnd001) fillet001 = fillet(extrude001, tags = getCommonEdge(faces = [region001.tags.line4, capEnd001]), radius = 1) ``` -------------------------------- ### Extracting Profile Start Y-Coordinate - KCL Source: https://github.com/kittycad/modeling-app/blob/main/docs/kcl-std/functions/std-sketch-profileStartY.md Use `profileStartY` to get the y-coordinate of a sketch's profile start. This is often used in subsequent drawing operations to align or position new elements relative to the existing profile. ```kcl sketch001 = startSketchOn(XY) |> startProfile(at = [5, 2]) |> angledLine(angle = -60deg, length = 14) |> angledLine(angle = 30deg, endAbsoluteY = profileStartY(%)) ``` -------------------------------- ### Correct Multiple Profiles Example Source: https://github.com/kittycad/modeling-app/blob/main/docs/kcl-std/functions/std-sketch-startSketchOn.md This example shows the correct method for creating multiple profiles in a sketch. Each profile is defined in a separate pipeline, and then an array of these profiles is used for operations like extrusion. ```js sketch1 = startSketchOn(XY) squareProfile1 = startProfile(sketch1, at = [0, 0]) |> line(end = [10, 0]) |> line(end = [0, 10]) |> line(end = [-10, 0]) |> close() squareProfile2 = startProfile(sketch1, at = [20, 0]) |> line(end = [10, 0]) |> line(end = [0, 10]) |> line(end = [-10, 0]) |> close() twoCubes = extrude([squareProfile1, squareProfile2], length = 10) ``` -------------------------------- ### Example Usage of angledLine Source: https://github.com/kittycad/modeling-app/blob/main/docs/kcl-std/functions/std-sketch-angledLine.md This example demonstrates how to use the angledLine function within a sketch. It starts a sketch, draws a vertical line, then an angled line using angledLine, followed by a regular line, and finally closes and extrudes the sketch. ```kcl exampleSketch = startSketchOn(XZ) |> startProfile(at = [0, 0]) |> yLine(endAbsolute = 15) |> angledLine(angle = 30deg, length = 15) |> line(end = [8, -10]) |> yLine(endAbsolute = 0) |> close() example = extrude(exampleSketch, length = 10) ``` -------------------------------- ### Create a circular arc with a line segment Source: https://github.com/kittycad/modeling-app/blob/main/docs/kcl-std/functions/std-solver-arc.md This example demonstrates creating a circular arc that is coincident with a line segment. Ensure that the end point of the line is the start point of the arc, and the start point of the line is the end point of the arc for proper closure. ```kcl profile = sketch(on = XY) { base = line(start = [var -5mm, var 0mm], end = [var 5mm, var 0mm]) top = arc(start = [var 5mm, var 0mm], end = [var -5mm, var 0mm], center = [var 0mm, var 5mm]) coincident([base.end, top.start]) coincident([base.start, top.end]) } solid = extrude(region(point = [0mm, 2mm], sketch = profile), length = 2) ``` -------------------------------- ### Define and call a function with keyword arguments Source: https://github.com/kittycad/modeling-app/blob/main/docs/kcl-lang/functions.md Shows how to define a function that accepts labeled arguments and how to call it using keyword arguments. ```kcl // 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) ``` -------------------------------- ### KCL Example: Constraining Distance in a Profile Source: https://github.com/kittycad/modeling-app/blob/main/docs/kcl-std/functions/std-solver-distance.md This example demonstrates how to use solver::distance to set a specific dimension between two points in a 2D sketch profile. The constraint `distance([edge1.start, edge2.end]) == 5mm` ensures that the distance between the start of edge1 and the end of edge2 is exactly 5mm. ```kcl profile = sketch(on = XY) { edge1 = line(start = [var 0mm, var 0mm], end = [var 4mm, var 0mm]) edge2 = line(start = [var 4mm, var 0mm], end = [var 4mm, var 3mm]) edge3 = line(start = [var 4mm, var 3mm], end = [var 0mm, var 3mm]) edge4 = line(start = [var 0mm, var 3mm], end = [var 0mm, var 0mm]) coincident([edge1.end, edge2.start]) coincident([edge2.end, edge3.start]) coincident([edge3.end, edge4.start]) coincident([edge4.end, edge1.start]) distance([edge1.start, edge2.end]) == 5mm } solid = extrude(region(point = [2mm, 1mm], sketch = profile), length = 2) ``` -------------------------------- ### Create a Lofted Solid from Two Sketches Source: https://github.com/kittycad/modeling-app/blob/main/docs/kcl-std/functions/std-sketch-loft.md This example demonstrates creating a solid loft by defining two separate sketch profiles on different planes and then lofting between them. Ensure sketches are properly defined and regions are created before lofting. ```kcl lowerProfile = sketch(on = XY) { edge1 = line(start = [var 0mm, var 0mm], end = [var 6mm, var 0mm]) edge2 = line(start = [var 6mm, var 0mm], end = [var 6mm, var 4mm]) edge3 = line(start = [var 6mm, var 4mm], end = [var 0mm, var 4mm]) edge4 = line(start = [var 0mm, var 4mm], end = [var 0mm, var 0mm]) coincident([edge1.end, edge2.start]) coincident([edge2.end, edge3.start]) coincident([edge3.end, edge4.start]) coincident([edge4.end, edge1.start]) } upperProfile = sketch(on = offsetPlane(XY, offset = 8mm)) { edge5 = line(start = [var 1.6mm, var 1mm], end = [var 4.4mm, var 1mm]) edge6 = line(start = [var 4.4mm, var 1mm], end = [var 3.2mm, var 2.6mm]) edge7 = line(start = [var 3.2mm, var 2.6mm], end = [var 2.8mm, var 2.6mm]) edge8 = line(start = [var 2.8mm, var 2.6mm], end = [var 1.6mm, var 1mm]) coincident([edge5.end, edge6.start]) coincident([edge6.end, edge7.start]) coincident([edge7.end, edge8.start]) coincident([edge8.end, edge5.start]) } lowerRegion = region(point = [2mm, 2mm], sketch = lowerProfile) upperRegion = region(point = [3mm, 1.8mm], sketch = upperProfile) lofted = loft([lowerRegion, upperRegion]) ``` -------------------------------- ### Shelling an Entire Object Source: https://github.com/kittycad/modeling-app/blob/main/docs/kcl-std/functions/std-solid-shell.md This example illustrates how to apply the shell function to an entire object by specifying the base solid and the faces to remove. Here, the START face is removed from a complex extruded shape. ```kcl // Shell a sketch on face. size = 100 case = startSketchOn(-XZ) |> startProfile(at = [-size, -size]) |> line(end = [2 * size, 0]) |> line(end = [0, 2 * size]) |> tangentialArc(endAbsolute = [-size, size]) |> close() |> extrude(length = 65) thing1 = startSketchOn(case, face = END) |> circle(center = [-size / 2, -size / 2], radius = 25) |> extrude(length = 50) thing2 = startSketchOn(case, face = END) |> circle(center = [size / 2, -size / 2], radius = 25) |> extrude(length = 50) // We put "case" in the shell function to shell the entire object. shell(case, faces = [START], thickness = 5) ``` -------------------------------- ### Start Sketch on XY Plane and Extrude Source: https://github.com/kittycad/modeling-app/blob/main/docs/kcl-std/functions/std-sketch-startSketchOn.md Initiates a sketch on the XY plane, draws a profile, closes it, and then extrudes the sketch. This is a basic example of creating a 3D shape from a 2D sketch. ```kcl exampleSketch = startSketchOn(XY) |> startProfile(at = [0, 0]) |> line(end = [10, 0]) |> line(end = [0, 10]) |> line(end = [-10, 0]) |> close() example = extrude(exampleSketch, length = 5) ``` -------------------------------- ### Incorrect Multiple Profiles Example Source: https://github.com/kittycad/modeling-app/blob/main/docs/kcl-std/functions/std-sketch-startSketchOn.md This example demonstrates an incorrect way to create multiple profiles in a sketch using a single pipeline. This approach is not supported and will not work as intended. ```js // This does NOT work. twoSquares = startSketchOn(XY) |> startProfile(at = [0, 0]) |> line(end = [10, 0]) |> line(end = [0, 10]) |> line(end = [-10, 0]) |> close() |> startProfile(at = [20, 0]) |> line(end = [10, 0]) |> line(end = [0, 10]) |> line(end = [-10, 0]) |> close() twoCubes = extrude(twoSquares, length = 10) ``` -------------------------------- ### Compute Y-coordinate of Line Segment Start Source: https://github.com/kittycad/modeling-app/blob/main/docs/kcl-std/functions/std-sketch-segStartY.md Use segStartY to get the y-coordinate of a tagged line segment. This is helpful when defining subsequent sketch operations that depend on the vertical position of a previously defined segment. ```kcl segStartY(@tag: TaggedEdge): number(Length) ``` -------------------------------- ### Call functions with labeled and unlabeled arguments Source: https://github.com/kittycad/modeling-app/blob/main/docs/kcl-lang/functions.md Provides examples of calling functions, demonstrating how to use labeled arguments and how the '@' prefix allows the first argument to be unlabeled during the call. ```kcl @settings(defaultLengthUnit = mm) // All args must be labeled when calling (no @ on first param) fn cube1(offsetX, offsetY, radius, length) { sketch001 = startSketchOn(XY) |> polygon(radius = radius, numSides = 4, center = [offsetX, offsetY]) return extrude(sketch001, length = length) } // First arg may be unlabeled at call sites (because of @) fn cube2(@offsetX, offsetY, radius, length) { sketch001 = startSketchOn(XY) |> polygon(radius = radius, numSides = 4, center = [offsetX, offsetY]) return extrude(sketch001, length = length) } // Function Calls // all labeled testCube1 = cube1( offsetX = 0, offsetY = 6, radius = 5, length = 5, ) // first unlabeled works here testCube2 = cube2( 0, offsetY = 10, radius = 5, length = 5, ) ``` -------------------------------- ### Get Shared Edge Between Two Faces Source: https://github.com/kittycad/modeling-app/blob/main/docs/kcl-std/functions/std-sketch-getCommonEdge.md This example demonstrates how to create a part with a chamfer and then use getCommonEdge to find the edge shared between the chamfered face and the extruded face. This shared edge can then be used for further operations. ```kcl scale = 20 part001 = startSketchOn(XY) |> startProfile(at = [0, 0]) |> line(end = [0, scale]) |> line(end = [scale, 0]) |> line(end = [0, -scale]) |> close(tag = $line0) |> extrude(length = 20, tagEnd = $end0) // We tag the chamfer to reference it later. |> chamfer(length = 10, tags = [getOppositeEdge(line0)], tag = $chamfer0) // Get the shared edge between the chamfer and the extrusion. commonEdge = getCommonEdge(faces = [chamfer0, end0]) // Chamfer the shared edge. // TODO: uncomment this when ssi for fillets lands // chamfer(part001, length = 5, tags = [commonEdge]) ``` -------------------------------- ### Build UI Components Package Source: https://github.com/kittycad/modeling-app/blob/main/packages/ui-components/README.md Compiles and bundles the `@kittycad/ui-components` package for distribution. This command prepares the components for use in other projects. ```bash npm run build -w @kittycad/ui-components ``` -------------------------------- ### Create a simple circular arc Source: https://github.com/kittycad/modeling-app/blob/main/docs/kcl-std/functions/std-solver-arc.md This example shows how to create a simple circular arc using the `arc` function. The arc is defined by its start and end points, and the center of the circle it belongs to. This arc is then used within a sketch. ```kcl height = 2 profile = sketch(on = XY) { arc1 = arc(start = [0, 0], end = [0, height], center = [0, height / 2]) } ``` -------------------------------- ### Basic Spur Gear Example Source: https://github.com/kittycad/modeling-app/blob/main/docs/kcl-std/functions/std-gear-spur.md Demonstrates the basic usage of the gear::spur function to create a spur gear with specific dimensions and properties. Ensure experimental features are enabled. ```kcl // Basic example of a spur gear. @settings(defaultLengthUnit = mm, kclVersion = 1.0, experimentalFeatures = allow) gear::spur( nTeeth = 21, module = 1.5, pressureAngle = 14deg, gearHeight = 6, ) ``` -------------------------------- ### Compute Line Segment Length with segLen Source: https://github.com/kittycad/modeling-app/blob/main/docs/kcl-std/functions/std-sketch-segLen.md Use segLen to get the length of a tagged edge. This example demonstrates creating a sketch with a tagged line, then using segLen to define the length of another line based on the first. ```kcl exampleSketch = startSketchOn(XZ) |> startProfile(at = [0, 0]) |> angledLine(angle = 60deg, length = 10, tag = $thing) |> tangentialArc(angle = -120deg, radius = 5) |> angledLine(angle = -60deg, length = segLen(thing)) |> close() example = extrude(exampleSketch, length = 5) ``` -------------------------------- ### Example: Cutting a Hole with hole::holeAt Source: https://github.com/kittycad/modeling-app/blob/main/docs/kcl-std/functions/std-hole-holeAt.md This example demonstrates how to model a cube and then use hole::holeAt to cut a counterbored hole into it using a custom plane. The hole's bottom, body, and type are explicitly defined. ```kcl // Model a cube. cube1 = startSketchOn(XY) |> rectangle(width = 3, height = 3, center = [0, 0]) |> extrude(length = 3) // Define a custom plane, into which a hole will be cut. customPlane = { origin = { x = 1.5, y = -1.5, z = 3 }, xAxis = { x = -0.5, y = -0.5, z = 0 }, yAxis = { x = 0, y = 0.5, z = 0.5 } } // Cut the hole through the cube, into the plane. hole::holeAt( [cube1], plane = customPlane, holeBottom = hole::flat(), holeBody = hole::blind(depth = 2, diameter = 1), holeType = hole::counterbore(diameter = 1.4, depth = 1), ) ``` -------------------------------- ### Sketching a decagon using reduce Source: https://github.com/kittycad/modeling-app/blob/main/docs/kcl-std/functions/std-array-reduce.md This example uses `reduce` to iteratively draw the sides of a decagon. It starts with an initial sketch and, for each step, adds a line segment to form the next edge of the decagon. The `decagon` function is then called and closed. ```kcl // Declare a function that sketches a decagon. fn decagon(@radius) { // Each side of the decagon is turned this many radians from the previous angle. stepAngle = (1 / 10 * TAU): rad // Start the decagon sketch at this point. startOfDecagonSketch = startSketchOn(XY) |> startProfile(at = [cos(0) * radius, sin(0) * 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], initial = startOfDecagonSketch, f = fn(@i, accum) { // Draw one edge of the decagon. x = cos(stepAngle * i) * radius y = sin(stepAngle * i) * radius return line(accum, end = [x, y]) }, ) return fullDecagon } /* The `decagon` above is basically like this pseudo-code: fn decagon(radius): stepAngle = ((1/10) * TAU): rad plane = startSketchOn(XY) startOfDecagonSketch = startProfile(plane, at = [(cos(0)*radius), (sin(0) * radius)]) // Here's the reduce part. partialDecagon = startOfDecagonSketch for i in [1..10]: x = cos(stepAngle * i) * radius y = sin(stepAngle * i) * radius partialDecagon = line(partialDecagon, end = [x, y]) fullDecagon = partialDecagon // it's now full return fullDecagon */ // Use the `decagon` function declared above, to sketch a decagon with radius 5. decagon(5.0) |> close() ``` -------------------------------- ### Enable Logging and Memory Metrics Source: https://github.com/kittycad/modeling-app/blob/main/CONTRIBUTING.md Instructions for enabling logging and memory metrics. Set `ZOO_LOG=1` for logging and build with `--features dhat-heap` for memory metrics. ```bash ZOO_LOG=1 ``` ```bash --features dhat-heap ``` -------------------------------- ### Create a Rectangular Profile using solver::line Source: https://github.com/kittycad/modeling-app/blob/main/docs/kcl-std/functions/std-solver-line.md Defines a rectangular profile using four line segments. Ensure that the start and end points of adjacent segments are coincident to form a closed shape. This example demonstrates the basic usage of `solver::line` within a `sketch` block. ```kcl profile = sketch(on = XY) { edge1 = line(start = [var 0mm, var 0mm], end = [var 5mm, var 0mm]) edge2 = line(start = [var 5mm, var 0mm], end = [var 5mm, var 3mm]) edge3 = line(start = [var 5mm, var 3mm], end = [var 0mm, var 3mm]) edge4 = line(start = [var 0mm, var 3mm], end = [var 0mm, var 0mm]) coincident([edge1.end, edge2.start]) coincident([edge2.end, edge3.start]) coincident([edge3.end, edge4.start]) coincident([edge4.end, edge1.start]) } solid = extrude(region(point = [2mm, 1mm], sketch = profile), length = 2) ``` -------------------------------- ### Split Solids using a Tool Solid Source: https://github.com/kittycad/modeling-app/blob/main/docs/kcl-std/functions/std-solid-split.md This example shows how to split one solid (cube1) using another solid (cube2) as a tool. The `merge = true` option ensures the resulting geometry is a single solid. The `appearance` function is then applied to the split result. ```kcl cube1 = startSketchOn(XY) |> rectangle(width = 3, height = 3, center = [0, 0]) |> extrude(length = 2) cube2 = startSketchOn(offsetPlane(XY, offset = 0.4)) |> rectangle(width = 3, height = 3, center = [2, 2]) |> extrude(length = 2) cubes = split([cube1], tools = [cube2], merge = true) |> appearance( color = "#da4333", roughness = 50, metalness = 90, opacity = 80, ) ``` -------------------------------- ### Install Rust Fuzzing Tool Source: https://github.com/kittycad/modeling-app/blob/main/CONTRIBUTING.md Installs the `cargo-fuzz` tool, which is required for fuzzing the Rust parser. Ensure you have Rust and Cargo installed. ```bash cargo install cargo-fuzz ```