diff --git a/src/wasm-lib/kcl/src/executor.rs b/src/wasm-lib/kcl/src/executor.rs index c7077ff8c..1d66794e1 100644 --- a/src/wasm-lib/kcl/src/executor.rs +++ b/src/wasm-lib/kcl/src/executor.rs @@ -1121,7 +1121,7 @@ impl ExecutorContext { &self, program: crate::ast::types::Program, memory: &mut ProgramMemory, - _body_type: BodyType, + body_type: BodyType, ) -> Result { let pipe_info = PipeInfo::default(); @@ -1328,8 +1328,10 @@ impl ExecutorContext { } } - // Flush the batch queue. - self.engine.flush_batch(SourceRange([program.end, program.end])).await?; + if BodyType::Root == body_type { + // Flush the batch queue. + self.engine.flush_batch(SourceRange([program.end, program.end])).await?; + } Ok(memory.clone()) } diff --git a/src/wasm-lib/tests/executor/inputs/pentagon_fillet_desugar.kcl b/src/wasm-lib/tests/executor/inputs/pentagon_fillet_desugar.kcl deleted file mode 100644 index 3b9ec38ac..000000000 --- a/src/wasm-lib/tests/executor/inputs/pentagon_fillet_desugar.kcl +++ /dev/null @@ -1,42 +0,0 @@ -fn make_circle = (face, tag, pos, radius) => { - const sg0 = startSketchOn(face, tag) - const sg1 = startProfileAt([pos[0] + radius, pos[1]], sg0) - const sg2 = arc({ - angle_end: 360, - angle_start: 0, - radius: radius - }, sg1, 'arc-' + tag) - return close(sg2) -} - -fn pentagon = (len) => { - const sg3 = startSketchOn('XY') - const sg4 = startProfileAt([-len / 2, -len / 2], sg3) - const sg5 = angledLine({ angle: 0, length: len }, sg4, 'a') - const sg6 = angledLine({ - angle: segAng('a', sg5) + 180 - 108, - length: len - },sg5, 'b') - const sg7 = angledLine({ - angle: segAng('b', sg6) + 180 - 108, - length: len - }, sg6, 'c') - const sg8 = angledLine({ - angle: segAng('c', sg7) + 180 - 108, - length: len - }, sg7, 'd') - return angledLine({ - angle: segAng('d', sg8) + 180 - 108, - length: len - }, sg8) -} - -const p = pentagon(48) -const pe = extrude(30, p) - -const plumbus0 = make_circle(pe, 'a', [0, 0], 9) -const plumbus1 = extrude(18, plumbus0) -const plumbus2 = fillet({ - radius: 0.5, - tags: ['arc-a', getOppositeEdge('arc-a', plumbus1)] - }, plumbus1) diff --git a/src/wasm-lib/tests/executor/inputs/pentagon_fillet_sugar.kcl b/src/wasm-lib/tests/executor/inputs/pentagon_fillet_sugar.kcl index 623c60de2..32d0d5c33 100644 --- a/src/wasm-lib/tests/executor/inputs/pentagon_fillet_sugar.kcl +++ b/src/wasm-lib/tests/executor/inputs/pentagon_fillet_sugar.kcl @@ -1,46 +1,41 @@ -fn make_circle = (face, tag, pos, radius) => { - const sg = startSketchOn(face, tag) - |> startProfileAt([pos[0] + radius, pos[1]], %) - |> arc({ - angle_end: 360, - angle_start: 0, - radius: radius - }, %, 'arc-' + tag) - |> close(%) - - return sg +fn triangle = (len) => { + return startSketchOn('XY') + |> startProfileAt([0, 0], %) + |> angledLine({angle: 60, length: len}, %, 'a') + |> angledLine({angle: 180, length: len}, %, 'b') + |> angledLine({angle: 300, length: len}, %, 'c') } -fn pentagon = (len) => { - const 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 +let triangleHeight = 200 +let plumbusLen = 100 +let radius = 80 +let circ = {angle_start: 0, angle_end: 360, radius: radius} + +let triangleLen = 500 +const p = triangle(triangleLen) + |> extrude(triangleHeight, %) + +fn circl = (x, tag) => { +return startSketchOn(p, tag) + |> startProfileAt([x + radius, triangleHeight/2], %) + |> arc(circ, %, 'arc-' + tag) + |> close(%) +} + +const plumbus1 = + circl(-200, 'c') + |> extrude(plumbusLen, %) + |> fillet({ + radius: 5, + tags: ['arc-c', getOppositeEdge('arc-c', %)] }, %) - return sg -} - -const p = pentagon(48) - |> extrude(30, %) - -const plumbus0 = make_circle(p, 'a', [0, 0], 9) - |> extrude(18, %) +const plumbus0 = + circl(200, 'a') + |> extrude(plumbusLen, %) |> fillet({ - radius: 0.5, + radius: 5, tags: ['arc-a', getOppositeEdge('arc-a', %)] }, %) + + diff --git a/src/wasm-lib/tests/executor/main.rs b/src/wasm-lib/tests/executor/main.rs index 199793dae..26f85fc60 100644 --- a/src/wasm-lib/tests/executor/main.rs +++ b/src/wasm-lib/tests/executor/main.rs @@ -128,15 +128,6 @@ async fn serial_test_lego() { twenty_twenty::assert_image("tests/executor/outputs/lego.png", &result, 0.999); } -#[tokio::test(flavor = "multi_thread")] -async fn serial_test_pentagon_fillet_desugar() { - let code = include_str!("inputs/pentagon_fillet_desugar.kcl"); - let result = execute_and_snapshot(code, kcl_lib::settings::types::UnitLength::Cm) - .await - .unwrap(); - twenty_twenty::assert_image("tests/executor/outputs/pentagon_fillet_desugar.png", &result, 0.999); -} - #[tokio::test(flavor = "multi_thread")] async fn serial_test_pentagon_fillet_sugar() { let code = include_str!("inputs/pentagon_fillet_sugar.kcl"); @@ -1955,12 +1946,12 @@ const plumbus0 = make_circle(p, 'a', [0, 0], 2.5) tags: ['arc-a', getOppositeEdge('arc-a', %)] }, %) -// const plumbus1 = make_circle(p, 'b', [0, 0], 2.5) -// |> extrude(10, %) -// |> fillet({ -// radius: 0.5, -// tags: ['arc-b', getOppositeEdge('arc-b', %)] -// }, %) +const plumbus1 = make_circle(p, 'b', [0, 0], 2.5) + |> extrude(10, %) + |> fillet({ + radius: 0.5, + tags: ['arc-b', getOppositeEdge('arc-b', %)] + }, %) "#; let result = execute_and_snapshot(code, kcl_lib::settings::types::UnitLength::Mm) diff --git a/src/wasm-lib/tests/executor/outputs/pentagon_fillet_desugar.png b/src/wasm-lib/tests/executor/outputs/pentagon_fillet_desugar.png deleted file mode 100644 index 297821f17..000000000 Binary files a/src/wasm-lib/tests/executor/outputs/pentagon_fillet_desugar.png and /dev/null differ diff --git a/src/wasm-lib/tests/executor/outputs/pentagon_fillet_sugar.png b/src/wasm-lib/tests/executor/outputs/pentagon_fillet_sugar.png index 297821f17..e3db6ad60 100644 Binary files a/src/wasm-lib/tests/executor/outputs/pentagon_fillet_sugar.png and b/src/wasm-lib/tests/executor/outputs/pentagon_fillet_sugar.png differ diff --git a/src/wasm-lib/tests/executor/outputs/plumbus_fillets.png b/src/wasm-lib/tests/executor/outputs/plumbus_fillets.png index 1a890b919..018b202c8 100644 Binary files a/src/wasm-lib/tests/executor/outputs/plumbus_fillets.png and b/src/wasm-lib/tests/executor/outputs/plumbus_fillets.png differ