Move KCL programs into their own files (#3200)

* Move KCL programs into their own files

* Move even more
This commit is contained in:
Adam Chalmers
2024-07-31 15:07:56 -05:00
committed by GitHub
parent 1684786659
commit dc21034b86
12 changed files with 132 additions and 134 deletions

View File

@ -0,0 +1,9 @@
const part001 = startSketchOn('XY')
|> startProfileAt([4.83, 12.56], %)
|> line([15.1, 2.48], %)
|> line([3.15, -9.85], %, $seg01)
|> line([-15.17, -4.1], %)
|> angledLine([segAng(seg01), 12.35], %)
|> line([-13.02, 10.03], %)
|> close(%)
|> extrude(4, %)

View File

@ -0,0 +1,9 @@
const center = [0,0]
const radius = 40
const height = 3
const body = startSketchOn('XY')
|> startProfileAt([center[0]+radius, center[1]], %)
|> arc({angle_end: 360, angle_start: 0, radius: radius}, %)
|> close(%)
|> extrude(height, %)

View File

@ -0,0 +1,7 @@
const part001 = startSketchOn('XY')
|> startProfileAt([-10, -10], %)
|> line([20, 0], %)
|> line([0, 20], %)
|> line([-20, 0], %)
|> close(%)
|> extrude(10, %)

View File

@ -0,0 +1,4 @@
const part001 = startSketchOn('XY')
|> circle([5, 5], 10, %)
|> extrude(10, %)
|> helix({revolutions: 16, angle_start: 0, ccw: true}, %)

View File

@ -0,0 +1,4 @@
const part001 = startSketchOn('XY')
|> circle([5, 5], 10, %)
|> extrude(10, %)
|> helix({revolutions: 16, angle_start: 0}, %)

View File

@ -0,0 +1,4 @@
const part001 = startSketchOn('XY')
|> circle([5, 5], 10, %)
|> extrude(-10, %)
|> helix({revolutions: 16, angle_start: 0}, %)

View File

@ -0,0 +1,4 @@
const part001 = startSketchOn('XY')
|> circle([5, 5], 10, %)
|> extrude(10, %)
|> helix({revolutions: 16, angle_start: 0, length: 3}, %)

View File

@ -0,0 +1,17 @@
fn cube = (pos, scale) => {
const sg = startSketchOn('XY')
|> startProfileAt(pos, %)
|> line([0, scale], %)
|> line([scale, 0], %)
|> line([0, -scale], %)
|> close(%)
return sg
}
const b1 = cube([0,0], 10)
const b2 = cube([3,3], 4)
|> extrude(10, %)
const pt1 = b1.value[0]
const pt2 = b2.value[0]

View File

@ -0,0 +1,19 @@
const width = 5
const height = 10
const length = 12
fn box = (sk1, sk2, scale) => {
const boxSketch = startSketchOn('XY')
|> startProfileAt([sk1, sk2], %)
|> line([0, scale], %)
|> line([scale, 0], %)
|> line([0, -scale], %)
|> close(%)
|> extrude(scale, %)
return boxSketch
}
box(0, 0, 5)
box(10, 23, 8)
let thing = box(-12, -15, 10)
box(-20, -5, 10)

View File

@ -0,0 +1,18 @@
const sigmaAllow = 35000 // psi
const width = 9 // inch
const p = 150 // Force on shelf - lbs
const distance = 6 // inches
const FOS = 2
const leg1 = 5 // inches
const leg2 = 8 // inches
const thickness = sqrt(distance * p * FOS * 6 / sigmaAllow / width) // inches
const bracket = startSketchOn('XY')
|> startProfileAt([0, 0], %)
|> line([0, leg1], %)
|> line([leg2, 0], %)
|> line([0, -thickness], %)
|> line([-leg2 + thickness, 0], %)
|> line([0, -leg1 + thickness], %)
|> close(%)
|> extrude(width, %)

View File

@ -0,0 +1,26 @@
const sigmaAllow = 15000 // psi
const width = 11 // inch
const p = 150 // Force on shelf - lbs
const distance = 12 // inches
const FOS = 2
const thickness = sqrt(distance * p * FOS * 6 / ( sigmaAllow * width ))
const filletR = thickness * 2
const shelfMountL = 9
const wallMountL = 8
const bracket = startSketchAt([0, 0])
|> line([0, wallMountL], %)
|> tangentialArc({
radius: filletR,
offset: 90
}, %)
|> line([-shelfMountL, 0], %)
|> line([0, -thickness], %)
|> line([shelfMountL, 0], %)
|> tangentialArc({
radius: filletR - thickness,
offset: -90
}, %)
|> line([0, -wallMountL], %)
|> close(%)
|> extrude(width, %)

View File

@ -150,77 +150,21 @@ async fn kcl_test_execute_with_function_sketch_with_position() {
#[tokio::test(flavor = "multi_thread")] #[tokio::test(flavor = "multi_thread")]
async fn kcl_test_execute_with_angled_line() { async fn kcl_test_execute_with_angled_line() {
let code = r#"const part001 = startSketchOn('XY') let code = kcl_input!("angled_line");
|> startProfileAt([4.83, 12.56], %)
|> line([15.1, 2.48], %)
|> line([3.15, -9.85], %, $seg01)
|> line([-15.17, -4.1], %)
|> angledLine([segAng(seg01), 12.35], %)
|> line([-13.02, 10.03], %)
|> close(%)
|> extrude(4, %)
"#;
let result = execute_and_snapshot(code, UnitLength::Mm).await.unwrap(); let result = execute_and_snapshot(code, UnitLength::Mm).await.unwrap();
assert_out("angled_line", &result); assert_out("angled_line", &result);
} }
#[tokio::test(flavor = "multi_thread")] #[tokio::test(flavor = "multi_thread")]
async fn kcl_test_execute_parametric_example() { async fn kcl_test_execute_parametric_example() {
let code = r#"const sigmaAllow = 35000 // psi let code = kcl_input!("parametric");
const width = 9 // inch
const p = 150 // Force on shelf - lbs
const distance = 6 // inches
const FOS = 2
const leg1 = 5 // inches
const leg2 = 8 // inches
const thickness = sqrt(distance * p * FOS * 6 / sigmaAllow / width) // inches
const bracket = startSketchOn('XY')
|> startProfileAt([0, 0], %)
|> line([0, leg1], %)
|> line([leg2, 0], %)
|> line([0, -thickness], %)
|> line([-leg2 + thickness, 0], %)
|> line([0, -leg1 + thickness], %)
|> close(%)
|> extrude(width, %)
"#;
let result = execute_and_snapshot(code, UnitLength::Mm).await.unwrap(); let result = execute_and_snapshot(code, UnitLength::Mm).await.unwrap();
assert_out("parametric", &result); assert_out("parametric", &result);
} }
#[tokio::test(flavor = "multi_thread")] #[tokio::test(flavor = "multi_thread")]
async fn kcl_test_execute_parametric_with_tan_arc_example() { async fn kcl_test_execute_parametric_with_tan_arc_example() {
let code = r#"const sigmaAllow = 15000 // psi let code = kcl_input!("parametric_with_tan_arc");
const width = 11 // inch
const p = 150 // Force on shelf - lbs
const distance = 12 // inches
const FOS = 2
const thickness = sqrt(distance * p * FOS * 6 / ( sigmaAllow * width ))
const filletR = thickness * 2
const shelfMountL = 9
const wallMountL = 8
const bracket = startSketchAt([0, 0])
|> line([0, wallMountL], %)
|> tangentialArc({
radius: filletR,
offset: 90
}, %)
|> line([-shelfMountL, 0], %)
|> line([0, -thickness], %)
|> line([shelfMountL, 0], %)
|> tangentialArc({
radius: filletR - thickness,
offset: -90
}, %)
|> line([0, -wallMountL], %)
|> close(%)
|> extrude(width, %)
"#;
let result = execute_and_snapshot(code, UnitLength::Mm).await.unwrap(); let result = execute_and_snapshot(code, UnitLength::Mm).await.unwrap();
assert_out("parametric_with_tan_arc", &result); assert_out("parametric_with_tan_arc", &result);
} }
@ -280,24 +224,7 @@ async fn kcl_test_execute_kittycad_svg() {
#[tokio::test(flavor = "multi_thread")] #[tokio::test(flavor = "multi_thread")]
async fn kcl_test_member_expression_sketch_group() { async fn kcl_test_member_expression_sketch_group() {
let code = r#"fn cube = (pos, scale) => { let code = kcl_input!("member_expression_sketch_group");
const sg = startSketchOn('XY')
|> startProfileAt(pos, %)
|> line([0, scale], %)
|> line([scale, 0], %)
|> line([0, -scale], %)
|> close(%)
return sg
}
const b1 = cube([0,0], 10)
const b2 = cube([3,3], 4)
|> extrude(10, %)
const pt1 = b1.value[0]
const pt2 = b2.value[0]
"#;
let result = execute_and_snapshot(code, UnitLength::Mm).await.unwrap(); let result = execute_and_snapshot(code, UnitLength::Mm).await.unwrap();
assert_out("member_expression_sketch_group", &result); assert_out("member_expression_sketch_group", &result);
@ -305,11 +232,7 @@ const pt2 = b2.value[0]
#[tokio::test(flavor = "multi_thread")] #[tokio::test(flavor = "multi_thread")]
async fn kcl_test_helix_defaults() { async fn kcl_test_helix_defaults() {
let code = r#"const part001 = startSketchOn('XY') let code = kcl_input!("helix_defaults");
|> circle([5, 5], 10, %)
|> extrude(10, %)
|> helix({revolutions: 16, angle_start: 0}, %)
"#;
let result = execute_and_snapshot(code, UnitLength::Mm).await.unwrap(); let result = execute_and_snapshot(code, UnitLength::Mm).await.unwrap();
assert_out("helix_defaults", &result); assert_out("helix_defaults", &result);
@ -317,11 +240,7 @@ async fn kcl_test_helix_defaults() {
#[tokio::test(flavor = "multi_thread")] #[tokio::test(flavor = "multi_thread")]
async fn kcl_test_helix_defaults_negative_extrude() { async fn kcl_test_helix_defaults_negative_extrude() {
let code = r#"const part001 = startSketchOn('XY') let code = kcl_input!("helix_defaults_negative_extrude");
|> circle([5, 5], 10, %)
|> extrude(-10, %)
|> helix({revolutions: 16, angle_start: 0}, %)
"#;
let result = execute_and_snapshot(code, UnitLength::Mm).await.unwrap(); let result = execute_and_snapshot(code, UnitLength::Mm).await.unwrap();
assert_out("helix_defaults_negative_extrude", &result); assert_out("helix_defaults_negative_extrude", &result);
@ -329,11 +248,7 @@ async fn kcl_test_helix_defaults_negative_extrude() {
#[tokio::test(flavor = "multi_thread")] #[tokio::test(flavor = "multi_thread")]
async fn kcl_test_helix_ccw() { async fn kcl_test_helix_ccw() {
let code = r#"const part001 = startSketchOn('XY') let code = kcl_input!("helix_ccw");
|> circle([5, 5], 10, %)
|> extrude(10, %)
|> helix({revolutions: 16, angle_start: 0, ccw: true}, %)
"#;
let result = execute_and_snapshot(code, UnitLength::Mm).await.unwrap(); let result = execute_and_snapshot(code, UnitLength::Mm).await.unwrap();
assert_out("helix_ccw", &result); assert_out("helix_ccw", &result);
@ -341,11 +256,7 @@ async fn kcl_test_helix_ccw() {
#[tokio::test(flavor = "multi_thread")] #[tokio::test(flavor = "multi_thread")]
async fn kcl_test_helix_with_length() { async fn kcl_test_helix_with_length() {
let code = r#"const part001 = startSketchOn('XY') let code = kcl_input!("helix_with_length");
|> circle([5, 5], 10, %)
|> extrude(10, %)
|> helix({revolutions: 16, angle_start: 0, length: 3}, %)
"#;
let result = execute_and_snapshot(code, UnitLength::Mm).await.unwrap(); let result = execute_and_snapshot(code, UnitLength::Mm).await.unwrap();
assert_out("helix_with_length", &result); assert_out("helix_with_length", &result);
@ -353,14 +264,7 @@ async fn kcl_test_helix_with_length() {
#[tokio::test(flavor = "multi_thread")] #[tokio::test(flavor = "multi_thread")]
async fn kcl_test_dimensions_match() { async fn kcl_test_dimensions_match() {
let code = r#"const part001 = startSketchOn('XY') let code = kcl_input!("dimensions_match");
|> startProfileAt([-10, -10], %)
|> line([20, 0], %)
|> line([0, 20], %)
|> line([-20, 0], %)
|> close(%)
|> extrude(10, %)
"#;
let result = execute_and_snapshot(code, UnitLength::Mm).await.unwrap(); let result = execute_and_snapshot(code, UnitLength::Mm).await.unwrap();
assert_out("dimensions_match", &result); assert_out("dimensions_match", &result);
@ -368,16 +272,7 @@ async fn kcl_test_dimensions_match() {
#[tokio::test(flavor = "multi_thread")] #[tokio::test(flavor = "multi_thread")]
async fn kcl_test_close_arc() { async fn kcl_test_close_arc() {
let code = r#"const center = [0,0] let code = kcl_input!("close_arc");
const radius = 40
const height = 3
const body = startSketchOn('XY')
|> startProfileAt([center[0]+radius, center[1]], %)
|> arc({angle_end: 360, angle_start: 0, radius: radius}, %)
|> close(%)
|> extrude(height, %)
"#;
let result = execute_and_snapshot(code, UnitLength::Mm).await.unwrap(); let result = execute_and_snapshot(code, UnitLength::Mm).await.unwrap();
assert_out("close_arc", &result); assert_out("close_arc", &result);
@ -385,25 +280,7 @@ const body = startSketchOn('XY')
#[tokio::test(flavor = "multi_thread")] #[tokio::test(flavor = "multi_thread")]
async fn kcl_test_negative_args() { async fn kcl_test_negative_args() {
let code = r#"const width = 5 let code = kcl_input!("negative_args");
const height = 10
const length = 12
fn box = (sk1, sk2, scale) => {
const boxSketch = startSketchOn('XY')
|> startProfileAt([sk1, sk2], %)
|> line([0, scale], %)
|> line([scale, 0], %)
|> line([0, -scale], %)
|> close(%)
|> extrude(scale, %)
return boxSketch
}
box(0, 0, 5)
box(10, 23, 8)
let thing = box(-12, -15, 10)
box(-20, -5, 10)"#;
let result = execute_and_snapshot(code, UnitLength::Mm).await.unwrap(); let result = execute_and_snapshot(code, UnitLength::Mm).await.unwrap();
assert_out("negative_args", &result); assert_out("negative_args", &result);