KCL: Angled line should use keyword args (#5803)

We continue migrating KCL stdlib functions to use keyword arguments. Next up is the `angledLine` family of functions (except `angledLineThatIntersects, which will be a quick follow-up).

Before vs. after:

`angledLine({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, length = 3, tag = $edge)`

`angledLineOfXLength({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, lengthX = 3, tag = $edge)`

`angledLineOfYLength({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, lengthY = 3, tag = $edge)`

`angledLineToX({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, endAbsoluteX = 3, tag = $edge)`

`angledLineToY({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, endAbsoluteY = 3, tag = $edge)`
This commit is contained in:
Adam Chalmers
2025-04-09 14:55:15 -05:00
committed by GitHub
parent b03ca30379
commit d275995dfe
288 changed files with 36142 additions and 40081 deletions

View File

@ -594,7 +594,7 @@ myCube = cube([0,0], 10)
async fn kcl_test_cube_cm() {
let code = r#"@settings(defaultLengthUnit = cm)
fn cube = (pos, scale) => {
sg = startSketchOn('XY')
sg = startSketchOn(XY)
|> startProfileAt(pos, %)
|> line(end = [0, scale])
|> line(end = [scale, 0])
@ -616,7 +616,7 @@ myCube = cube([0,0], 10)
async fn kcl_test_cube_m() {
let code = r#"@settings(defaultLengthUnit = m)
fn cube = (pos, scale) => {
sg = startSketchOn('XY')
sg = startSketchOn(XY)
|> startProfileAt(pos, %)
|> line(end = [0, scale])
|> line(end = [scale, 0])
@ -638,7 +638,7 @@ myCube = cube([0,0], 10)
async fn kcl_test_cube_in() {
let code = r#"@settings(defaultLengthUnit = in)
fn cube = (pos, scale) => {
sg = startSketchOn('XY')
sg = startSketchOn(XY)
|> startProfileAt(pos, %)
|> line(end = [0, scale])
|> line(end = [scale, 0])
@ -660,7 +660,7 @@ myCube = cube([0,0], 10)
async fn kcl_test_cube_ft() {
let code = r#"@settings(defaultLengthUnit = ft)
fn cube = (pos, scale) => {
sg = startSketchOn('XY')
sg = startSketchOn(XY)
|> startProfileAt(pos, %)
|> line(end = [0, scale])
|> line(end = [scale, 0])
@ -682,7 +682,7 @@ myCube = cube([0,0], 10)
async fn kcl_test_cube_yd() {
let code = r#"@settings(defaultLengthUnit = yd)
fn cube = (pos, scale) => {
sg = startSketchOn('XY')
sg = startSketchOn(XY)
|> startProfileAt(pos, %)
|> line(end = [0, scale])
|> line(end = [scale, 0])
@ -842,10 +842,10 @@ holeIndex = 6
// Create the mounting plate extrusion, holes, and fillets
part = rectShape([0, 0], 20, 20)
|> hole(circle('XY', center = [-holeIndex, holeIndex], radius = holeRadius), %)
|> hole(circle('XY', center = [holeIndex, holeIndex], radius = holeRadius), %)
|> hole(circle('XY', center = [-holeIndex, -holeIndex], radius = holeRadius), %)
|> hole(circle('XY', center = [holeIndex, -holeIndex], radius = holeRadius), %)
|> hole(circle('XY', center = [-holeIndex, holeIndex], radius = holeRadius))
|> hole(circle('XY', center = [holeIndex, holeIndex], radius = holeRadius))
|> hole(circle('XY', center = [-holeIndex, -holeIndex], radius = holeRadius))
|> hole(circle('XY', center = [holeIndex, -holeIndex], radius = holeRadius))
|> extrude(length = 2)
|> fillet(
radius = 4,
@ -1088,8 +1088,8 @@ async fn kcl_test_revolve_on_face_circle_edge() {
sketch001 = startSketchOn(box, "END")
|> circle(center = [10,10], radius= 4)
|> revolve(
angle = 90,
axis = getOppositeEdge(revolveAxis)
angle = 90,
axis = getOppositeEdge(revolveAxis)
)
"#;
@ -1192,9 +1192,9 @@ async fn kcl_test_plumbus_fillets() {
sg = startSketchOn(ext, face)
|> startProfileAt([pos[0] + radius, pos[1]], %)
|> arc({
angleEnd: 360,
angleStart: 0,
radius= radius
angleEnd = 360,
angleStart = 0,
radius = radius
}, %, $arc1)
|> close()
@ -1204,23 +1204,26 @@ async fn kcl_test_plumbus_fillets() {
fn pentagon = (len) => {
sg = startSketchOn(XY)
|> startProfileAt([-len / 2, -len / 2], %)
|> angledLine({ angle: 0, length: len }, %, $a)
|> angledLine({
angle: segAng(a) + 180 - 108,
length: len
}, %, $b)
|> angledLine({
angle: segAng(b) + 180 - 108,
length: len
}, %, $c)
|> angledLine({
angle: segAng(c) + 180 - 108,
length: len
}, %, $d)
|> angledLine({
angle: segAng(d) + 180 - 108,
length: len
}, %)
|> angledLine(angle = 0, length = len, tag = $a)
|> angledLine(
angle = segAng(a) + 180 - 108,
length = len,
tag = $b,
)
|> angledLine(
angle = segAng(b) + 180 - 108,
length = len,
tag = $c,
)
|> angledLine(
angle = segAng(c) + 180 - 108,
length = len,
tag = $d,
)
|> angledLine(
angle = segAng(d) + 180 - 108,
length = len,
)
return sg
}
@ -1471,7 +1474,7 @@ cornerFilletRad = 0.5
holeDia = 0.5
sketch001 = startSketchOn("XZ")
sketch001 = startSketchOn(XZ)
|> startProfileAt([-foot1Length, 0], %)
|> line(end = [0, thickness], tag = $cornerFillet1)
|> line(end = [foot1Length, 0])
@ -1519,7 +1522,7 @@ cornerChamferRad = 0.5
holeDia = 0.5
sketch001 = startSketchOn("XZ")
sketch001 = startSketchOn(XZ)
|> startProfileAt([-foot1Length, 0], %)
|> line(end = [0, thickness], tag = $cornerChamfer1)
|> line(end = [foot1Length, 0])
@ -1692,26 +1695,26 @@ async fn kcl_test_duplicate_tags_should_error() {
let code = r#"fn triangle = (len) => {
return startSketchOn(XY)
|> startProfileAt([-len / 2, -len / 2], %)
|> angledLine({ angle: 0, length: len }, %, $a)
|> angledLine({
angle: segAng(a) + 120,
length: len
}, %, $b)
|> angledLine({
angle: segAng(b) + 120,
length: len
}, %, $a)
|> angledLine(angle = 0, length = len , tag = $a)
|> angledLine(
angle = segAng(a) + 120,
length = len,
tag = $b,
)
|> angledLine(
angle = segAng(b) + 120,
length = len,
tag = $a,
)
}
let p = triangle(200)
"#;
let result = execute_and_snapshot(code, None).await;
assert!(result.is_err());
assert_eq!(
result.err().unwrap().to_string(),
r#"value already defined: KclErrorDetails { source_ranges: [SourceRange([309, 311, 0]), SourceRange([324, 337, 0])], message: "Cannot redefine `a`" }"#
);
let err = result.unwrap_err();
let err = err.as_kcl_error().unwrap();
assert_eq!(err.message(), "Cannot redefine `a`");
}
#[tokio::test(flavor = "multi_thread")]
@ -1793,7 +1796,7 @@ async fn kcl_test_arc_error_same_start_end() {
async fn kcl_test_angled_line_to_x_90() {
let code = r#"exampleSketch = startSketchOn(XZ)
|> startProfileAt([0, 0], %)
|> angledLineToX({ angle: 90, to: 10 }, %)
|> angledLine(angle = 90, endAbsoluteX = 10)
|> line(end = [0, 10])
|> line(end = [-10, 0])
|> close()
@ -1805,7 +1808,7 @@ example = extrude(exampleSketch, length = 10)
assert!(result.is_err());
assert_eq!(
result.err().unwrap().to_string(),
r#"type: KclErrorDetails { source_ranges: [SourceRange([70, 109, 0])], message: "Cannot have an x constrained angle of 90 degrees" }"#
r#"type: KclErrorDetails { source_ranges: [SourceRange([70, 111, 0])], message: "Cannot have an x constrained angle of 90 degrees" }"#
);
}
@ -1813,7 +1816,7 @@ example = extrude(exampleSketch, length = 10)
async fn kcl_test_angled_line_to_x_270() {
let code = r#"exampleSketch = startSketchOn(XZ)
|> startProfileAt([0, 0], %)
|> angledLineToX({ angle: 270, to: 10 }, %)
|> angledLine(angle = 270, endAbsoluteX = 10)
|> line(end = [0, 10])
|> line(end = [-10, 0])
|> close()
@ -1825,7 +1828,7 @@ example = extrude(exampleSketch, length = 10)
assert!(result.is_err());
assert_eq!(
result.err().unwrap().to_string(),
r#"type: KclErrorDetails { source_ranges: [SourceRange([70, 110, 0])], message: "Cannot have an x constrained angle of 270 degrees" }"#
r#"type: KclErrorDetails { source_ranges: [SourceRange([70, 112, 0])], message: "Cannot have an x constrained angle of 270 degrees" }"#
);
}
@ -1833,9 +1836,9 @@ example = extrude(exampleSketch, length = 10)
async fn kcl_test_angled_line_to_y_0() {
let code = r#"exampleSketch = startSketchOn(XZ)
|> startProfileAt([0, 0], %)
|> angledLineToY({ angle: 0, to: 20 }, %)
|> angledLine(angle = 0, endAbsoluteY = 20)
|> line(end = [-20, 0])
|> angledLineToY({ angle: 70, to: 10 }, %)
|> angledLine(angle = 70, endAbsoluteY = 10)
|> close()
example = extrude(exampleSketch, length = 10)
@ -1845,7 +1848,7 @@ example = extrude(exampleSketch, length = 10)
assert!(result.is_err());
assert_eq!(
result.err().unwrap().to_string(),
r#"type: KclErrorDetails { source_ranges: [SourceRange([70, 108, 0])], message: "Cannot have a y constrained angle of 0 degrees" }"#
r#"type: KclErrorDetails { source_ranges: [SourceRange([70, 110, 0])], message: "Cannot have a y constrained angle of 0 degrees" }"#
);
}
@ -1853,9 +1856,9 @@ example = extrude(exampleSketch, length = 10)
async fn kcl_test_angled_line_to_y_180() {
let code = r#"exampleSketch = startSketchOn(XZ)
|> startProfileAt([0, 0], %)
|> angledLineToY({ angle: 180, to: 20 }, %)
|> angledLine(angle = 180, endAbsoluteY = 20)
|> line(end = [-20, 0])
|> angledLineToY({ angle: 70, to: 10 }, %)
|> angledLine(angle = 70, endAbsoluteY = 10)
|> close()
example = extrude(exampleSketch, length = 10)
@ -1865,7 +1868,7 @@ example = extrude(exampleSketch, length = 10)
assert!(result.is_err());
assert_eq!(
result.err().unwrap().to_string(),
r#"type: KclErrorDetails { source_ranges: [SourceRange([70, 110, 0])], message: "Cannot have a y constrained angle of 180 degrees" }"#
r#"type: KclErrorDetails { source_ranges: [SourceRange([70, 112, 0])], message: "Cannot have a y constrained angle of 180 degrees" }"#
);
}
@ -1873,8 +1876,8 @@ example = extrude(exampleSketch, length = 10)
async fn kcl_test_angled_line_of_x_length_90() {
let code = r#"sketch001 = startSketchOn(XZ)
|> startProfileAt([0, 0], %)
|> angledLineOfXLength({ angle: 90, length: 10 }, %, $edge1)
|> angledLineOfXLength({ angle: -15, length: 20 }, %, $edge2)
|> angledLine(angle = 90, lengthX = 90, tag = $edge1)
|> angledLine(angle = -15, lengthX = -15, tag = $edge2)
|> line(end = [0, -5])
|> close(tag = $edge3)
@ -1885,7 +1888,7 @@ extrusion = extrude(sketch001, length = 10)
assert!(result.is_err());
assert_eq!(
result.err().unwrap().to_string(),
r#"type: KclErrorDetails { source_ranges: [SourceRange([66, 123, 0])], message: "Cannot have an x constrained angle of 90 degrees" }"#
r#"type: KclErrorDetails { source_ranges: [SourceRange([66, 116, 0])], message: "Cannot have an x constrained angle of 90 degrees" }"#
);
}
@ -1893,8 +1896,8 @@ extrusion = extrude(sketch001, length = 10)
async fn kcl_test_angled_line_of_x_length_270() {
let code = r#"sketch001 = startSketchOn(XZ)
|> startProfileAt([0, 0], %)
|> angledLineOfXLength({ angle: 90, length: 10 }, %, $edge1)
|> angledLineOfXLength({ angle: -15, length: 20 }, %, $edge2)
|> angledLine(angle = 90, lengthX = 90, tag = $edge1)
|> angledLine(angle = -15, lengthX = -15, tag = $edge2)
|> line(end = [0, -5])
|> close(tag = $edge3)
@ -1905,7 +1908,7 @@ extrusion = extrude(sketch001, length = 10)
assert!(result.is_err());
assert_eq!(
result.err().unwrap().to_string(),
r#"type: KclErrorDetails { source_ranges: [SourceRange([66, 123, 0])], message: "Cannot have an x constrained angle of 90 degrees" }"#
r#"type: KclErrorDetails { source_ranges: [SourceRange([66, 116, 0])], message: "Cannot have an x constrained angle of 90 degrees" }"#
);
}
@ -1914,9 +1917,9 @@ async fn kcl_test_angled_line_of_y_length_0() {
let code = r#"exampleSketch = startSketchOn(XZ)
|> startProfileAt([0, 0], %)
|> line(end = [10, 0])
|> angledLineOfYLength({ angle: 0, length: 10 }, %)
|> angledLine(angle = 0, lengthY = 10)
|> line(end = [0, 10])
|> angledLineOfYLength({ angle: 135, length: 10 }, %)
|> angledLine(angle = 135, lengthY = 10)
|> line(end = [-10, 0])
|> line(end = [0, -30])
@ -1927,7 +1930,7 @@ example = extrude(exampleSketch, length = 10)
assert!(result.is_err());
assert_eq!(
result.err().unwrap().to_string(),
r#"type: KclErrorDetails { source_ranges: [SourceRange([95, 143, 0])], message: "Cannot have a y constrained angle of 0 degrees" }"#
r#"type: KclErrorDetails { source_ranges: [SourceRange([95, 130, 0])], message: "Cannot have a y constrained angle of 0 degrees" }"#
);
}
@ -1936,9 +1939,9 @@ async fn kcl_test_angled_line_of_y_length_180() {
let code = r#"exampleSketch = startSketchOn(XZ)
|> startProfileAt([0, 0], %)
|> line(end = [10, 0])
|> angledLineOfYLength({ angle: 180, length: 10 }, %)
|> angledLine(angle = 180, lengthY = 10)
|> line(end = [0, 10])
|> angledLineOfYLength({ angle: 135, length: 10 }, %)
|> angledLine(angle = 135, lengthY = 10)
|> line(end = [-10, 0])
|> line(end = [0, -30])
@ -1949,7 +1952,7 @@ example = extrude(exampleSketch, length = 10)
assert!(result.is_err());
assert_eq!(
result.err().unwrap().to_string(),
r#"type: KclErrorDetails { source_ranges: [SourceRange([95, 145, 0])], message: "Cannot have a y constrained angle of 180 degrees" }"#
r#"type: KclErrorDetails { source_ranges: [SourceRange([95, 132, 0])], message: "Cannot have a y constrained angle of 180 degrees" }"#
);
}
@ -1958,9 +1961,9 @@ async fn kcl_test_angled_line_of_y_length_negative_180() {
let code = r#"exampleSketch = startSketchOn(XZ)
|> startProfileAt([0, 0], %)
|> line(end = [10, 0])
|> angledLineOfYLength({ angle: -180, length: 10 }, %)
|> angledLine(angle = -180, lengthY = 10)
|> line(end = [0, 10])
|> angledLineOfYLength({ angle: 135, length: 10 }, %)
|> angledLine(angle = 135, lengthY = 10)
|> line(end = [-10, 0])
|> line(end = [0, -30])
@ -1971,7 +1974,7 @@ example = extrude(exampleSketch, length = 10)
assert!(result.is_err());
assert_eq!(
result.err().unwrap().to_string(),
r#"type: KclErrorDetails { source_ranges: [SourceRange([95, 146, 0])], message: "Cannot have a y constrained angle of 180 degrees" }"#
r#"type: KclErrorDetails { source_ranges: [SourceRange([95, 133, 0])], message: "Cannot have a y constrained angle of 180 degrees" }"#
);
}