From 3e7c6480dbe6e0f0c3ca4eebb116fd66896a46a0 Mon Sep 17 00:00:00 2001 From: Nick Cameron Date: Fri, 24 Jan 2025 17:18:05 +1300 Subject: [PATCH] Deprecate the math constants functions Signed-off-by: Nick Cameron --- docs/kcl/index.md | 3 --- docs/kcl/reduce.md | 4 ++-- docs/kcl/std.json | 14 +++++++------- src/wasm-lib/kcl/src/execution/mod.rs | 2 +- src/wasm-lib/kcl/src/parsing/parser.rs | 2 +- src/wasm-lib/kcl/src/std/array.rs | 4 ++-- src/wasm-lib/kcl/src/std/math.rs | 9 +++++++++ 7 files changed, 22 insertions(+), 16 deletions(-) diff --git a/docs/kcl/index.md b/docs/kcl/index.md index 965f15d8fd..c5292fdbd2 100644 --- a/docs/kcl/index.md +++ b/docs/kcl/index.md @@ -46,7 +46,6 @@ layout: manual * [`close`](kcl/close) * [`cm`](kcl/cm) * [`cos`](kcl/cos) -* [`e`](kcl/e) * [`extrude`](kcl/extrude) * [`fillet`](kcl/fillet) * [`floor`](kcl/floor) @@ -84,7 +83,6 @@ layout: manual * [`patternLinear3d`](kcl/patternLinear3d) * [`patternTransform`](kcl/patternTransform) * [`patternTransform2d`](kcl/patternTransform2d) -* [`pi`](kcl/pi) * [`polar`](kcl/polar) * [`polygon`](kcl/polygon) * [`pop`](kcl/pop) @@ -116,7 +114,6 @@ layout: manual * [`tangentialArc`](kcl/tangentialArc) * [`tangentialArcTo`](kcl/tangentialArcTo) * [`tangentialArcToRelative`](kcl/tangentialArcToRelative) -* [`tau`](kcl/tau) * [`toDegrees`](kcl/toDegrees) * [`toRadians`](kcl/toRadians) * [`xLine`](kcl/xLine) diff --git a/docs/kcl/reduce.md b/docs/kcl/reduce.md index 730715cfc0..42804a0073 100644 --- a/docs/kcl/reduce.md +++ b/docs/kcl/reduce.md @@ -76,7 +76,7 @@ assertEqual(sum, 6, 0.00001, "1 + 2 + 3 summed is 6") // Declare a function that sketches a decagon. fn decagon(radius) { // Each side of the decagon is turned this many degrees from the previous angle. - stepAngle = 1 / 10 * tau() + stepAngle = 1 / 10 * TAU // Start the decagon sketch at this point. startOfDecagonSketch = startSketchOn('XY') @@ -97,7 +97,7 @@ fn decagon(radius) { /* The `decagon` above is basically like this pseudo-code: fn decagon(radius): - stepAngle = (1/10) * tau() + stepAngle = (1/10) * TAU plane = startSketchOn('XY') startOfDecagonSketch = startProfileAt([(cos(0)*radius), (sin(0) * radius)], plane) diff --git a/docs/kcl/std.json b/docs/kcl/std.json index 79088ec3f7..321cfd2600 100644 --- a/docs/kcl/std.json +++ b/docs/kcl/std.json @@ -69705,7 +69705,7 @@ { "name": "e", "summary": "Return the value of Euler’s number `e`.", - "description": "", + "description": "**DEPRECATED** use the constant E", "tags": [ "math" ], @@ -69724,7 +69724,7 @@ "labelRequired": true }, "unpublished": false, - "deprecated": false, + "deprecated": true, "examples": [ "exampleSketch = startSketchOn(\"XZ\")\n |> startProfileAt([0, 0], %)\n |> angledLine({ angle = 30, length = 2 * e() ^ 2 }, %)\n |> yLineTo(0, %)\n |> close(%)\n\nexample = extrude(10, exampleSketch)" ] @@ -143089,7 +143089,7 @@ { "name": "pi", "summary": "Return the value of `pi`. Archimedes’ constant (π).", - "description": "", + "description": "**DEPRECATED** use the constant PI", "tags": [ "math" ], @@ -143108,7 +143108,7 @@ "labelRequired": true }, "unpublished": false, - "deprecated": false, + "deprecated": true, "examples": [ "circumference = 70\n\nexampleSketch = startSketchOn(\"XZ\")\n |> circle({\n center = [0, 0],\n radius = circumference / (2 * pi())\n }, %)\n\nexample = extrude(5, exampleSketch)" ] @@ -174308,7 +174308,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 = 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(%)" + "// 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(%)" ] }, { @@ -219519,7 +219519,7 @@ { "name": "tau", "summary": "Return the value of `tau`. The full circle constant (τ). Equal to 2π.", - "description": "", + "description": "**DEPRECATED** use the constant TAU", "tags": [ "math" ], @@ -219538,7 +219538,7 @@ "labelRequired": true }, "unpublished": false, - "deprecated": false, + "deprecated": true, "examples": [ "exampleSketch = startSketchOn(\"XZ\")\n |> startProfileAt([0, 0], %)\n |> angledLine({ angle = 50, length = 10 * tau() }, %)\n |> yLineTo(0, %)\n |> close(%)\n\nexample = extrude(5, exampleSketch)" ] diff --git a/src/wasm-lib/kcl/src/execution/mod.rs b/src/wasm-lib/kcl/src/execution/mod.rs index a33bae6fa3..4e03fd0fd4 100644 --- a/src/wasm-lib/kcl/src/execution/mod.rs +++ b/src/wasm-lib/kcl/src/execution/mod.rs @@ -3475,7 +3475,7 @@ let shape = layer() |> patternTransform(10, transform, %) #[tokio::test(flavor = "multi_thread")] async fn test_math_execute_with_pi() { - let ast = r#"const myVar = pi() * 2"#; + let ast = r#"const myVar = PI * 2"#; let (_, _, exec_state) = parse_execute(ast).await.unwrap(); assert_eq!( std::f64::consts::TAU, diff --git a/src/wasm-lib/kcl/src/parsing/parser.rs b/src/wasm-lib/kcl/src/parsing/parser.rs index 8c3501af10..b68f67a74a 100644 --- a/src/wasm-lib/kcl/src/parsing/parser.rs +++ b/src/wasm-lib/kcl/src/parsing/parser.rs @@ -1680,7 +1680,7 @@ fn validate_path_string(path_string: String, var_name: bool, path_range: SourceR for s in &segments { if s.chars().any(|c| !c.is_ascii_alphanumeric() && c != '_') || s.starts_with('_') { return Err(ErrMode::Cut( - CompilationError::fatal(path_range, "invalid path in import statment.").into(), + CompilationError::fatal(path_range, "invalid path in import statement.").into(), )); } } diff --git a/src/wasm-lib/kcl/src/std/array.rs b/src/wasm-lib/kcl/src/std/array.rs index 29a6452bcb..31a773b73a 100644 --- a/src/wasm-lib/kcl/src/std/array.rs +++ b/src/wasm-lib/kcl/src/std/array.rs @@ -141,7 +141,7 @@ pub async fn reduce(exec_state: &mut ExecState, args: Args) -> Result Result Result Result Result { Ok(std::f64::consts::PI) @@ -669,6 +672,8 @@ pub async fn e(_exec_state: &mut ExecState, args: Args) -> Result startProfileAt([0, 0], %) @@ -684,6 +689,7 @@ pub async fn e(_exec_state: &mut ExecState, args: Args) -> Result Result { Ok(std::f64::consts::E) @@ -698,6 +704,8 @@ pub async fn tau(_exec_state: &mut ExecState, args: Args) -> Result startProfileAt([0, 0], %) @@ -713,6 +721,7 @@ pub async fn tau(_exec_state: &mut ExecState, args: Args) -> Result Result { Ok(std::f64::consts::TAU)