diff --git a/docs/kcl/index.md b/docs/kcl/index.md index 3c8b18cc7..a9f13ad4e 100644 --- a/docs/kcl/index.md +++ b/docs/kcl/index.md @@ -101,7 +101,6 @@ layout: manual * [`sin`](kcl/sin) * [`sqrt`](kcl/sqrt) * [`startProfileAt`](kcl/startProfileAt) -* [`startSketchAt`](kcl/startSketchAt) * [`startSketchOn`](kcl/startSketchOn) * [`sweep`](kcl/sweep) * [`tan`](kcl/tan) diff --git a/docs/kcl/patternTransform.md b/docs/kcl/patternTransform.md index 2b4854ba7..308fec983 100644 --- a/docs/kcl/patternTransform.md +++ b/docs/kcl/patternTransform.md @@ -95,7 +95,8 @@ fn cube(length, center) { p2 = [l + x, l + y] p3 = [l + x, -l + y] - return startSketchAt(p0) + return startSketchOn('XY') + |> startProfileAt(p0, %) |> lineTo(p1, %) |> lineTo(p2, %) |> lineTo(p3, %) @@ -132,7 +133,8 @@ fn cube(length, center) { p2 = [l + x, l + y] p3 = [l + x, -l + y] - return startSketchAt(p0) + return startSketchOn('XY') + |> startProfileAt(p0, %) |> lineTo(p1, %) |> lineTo(p2, %) |> lineTo(p3, %) @@ -195,7 +197,8 @@ fn transform(i) { { rotation = { angle = 45 * i } } ] } -startSketchAt([0, 0]) +startSketchOn('XY') + |> startProfileAt([0, 0], %) |> polygon({ radius = 10, numSides = 4, diff --git a/docs/kcl/reduce.md b/docs/kcl/reduce.md index 8dbf49195..730715cfc 100644 --- a/docs/kcl/reduce.md +++ b/docs/kcl/reduce.md @@ -79,10 +79,11 @@ fn decagon(radius) { stepAngle = 1 / 10 * tau() // Start the decagon sketch at this point. - startOfDecagonSketch = startSketchAt([cos(0) * radius, sin(0) * radius]) + startOfDecagonSketch = startSketchOn('XY') + |> startProfileAt([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, + // Use a `reduce` to draw the remaining decagon sides. + // For each number in the array 1..10, run the given function, // which takes a partially-sketched decagon and adds one more edge to it. fullDecagon = reduce([1..10], startOfDecagonSketch, fn(i, partialDecagon) { // Draw one edge of the decagon. @@ -97,7 +98,8 @@ fn decagon(radius) { /* The `decagon` above is basically like this pseudo-code: fn decagon(radius): stepAngle = (1/10) * tau() - startOfDecagonSketch = startSketchAt([(cos(0)*radius), (sin(0) * radius)]) + plane = startSketchOn('XY') + startOfDecagonSketch = startProfileAt([(cos(0)*radius), (sin(0) * radius)], plane) // Here's the reduce part. partialDecagon = startOfDecagonSketch diff --git a/docs/kcl/segEnd.md b/docs/kcl/segEnd.md index 73f2ec0a8..3d56aa7b2 100644 --- a/docs/kcl/segEnd.md +++ b/docs/kcl/segEnd.md @@ -28,7 +28,8 @@ segEnd(tag: TagIdentifier) -> [number] ```js w = 15 -cube = startSketchAt([0, 0]) +cube = startSketchOn('XY') + |> startProfileAt([0, 0], %) |> line([w, 0], %, $line1) |> line([0, w], %, $line2) |> line([-w, 0], %, $line3) @@ -37,7 +38,8 @@ cube = startSketchAt([0, 0]) |> extrude(5, %) fn cylinder(radius, tag) { - return startSketchAt([0, 0]) + return startSketchOn('XY') + |> startProfileAt([0, 0], %) |> circle({ radius = radius, center = segEnd(tag) diff --git a/docs/kcl/segStart.md b/docs/kcl/segStart.md index 7aa4b2bbd..0977c10c3 100644 --- a/docs/kcl/segStart.md +++ b/docs/kcl/segStart.md @@ -28,7 +28,8 @@ segStart(tag: TagIdentifier) -> [number] ```js w = 15 -cube = startSketchAt([0, 0]) +cube = startSketchOn('XY') + |> startProfileAt([0, 0], %) |> line([w, 0], %, $line1) |> line([0, w], %, $line2) |> line([-w, 0], %, $line3) @@ -37,7 +38,8 @@ cube = startSketchAt([0, 0]) |> extrude(5, %) fn cylinder(radius, tag) { - return startSketchAt([0, 0]) + return startSketchOn('XY') + |> startProfileAt([0, 0], %) |> circle({ radius = radius, center = segStart(tag) diff --git a/docs/kcl/startSketchAt.md b/docs/kcl/startSketchAt.md index e73fbb399..570f6e416 100644 --- a/docs/kcl/startSketchAt.md +++ b/docs/kcl/startSketchAt.md @@ -4,6 +4,8 @@ excerpt: "Start a new 2-dimensional sketch at a given point on the 'XY' plane." layout: manual --- +**WARNING:** This function is deprecated. + Start a new 2-dimensional sketch at a given point on the 'XY' plane. diff --git a/docs/kcl/std.json b/docs/kcl/std.json index 2e71fda04..0ba3e498d 100644 --- a/docs/kcl/std.json +++ b/docs/kcl/std.json @@ -125560,10 +125560,10 @@ "examples": [ "// Each instance will be shifted along the X axis.\nfn transform(id) {\n return { translate = [4 * id, 0, 0] }\n}\n\n// Sketch 4 cylinders.\nsketch001 = startSketchOn('XZ')\n |> circle({ center = [0, 0], radius = 2 }, %)\n |> extrude(5, %)\n |> patternTransform(4, transform, %)", "// Each instance will be shifted along the X axis,\n// with a gap between the original (at x = 0) and the first replica\n// (at x = 8). This is because `id` starts at 1.\nfn transform(id) {\n return { translate = [4 * (1 + id), 0, 0] }\n}\n\nsketch001 = startSketchOn('XZ')\n |> circle({ center = [0, 0], radius = 2 }, %)\n |> extrude(5, %)\n |> patternTransform(4, transform, %)", - "fn cube(length, center) {\n l = length / 2\n x = center[0]\n y = center[1]\n p0 = [-l + x, -l + y]\n p1 = [-l + x, l + y]\n p2 = [l + x, l + y]\n p3 = [l + x, -l + y]\n\n return startSketchAt(p0)\n |> lineTo(p1, %)\n |> lineTo(p2, %)\n |> lineTo(p3, %)\n |> lineTo(p0, %)\n |> close(%)\n |> extrude(length, %)\n}\n\nwidth = 20\nfn transform(i) {\n return {\n // Move down each time.\n translate = [0, 0, -i * width],\n // Make the cube longer, wider and flatter each time.\n scale = [pow(1.1, i), pow(1.1, i), pow(0.9, i)],\n // Turn by 15 degrees each time.\n rotation = { angle = 15 * i, origin = \"local\" }\n }\n}\n\nmyCubes = cube(width, [100, 0])\n |> patternTransform(25, transform, %)", - "fn cube(length, center) {\n l = length / 2\n x = center[0]\n y = center[1]\n p0 = [-l + x, -l + y]\n p1 = [-l + x, l + y]\n p2 = [l + x, l + y]\n p3 = [l + x, -l + y]\n\n return startSketchAt(p0)\n |> lineTo(p1, %)\n |> lineTo(p2, %)\n |> lineTo(p3, %)\n |> lineTo(p0, %)\n |> close(%)\n |> extrude(length, %)\n}\n\nwidth = 20\nfn transform(i) {\n return {\n translate = [0, 0, -i * width],\n rotation = {\n angle = 90 * i,\n // Rotate around the overall scene's origin.\n origin = \"global\"\n }\n }\n}\nmyCubes = cube(width, [100, 100])\n |> patternTransform(4, transform, %)", + "fn cube(length, center) {\n l = length / 2\n x = center[0]\n y = center[1]\n p0 = [-l + x, -l + y]\n p1 = [-l + x, l + y]\n p2 = [l + x, l + y]\n p3 = [l + x, -l + y]\n\n return startSketchOn('XY')\n |> startProfileAt(p0, %)\n |> lineTo(p1, %)\n |> lineTo(p2, %)\n |> lineTo(p3, %)\n |> lineTo(p0, %)\n |> close(%)\n |> extrude(length, %)\n}\n\nwidth = 20\nfn transform(i) {\n return {\n // Move down each time.\n translate = [0, 0, -i * width],\n // Make the cube longer, wider and flatter each time.\n scale = [pow(1.1, i), pow(1.1, i), pow(0.9, i)],\n // Turn by 15 degrees each time.\n rotation = { angle = 15 * i, origin = \"local\" }\n }\n}\n\nmyCubes = cube(width, [100, 0])\n |> patternTransform(25, transform, %)", + "fn cube(length, center) {\n l = length / 2\n x = center[0]\n y = center[1]\n p0 = [-l + x, -l + y]\n p1 = [-l + x, l + y]\n p2 = [l + x, l + y]\n p3 = [l + x, -l + y]\n\n return startSketchOn('XY')\n |> startProfileAt(p0, %)\n |> lineTo(p1, %)\n |> lineTo(p2, %)\n |> lineTo(p3, %)\n |> lineTo(p0, %)\n |> close(%)\n |> extrude(length, %)\n}\n\nwidth = 20\nfn transform(i) {\n return {\n translate = [0, 0, -i * width],\n rotation = {\n angle = 90 * i,\n // Rotate around the overall scene's origin.\n origin = \"global\"\n }\n }\n}\nmyCubes = cube(width, [100, 100])\n |> patternTransform(4, transform, %)", "// Parameters\nr = 50 // base radius\nh = 10 // layer height\nt = 0.005 // taper factor [0-1)\n// Defines how to modify each layer of the vase.\n// Each replica is shifted up the Z axis, and has a smoothly-varying radius\nfn transform(replicaId) {\n scale = r * abs(1 - (t * replicaId)) * (5 + cos(replicaId / 8))\n return {\n translate = [0, 0, replicaId * 10],\n scale = [scale, scale, 0]\n }\n}\n// Each layer is just a pretty thin cylinder.\nfn layer() {\n return startSketchOn(\"XY\")\n // or some other plane idk\n |> circle({ center = [0, 0], radius = 1 }, %, $tag1)\n |> extrude(h, %)\n}\n// The vase is 100 layers tall.\n// The 100 layers are replica of each other, with a slight transformation applied to each.\nvase = layer()\n |> patternTransform(100, transform, %)", - "fn transform(i) {\n // Transform functions can return multiple transforms. They'll be applied in order.\n return [\n { translate = [30 * i, 0, 0] },\n { rotation = { angle = 45 * i } }\n ]\n}\nstartSketchAt([0, 0])\n |> polygon({\n radius = 10,\n numSides = 4,\n center = [0, 0],\n inscribed = false\n }, %)\n |> extrude(4, %)\n |> patternTransform(3, transform, %)" + "fn transform(i) {\n // Transform functions can return multiple transforms. They'll be applied in order.\n return [\n { translate = [30 * i, 0, 0] },\n { rotation = { angle = 45 * i } }\n ]\n}\nstartSketchOn('XY')\n |> startProfileAt([0, 0], %)\n |> polygon({\n radius = 10,\n numSides = 4,\n center = [0, 0],\n inscribed = false\n }, %)\n |> extrude(4, %)\n |> patternTransform(3, transform, %)" ] }, { @@ -153536,7 +153536,7 @@ "examples": [ "// This function adds two numbers.\nfn add(a, b) {\n return a + b\n}\n\n// This function adds an array of numbers.\n// It uses the `reduce` function, to call the `add` function on every\n// element of the `arr` parameter. The starting value is 0.\nfn sum(arr) {\n return reduce(arr, 0, add)\n}\n\n/* The above is basically like this pseudo-code:\nfn sum(arr):\n sumSoFar = 0\n for i in arr:\n sumSoFar = add(sumSoFar, i)\n return sumSoFar */\n\n\n// We use `assertEqual` to check that our `sum` function gives the\n// expected result. It's good to check your work!\nassertEqual(sum([1, 2, 3]), 6, 0.00001, \"1 + 2 + 3 summed is 6\")", "// This example works just like the previous example above, but it uses\n// an anonymous `add` function as its parameter, instead of declaring a\n// named function outside.\narr = [1, 2, 3]\nsum = reduce(arr, 0, fn(i, result_so_far) {\n return i + result_so_far\n})\n\n// We use `assertEqual` to check that our `sum` function gives the\n// expected result. It's good to check your work!\nassertEqual(sum, 6, 0.00001, \"1 + 2 + 3 summed is 6\")", - "// Declare a function that sketches a decagon.\nfn decagon(radius) {\n // Each side of the decagon is turned this many degrees from the previous angle.\n stepAngle = 1 / 10 * tau()\n\n // Start the decagon sketch at this point.\n startOfDecagonSketch = startSketchAt([cos(0) * radius, sin(0) * radius])\n\n // Use a `reduce` to draw the remaining decagon sides.\n // For each number in the array 1..10, run the given function,\n // which takes a partially-sketched decagon and adds one more edge to it.\n fullDecagon = reduce([1..10], startOfDecagonSketch, fn(i, partialDecagon) {\n // Draw one edge of the decagon.\n x = cos(stepAngle * i) * radius\n y = sin(stepAngle * i) * radius\n return lineTo([x, y], partialDecagon)\n })\n\n return fullDecagon\n}\n\n/* The `decagon` above is basically like this pseudo-code:\nfn decagon(radius):\n stepAngle = (1/10) * tau()\n startOfDecagonSketch = startSketchAt([(cos(0)*radius), (sin(0) * radius)])\n\n // Here's the reduce part.\n partialDecagon = startOfDecagonSketch\n for i in [1..10]:\n x = cos(stepAngle * i) * radius\n y = sin(stepAngle * i) * radius\n partialDecagon = lineTo([x, y], partialDecagon)\n fullDecagon = partialDecagon // it's now full\n return fullDecagon */\n\n\n// Use the `decagon` function declared above, to sketch a decagon with radius 5.\ndecagon(5.0)\n |> close(%)" + "// Declare a function that sketches a decagon.\nfn decagon(radius) {\n // Each side of the decagon is turned this many degrees from the previous angle.\n stepAngle = 1 / 10 * tau()\n\n // Start the decagon sketch at this point.\n startOfDecagonSketch = startSketchOn('XY')\n |> startProfileAt([cos(0) * radius, sin(0) * radius], %)\n\n // Use a `reduce` to draw the remaining decagon sides.\n // For each number in the array 1..10, run the given function,\n // which takes a partially-sketched decagon and adds one more edge to it.\n fullDecagon = reduce([1..10], startOfDecagonSketch, fn(i, partialDecagon) {\n // Draw one edge of the decagon.\n x = cos(stepAngle * i) * radius\n y = sin(stepAngle * i) * radius\n return lineTo([x, y], partialDecagon)\n })\n\n return fullDecagon\n}\n\n/* The `decagon` above is basically like this pseudo-code:\nfn decagon(radius):\n stepAngle = (1/10) * tau()\n plane = startSketchOn('XY')\n startOfDecagonSketch = startProfileAt([(cos(0)*radius), (sin(0) * radius)], plane)\n\n // Here's the reduce part.\n partialDecagon = startOfDecagonSketch\n for i in [1..10]:\n x = cos(stepAngle * i) * radius\n y = sin(stepAngle * i) * radius\n partialDecagon = lineTo([x, y], partialDecagon)\n fullDecagon = partialDecagon // it's now full\n return fullDecagon */\n\n\n// Use the `decagon` function declared above, to sketch a decagon with radius 5.\ndecagon(5.0)\n |> close(%)" ] }, { @@ -159352,7 +159352,7 @@ "unpublished": false, "deprecated": false, "examples": [ - "w = 15\ncube = startSketchAt([0, 0])\n |> line([w, 0], %, $line1)\n |> line([0, w], %, $line2)\n |> line([-w, 0], %, $line3)\n |> line([0, -w], %, $line4)\n |> close(%)\n |> extrude(5, %)\n\nfn cylinder(radius, tag) {\n return startSketchAt([0, 0])\n |> circle({\n radius = radius,\n center = segEnd(tag)\n }, %)\n |> extrude(radius, %)\n}\n\ncylinder(1, line1)\ncylinder(2, line2)\ncylinder(3, line3)\ncylinder(4, line4)" + "w = 15\ncube = startSketchOn('XY')\n |> startProfileAt([0, 0], %)\n |> line([w, 0], %, $line1)\n |> line([0, w], %, $line2)\n |> line([-w, 0], %, $line3)\n |> line([0, -w], %, $line4)\n |> close(%)\n |> extrude(5, %)\n\nfn cylinder(radius, tag) {\n return startSketchOn('XY')\n |> startProfileAt([0, 0], %)\n |> circle({\n radius = radius,\n center = segEnd(tag)\n }, %)\n |> extrude(radius, %)\n}\n\ncylinder(1, line1)\ncylinder(2, line2)\ncylinder(3, line3)\ncylinder(4, line4)" ] }, { @@ -162981,7 +162981,7 @@ "unpublished": false, "deprecated": false, "examples": [ - "w = 15\ncube = startSketchAt([0, 0])\n |> line([w, 0], %, $line1)\n |> line([0, w], %, $line2)\n |> line([-w, 0], %, $line3)\n |> line([0, -w], %, $line4)\n |> close(%)\n |> extrude(5, %)\n\nfn cylinder(radius, tag) {\n return startSketchAt([0, 0])\n |> circle({\n radius = radius,\n center = segStart(tag)\n }, %)\n |> extrude(radius, %)\n}\n\ncylinder(1, line1)\ncylinder(2, line2)\ncylinder(3, line3)\ncylinder(4, line4)" + "w = 15\ncube = startSketchOn('XY')\n |> startProfileAt([0, 0], %)\n |> line([w, 0], %, $line1)\n |> line([0, w], %, $line2)\n |> line([-w, 0], %, $line3)\n |> line([0, -w], %, $line4)\n |> close(%)\n |> extrude(5, %)\n\nfn cylinder(radius, tag) {\n return startSketchOn('XY')\n |> startProfileAt([0, 0], %)\n |> circle({\n radius = radius,\n center = segStart(tag)\n }, %)\n |> extrude(radius, %)\n}\n\ncylinder(1, line1)\ncylinder(2, line2)\ncylinder(3, line3)\ncylinder(4, line4)" ] }, { @@ -174273,7 +174273,7 @@ "labelRequired": true }, "unpublished": false, - "deprecated": false, + "deprecated": true, "examples": [ "exampleSketch = startSketchAt([0, 0])\n |> line([10, 0], %)\n |> line([0, 10], %)\n |> line([-10, 0], %)\n |> close(%)\n\nexample = extrude(5, exampleSketch)", "exampleSketch = startSketchAt([10, 10])\n |> line([10, 0], %)\n |> line([0, 10], %)\n |> line([-10, 0], %)\n |> close(%)\n\nexample = extrude(5, exampleSketch)", diff --git a/src/wasm-lib/kcl/src/std/array.rs b/src/wasm-lib/kcl/src/std/array.rs index 110bad79c..37299e784 100644 --- a/src/wasm-lib/kcl/src/std/array.rs +++ b/src/wasm-lib/kcl/src/std/array.rs @@ -144,7 +144,8 @@ pub async fn reduce(exec_state: &mut ExecState, args: Args) -> Result startProfileAt([(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, @@ -164,7 +165,8 @@ pub async fn reduce(exec_state: &mut ExecState, args: Args) -> Result Res /// p2 = [ l + x, l + y] /// p3 = [ l + x, -l + y] /// -/// return startSketchAt(p0) +/// return startSketchOn('XY') +/// |> startProfileAt(p0, %) /// |> lineTo(p1, %) /// |> lineTo(p2, %) /// |> lineTo(p3, %) @@ -218,7 +219,8 @@ pub async fn pattern_transform_2d(exec_state: &mut ExecState, args: Args) -> Res /// p2 = [ l + x, l + y] /// p3 = [ l + x, -l + y] /// -/// return startSketchAt(p0) +/// return startSketchOn('XY') +/// |> startProfileAt(p0, %) /// |> lineTo(p1, %) /// |> lineTo(p2, %) /// |> lineTo(p3, %) @@ -274,7 +276,8 @@ pub async fn pattern_transform_2d(exec_state: &mut ExecState, args: Args) -> Res /// { rotation: { angle: 45 * i } }, /// ] /// } -/// startSketchAt([0, 0]) +/// startSketchOn('XY') +/// |> startProfileAt([0, 0], %) /// |> polygon({ /// radius: 10, /// numSides: 4, diff --git a/src/wasm-lib/kcl/src/std/segment.rs b/src/wasm-lib/kcl/src/std/segment.rs index 2e4b706aa..edb6451ae 100644 --- a/src/wasm-lib/kcl/src/std/segment.rs +++ b/src/wasm-lib/kcl/src/std/segment.rs @@ -22,7 +22,8 @@ pub async fn segment_end(exec_state: &mut ExecState, args: Args) -> Result startProfileAt([0, 0], %) /// |> line([w, 0], %, $line1) /// |> line([0, w], %, $line2) /// |> line([-w, 0], %, $line3) @@ -31,7 +32,8 @@ pub async fn segment_end(exec_state: &mut ExecState, args: Args) -> Result extrude(5, %) /// /// fn cylinder(radius, tag) { -/// return startSketchAt([0, 0]) +/// return startSketchOn('XY') +/// |> startProfileAt([0, 0], %) /// |> circle({ radius = radius, center = segEnd(tag) }, %) /// |> extrude(radius, %) /// } @@ -141,7 +143,8 @@ pub async fn segment_start(exec_state: &mut ExecState, args: Args) -> Result startProfileAt([0, 0], %) /// |> line([w, 0], %, $line1) /// |> line([0, w], %, $line2) /// |> line([-w, 0], %, $line3) @@ -150,7 +153,8 @@ pub async fn segment_start(exec_state: &mut ExecState, args: Args) -> Result extrude(5, %) /// /// fn cylinder(radius, tag) { -/// return startSketchAt([0, 0]) +/// return startSketchOn('XY') +/// |> startProfileAt([0, 0], %) /// |> circle({ radius = radius, center = segStart(tag) }, %) /// |> extrude(radius, %) /// } diff --git a/src/wasm-lib/kcl/src/std/sketch.rs b/src/wasm-lib/kcl/src/std/sketch.rs index 70617263b..6d9fc3e63 100644 --- a/src/wasm-lib/kcl/src/std/sketch.rs +++ b/src/wasm-lib/kcl/src/std/sketch.rs @@ -889,6 +889,7 @@ pub async fn start_sketch_at(exec_state: &mut ExecState, args: Args) -> Result Result { // Let's assume it's the XY plane for now, this is just for backwards compatibility.