KCL: User-defined KCL functions in examples etc now use keywords (#6603)
Preparing for the removal of positional functions from the language. The first big step is to change all our KCL code examples, test code, public samples etc to all use keyword functions. Apologies for how large this PR is. Most of it is: - Changing example KCL that defined its own functions, so the functions now use keyword arguments rather than positional arguments. E.g. change `cube([20, 20])` to be `cube(center = [20, 20])`. - Some parts of the code assumed positional code and didn't handle keyword calls, e.g. the linter would only check for positional calls to startSketchOn. Now they should work with either positional or keyword. - Update all the artifacts This does _not_ remove support for positional calls. That will be in a follow-up PR.
This commit is contained in:
@ -91,9 +91,9 @@ pub async fn appearance(exec_state: &mut ExecState, args: Args) -> Result<KclVal
|
||||
/// |> extrude(length = 10)
|
||||
/// }
|
||||
///
|
||||
/// example0 = cube([0, 0])
|
||||
/// example1 = cube([20, 0])
|
||||
/// example2 = cube([40, 0])
|
||||
/// example0 = cube(center = [0, 0])
|
||||
/// example1 = cube(center = [20, 0])
|
||||
/// example2 = cube(center = [40, 0])
|
||||
///
|
||||
/// appearance([example0, example1], color='#ff0000', metalness=50, roughness=50)
|
||||
/// appearance(example2, color='#00ff00', metalness=50, roughness=50)
|
||||
|
@ -26,7 +26,7 @@ pub async fn map(exec_state: &mut ExecState, args: Args) -> Result<KclValue, Kcl
|
||||
/// `[f(a), f(b), f(c)]`
|
||||
/// ```no_run
|
||||
/// r = 10 // radius
|
||||
/// fn drawCircle(id) {
|
||||
/// fn drawCircle(@id) {
|
||||
/// return startSketchOn(XY)
|
||||
/// |> circle( center= [id * 2 * r, 0], radius= r)
|
||||
/// }
|
||||
@ -110,7 +110,7 @@ pub async fn reduce(exec_state: &mut ExecState, args: Args) -> Result<KclValue,
|
||||
/// // This function adds an array of numbers.
|
||||
/// // It uses the `reduce` function, to call the `add` function on every
|
||||
/// // element of the `arr` parameter. The starting value is 0.
|
||||
/// fn sum(arr) { return reduce(arr, initial = 0, f = add) }
|
||||
/// fn sum(@arr) { return reduce(arr, initial = 0, f = add) }
|
||||
///
|
||||
/// /*
|
||||
/// The above is basically like this pseudo-code:
|
||||
@ -138,7 +138,7 @@ pub async fn reduce(exec_state: &mut ExecState, args: Args) -> Result<KclValue,
|
||||
/// ```
|
||||
/// ```no_run
|
||||
/// // Declare a function that sketches a decagon.
|
||||
/// fn decagon(radius) {
|
||||
/// fn decagon(@radius) {
|
||||
/// // Each side of the decagon is turned this many radians from the previous angle.
|
||||
/// stepAngle = ((1/10) * TAU): number(rad)
|
||||
///
|
||||
|
@ -49,8 +49,8 @@ pub async fn union(exec_state: &mut ExecState, args: Args) -> Result<KclValue, K
|
||||
/// |> extrude(length = 10)
|
||||
/// }
|
||||
///
|
||||
/// part001 = cube([0, 0], 10)
|
||||
/// part002 = cube([7, 3], 5)
|
||||
/// part001 = cube(center = [0, 0], size = 10)
|
||||
/// part002 = cube(center = [7, 3], size = 5)
|
||||
/// |> translate(z = 1)
|
||||
///
|
||||
/// unionedPart = union([part001, part002])
|
||||
@ -71,8 +71,8 @@ pub async fn union(exec_state: &mut ExecState, args: Args) -> Result<KclValue, K
|
||||
/// |> extrude(length = 10)
|
||||
/// }
|
||||
///
|
||||
/// part001 = cube([0, 0], 10)
|
||||
/// part002 = cube([7, 3], 5)
|
||||
/// part001 = cube(center = [0, 0], size = 10)
|
||||
/// part002 = cube(center = [7, 3], size = 5)
|
||||
/// |> translate(z = 1)
|
||||
///
|
||||
/// // This is the equivalent of: union([part001, part002])
|
||||
@ -94,8 +94,8 @@ pub async fn union(exec_state: &mut ExecState, args: Args) -> Result<KclValue, K
|
||||
/// |> extrude(length = 10)
|
||||
/// }
|
||||
///
|
||||
/// part001 = cube([0, 0], 10)
|
||||
/// part002 = cube([7, 3], 5)
|
||||
/// part001 = cube(center = [0, 0], size = 10)
|
||||
/// part002 = cube(center = [7, 3], size = 5)
|
||||
/// |> translate(z = 1)
|
||||
///
|
||||
/// // This is the equivalent of: union([part001, part002])
|
||||
@ -199,8 +199,8 @@ pub async fn intersect(exec_state: &mut ExecState, args: Args) -> Result<KclValu
|
||||
/// |> extrude(length = 10)
|
||||
/// }
|
||||
///
|
||||
/// part001 = cube([0, 0], 10)
|
||||
/// part002 = cube([7, 3], 5)
|
||||
/// part001 = cube(center = [0, 0], size = 10)
|
||||
/// part002 = cube(center = [7, 3], size = 5)
|
||||
/// |> translate(z = 1)
|
||||
///
|
||||
/// intersectedPart = intersect([part001, part002])
|
||||
@ -221,8 +221,8 @@ pub async fn intersect(exec_state: &mut ExecState, args: Args) -> Result<KclValu
|
||||
/// |> extrude(length = 10)
|
||||
/// }
|
||||
///
|
||||
/// part001 = cube([0, 0], 10)
|
||||
/// part002 = cube([7, 3], 5)
|
||||
/// part001 = cube(center = [0, 0], size = 10)
|
||||
/// part002 = cube(center = [7, 3], size = 5)
|
||||
/// |> translate(z = 1)
|
||||
///
|
||||
/// // This is the equivalent of: intersect([part001, part002])
|
||||
@ -332,8 +332,8 @@ pub async fn subtract(exec_state: &mut ExecState, args: Args) -> Result<KclValue
|
||||
/// |> extrude(length = 10)
|
||||
/// }
|
||||
///
|
||||
/// part001 = cube([0, 0], 10)
|
||||
/// part002 = cube([7, 3], 5)
|
||||
/// part001 = cube(center = [0, 0], size = 10)
|
||||
/// part002 = cube(center = [7, 3], size = 5)
|
||||
/// |> translate(z = 1)
|
||||
///
|
||||
/// subtractedPart = subtract([part001], tools=[part002])
|
||||
@ -354,8 +354,8 @@ pub async fn subtract(exec_state: &mut ExecState, args: Args) -> Result<KclValue
|
||||
/// |> extrude(length = 10)
|
||||
/// }
|
||||
///
|
||||
/// part001 = cube([0, 0], 10)
|
||||
/// part002 = cube([7, 3], 5)
|
||||
/// part001 = cube(center = [0, 0], size = 10)
|
||||
/// part002 = cube(center = [7, 3], size = 5)
|
||||
/// |> translate(z = 1)
|
||||
///
|
||||
/// // This is the equivalent of: subtract([part001], tools=[part002])
|
||||
|
@ -96,7 +96,7 @@ pub async fn pattern_transform_2d(exec_state: &mut ExecState, args: Args) -> Res
|
||||
///
|
||||
/// ```no_run
|
||||
/// // Each instance will be shifted along the X axis.
|
||||
/// fn transform(id) {
|
||||
/// fn transform(@id) {
|
||||
/// return { translate = [4 * id, 0, 0] }
|
||||
/// }
|
||||
///
|
||||
@ -110,7 +110,7 @@ pub async fn pattern_transform_2d(exec_state: &mut ExecState, args: Args) -> Res
|
||||
/// // Each instance will be shifted along the X axis,
|
||||
/// // with a gap between the original (at x = 0) and the first replica
|
||||
/// // (at x = 8). This is because `id` starts at 1.
|
||||
/// fn transform(id) {
|
||||
/// fn transform(@id) {
|
||||
/// return { translate = [4 * (1+id), 0, 0] }
|
||||
/// }
|
||||
///
|
||||
@ -140,7 +140,7 @@ pub async fn pattern_transform_2d(exec_state: &mut ExecState, args: Args) -> Res
|
||||
/// }
|
||||
///
|
||||
/// width = 20
|
||||
/// fn transform(i) {
|
||||
/// fn transform(@i) {
|
||||
/// return {
|
||||
/// // Move down each time.
|
||||
/// translate = [0, 0, -i * width],
|
||||
@ -155,7 +155,7 @@ pub async fn pattern_transform_2d(exec_state: &mut ExecState, args: Args) -> Res
|
||||
/// }
|
||||
///
|
||||
/// myCubes =
|
||||
/// cube(width, [100,0])
|
||||
/// cube(length = width, center = [100,0])
|
||||
/// |> patternTransform(instances = 25, transform = transform)
|
||||
/// ```
|
||||
///
|
||||
@ -180,7 +180,7 @@ pub async fn pattern_transform_2d(exec_state: &mut ExecState, args: Args) -> Res
|
||||
/// }
|
||||
///
|
||||
/// width = 20
|
||||
/// fn transform(i) {
|
||||
/// fn transform(@i) {
|
||||
/// return {
|
||||
/// translate = [0, 0, -i * width],
|
||||
/// rotation = {
|
||||
@ -191,7 +191,7 @@ pub async fn pattern_transform_2d(exec_state: &mut ExecState, args: Args) -> Res
|
||||
/// }
|
||||
/// }
|
||||
/// myCubes =
|
||||
/// cube(width, [100,100])
|
||||
/// cube(length = width, center = [100,100])
|
||||
/// |> patternTransform(instances = 4, transform = transform)
|
||||
/// ```
|
||||
/// ```no_run
|
||||
@ -201,7 +201,7 @@ pub async fn pattern_transform_2d(exec_state: &mut ExecState, args: Args) -> Res
|
||||
/// t = 0.005 // taper factor [0-1)
|
||||
/// // Defines how to modify each layer of the vase.
|
||||
/// // Each replica is shifted up the Z axis, and has a smoothly-varying radius
|
||||
/// fn transform(replicaId) {
|
||||
/// fn transform(@replicaId) {
|
||||
/// scale = r * abs(1 - (t * replicaId)) * (5 + cos((replicaId / 8): number(rad)))
|
||||
/// return {
|
||||
/// translate = [0, 0, replicaId * 10],
|
||||
@ -219,7 +219,7 @@ pub async fn pattern_transform_2d(exec_state: &mut ExecState, args: Args) -> Res
|
||||
/// vase = layer() |> patternTransform(instances = 100, transform = transform)
|
||||
/// ```
|
||||
/// ```
|
||||
/// fn transform(i) {
|
||||
/// fn transform(@i) {
|
||||
/// // Transform functions can return multiple transforms. They'll be applied in order.
|
||||
/// return [
|
||||
/// { translate = [30 * i, 0, 0] },
|
||||
@ -282,7 +282,7 @@ async fn inner_pattern_transform<'a>(
|
||||
/// Just like patternTransform, but works on 2D sketches not 3D solids.
|
||||
/// ```no_run
|
||||
/// // Each instance will be shifted along the X axis.
|
||||
/// fn transform(id) {
|
||||
/// fn transform(@id) {
|
||||
/// return { translate = [4 * id, 0] }
|
||||
/// }
|
||||
///
|
||||
|
@ -42,10 +42,10 @@ pub async fn segment_end(exec_state: &mut ExecState, args: Args) -> Result<KclVa
|
||||
/// |> extrude(length = radius)
|
||||
/// }
|
||||
///
|
||||
/// cylinder(1, line1)
|
||||
/// cylinder(2, line2)
|
||||
/// cylinder(3, line3)
|
||||
/// cylinder(4, line4)
|
||||
/// cylinder(radius = 1, tag = line1)
|
||||
/// cylinder(radius = 2, tag = line2)
|
||||
/// cylinder(radius = 3, tag = line3)
|
||||
/// cylinder(radius = 4, tag = line4)
|
||||
/// ```
|
||||
#[stdlib {
|
||||
name = "segEnd",
|
||||
@ -178,10 +178,10 @@ pub async fn segment_start(exec_state: &mut ExecState, args: Args) -> Result<Kcl
|
||||
/// |> extrude(length = radius)
|
||||
/// }
|
||||
///
|
||||
/// cylinder(1, line1)
|
||||
/// cylinder(2, line2)
|
||||
/// cylinder(3, line3)
|
||||
/// cylinder(4, line4)
|
||||
/// cylinder(radius = 1, tag = line1)
|
||||
/// cylinder(radius = 2, tag = line2)
|
||||
/// cylinder(radius = 3, tag = line3)
|
||||
/// cylinder(radius = 4, tag = line4)
|
||||
/// ```
|
||||
#[stdlib {
|
||||
name = "segStart",
|
||||
|
@ -326,7 +326,7 @@ pub async fn translate(exec_state: &mut ExecState, args: Args) -> Result<KclValu
|
||||
/// ```no_run
|
||||
/// // Move a sketch.
|
||||
///
|
||||
/// fn square(length){
|
||||
/// fn square(@length){
|
||||
/// l = length / 2
|
||||
/// p0 = [-l, -l]
|
||||
/// p1 = [-l, l]
|
||||
|
Reference in New Issue
Block a user