Simplify the pentagon test (#2474)

* plumbus fixes

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* Simplify the pentagon test

* Fix up triangle png

* Triangle plumbuses now face the camera

---------

Signed-off-by: Jess Frazelle <github@jessfraz.com>
Co-authored-by: Jess Frazelle <github@jessfraz.com>
This commit is contained in:
Adam Chalmers
2024-05-22 18:50:54 -05:00
committed by GitHub
parent e3b9a6e5d8
commit 97faf5ae2b
7 changed files with 45 additions and 99 deletions

View File

@ -1121,7 +1121,7 @@ impl ExecutorContext {
&self, &self,
program: crate::ast::types::Program, program: crate::ast::types::Program,
memory: &mut ProgramMemory, memory: &mut ProgramMemory,
_body_type: BodyType, body_type: BodyType,
) -> Result<ProgramMemory, KclError> { ) -> Result<ProgramMemory, KclError> {
let pipe_info = PipeInfo::default(); let pipe_info = PipeInfo::default();
@ -1328,8 +1328,10 @@ impl ExecutorContext {
} }
} }
// Flush the batch queue. if BodyType::Root == body_type {
self.engine.flush_batch(SourceRange([program.end, program.end])).await?; // Flush the batch queue.
self.engine.flush_batch(SourceRange([program.end, program.end])).await?;
}
Ok(memory.clone()) Ok(memory.clone())
} }

View File

@ -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)

View File

@ -1,46 +1,41 @@
fn make_circle = (face, tag, pos, radius) => { fn triangle = (len) => {
const sg = startSketchOn(face, tag) return startSketchOn('XY')
|> startProfileAt([pos[0] + radius, pos[1]], %) |> startProfileAt([0, 0], %)
|> arc({ |> angledLine({angle: 60, length: len}, %, 'a')
angle_end: 360, |> angledLine({angle: 180, length: len}, %, 'b')
angle_start: 0, |> angledLine({angle: 300, length: len}, %, 'c')
radius: radius
}, %, 'arc-' + tag)
|> close(%)
return sg
} }
fn pentagon = (len) => { let triangleHeight = 200
const sg = startSketchOn('XY') let plumbusLen = 100
|> startProfileAt([-len / 2, -len / 2], %) let radius = 80
|> angledLine({ angle: 0, length: len }, %, 'a') let circ = {angle_start: 0, angle_end: 360, radius: radius}
|> angledLine({
angle: segAng('a', %) + 180 - 108, let triangleLen = 500
length: len const p = triangle(triangleLen)
}, %, 'b') |> extrude(triangleHeight, %)
|> angledLine({
angle: segAng('b', %) + 180 - 108, fn circl = (x, tag) => {
length: len return startSketchOn(p, tag)
}, %, 'c') |> startProfileAt([x + radius, triangleHeight/2], %)
|> angledLine({ |> arc(circ, %, 'arc-' + tag)
angle: segAng('c', %) + 180 - 108, |> close(%)
length: len }
}, %, 'd')
|> angledLine({ const plumbus1 =
angle: segAng('d', %) + 180 - 108, circl(-200, 'c')
length: len |> extrude(plumbusLen, %)
|> fillet({
radius: 5,
tags: ['arc-c', getOppositeEdge('arc-c', %)]
}, %) }, %)
return sg const plumbus0 =
} circl(200, 'a')
|> extrude(plumbusLen, %)
const p = pentagon(48)
|> extrude(30, %)
const plumbus0 = make_circle(p, 'a', [0, 0], 9)
|> extrude(18, %)
|> fillet({ |> fillet({
radius: 0.5, radius: 5,
tags: ['arc-a', getOppositeEdge('arc-a', %)] tags: ['arc-a', getOppositeEdge('arc-a', %)]
}, %) }, %)

View File

@ -128,15 +128,6 @@ async fn serial_test_lego() {
twenty_twenty::assert_image("tests/executor/outputs/lego.png", &result, 0.999); 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")] #[tokio::test(flavor = "multi_thread")]
async fn serial_test_pentagon_fillet_sugar() { async fn serial_test_pentagon_fillet_sugar() {
let code = include_str!("inputs/pentagon_fillet_sugar.kcl"); 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', %)] tags: ['arc-a', getOppositeEdge('arc-a', %)]
}, %) }, %)
// const plumbus1 = make_circle(p, 'b', [0, 0], 2.5) const plumbus1 = make_circle(p, 'b', [0, 0], 2.5)
// |> extrude(10, %) |> extrude(10, %)
// |> fillet({ |> fillet({
// radius: 0.5, radius: 0.5,
// tags: ['arc-b', getOppositeEdge('arc-b', %)] tags: ['arc-b', getOppositeEdge('arc-b', %)]
// }, %) }, %)
"#; "#;
let result = execute_and_snapshot(code, kcl_lib::settings::types::UnitLength::Mm) let result = execute_and_snapshot(code, kcl_lib::settings::types::UnitLength::Mm)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 100 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 100 KiB

After

Width:  |  Height:  |  Size: 95 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 127 KiB

After

Width:  |  Height:  |  Size: 133 KiB