Pipelines cause Z-fighting (#1976)
Bug: You can see here that the two programs under tests/ are equivalent, just one uses pipelines and one always assigns to a new sketchgroup. However, the pipeline produces weird visual bugs. Jess did a git bisect to figure out this was the problem that Mike was experiencing, around weird visual artifacts with filleting. Ultimately the bug was that my rewritten `execute_pipe_body` function was executing the first expression of the pipeline body twice! In most unit tests this didn't matter, because the first expression in a pipeline was startSketchAt. No big deal to run that twice. However, in Mike's program, the first expression was `make_circle` or `pentagon`, user-defined functions that sent a lot of API calls. This meant the pipeline duplicated a lot of geometry, causing Z-fighting and weird artifacts.
@ -0,0 +1,42 @@
|
||||
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)
|
46
src/wasm-lib/tests/executor/inputs/pentagon_fillet_sugar.kcl
Normal file
@ -0,0 +1,46 @@
|
||||
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 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
|
||||
}, %)
|
||||
|
||||
return sg
|
||||
}
|
||||
|
||||
const p = pentagon(48)
|
||||
|> extrude(30, %)
|
||||
|
||||
const plumbus0 = make_circle(p, 'a', [0, 0], 9)
|
||||
|> extrude(18, %)
|
||||
|> fillet({
|
||||
radius: 0.5,
|
||||
tags: ['arc-a', getOppositeEdge('arc-a', %)]
|
||||
}, %)
|
@ -111,16 +111,34 @@ const part002 = startSketchOn(part001, "here")
|
||||
.unwrap();
|
||||
twenty_twenty::assert_image("tests/executor/outputs/sketch_on_face.png", &result, 0.999);
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
async fn serial_test_riddle_small() {
|
||||
let code = include_str!("inputs/riddle_small.kcl");
|
||||
|
||||
let result = execute_and_snapshot(code, kittycad::types::UnitLength::Mm)
|
||||
.await
|
||||
.unwrap();
|
||||
twenty_twenty::assert_image("tests/executor/outputs/riddle_small.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, kittycad::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");
|
||||
let result = execute_and_snapshot(code, kittycad::types::UnitLength::Cm)
|
||||
.await
|
||||
.unwrap();
|
||||
twenty_twenty::assert_image("tests/executor/outputs/pentagon_fillet_sugar.png", &result, 0.999);
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
async fn serial_test_sketch_on_face_start() {
|
||||
let code = r#"fn cube = (pos, scale) => {
|
||||
@ -1898,12 +1916,12 @@ const plumbus0 = make_circle(p, 'a', [0, 0], 1.5)
|
||||
tags: ['arc-a', getOppositeEdge('arc-a', %)]
|
||||
}, %)
|
||||
|
||||
const plumbus1 = make_circle(p, 'b', [0, 0], 1.5)
|
||||
|> extrude(3, %)
|
||||
|> fillet({
|
||||
radius: 0.5,
|
||||
tags: ['arc-b', getOppositeEdge('arc-b', %)]
|
||||
}, %)
|
||||
// const plumbus1 = make_circle(p, 'b', [0, 0], 1.5)
|
||||
// |> extrude(3, %)
|
||||
// |> fillet({
|
||||
// radius: 0.5,
|
||||
// tags: ['arc-b', getOppositeEdge('arc-b', %)]
|
||||
// }, %)
|
||||
"#;
|
||||
|
||||
let result = execute_and_snapshot(code, kittycad::types::UnitLength::Mm)
|
||||
|
Before Width: | Height: | Size: 125 KiB After Width: | Height: | Size: 125 KiB |
Before Width: | Height: | Size: 95 KiB After Width: | Height: | Size: 95 KiB |
BIN
src/wasm-lib/tests/executor/outputs/pentagon_fillet_desugar.png
Normal file
After Width: | Height: | Size: 166 KiB |
BIN
src/wasm-lib/tests/executor/outputs/pentagon_fillet_sugar.png
Normal file
After Width: | Height: | Size: 166 KiB |
Before Width: | Height: | Size: 101 KiB After Width: | Height: | Size: 98 KiB |
Before Width: | Height: | Size: 100 KiB After Width: | Height: | Size: 100 KiB |
Before Width: | Height: | Size: 114 KiB After Width: | Height: | Size: 114 KiB |
Before Width: | Height: | Size: 114 KiB After Width: | Height: | Size: 114 KiB |
Before Width: | Height: | Size: 111 KiB After Width: | Height: | Size: 111 KiB |
Before Width: | Height: | Size: 110 KiB After Width: | Height: | Size: 109 KiB |
Before Width: | Height: | Size: 112 KiB After Width: | Height: | Size: 111 KiB |
Before Width: | Height: | Size: 112 KiB After Width: | Height: | Size: 112 KiB |
Before Width: | Height: | Size: 95 KiB After Width: | Height: | Size: 95 KiB |
Before Width: | Height: | Size: 95 KiB After Width: | Height: | Size: 95 KiB |
Before Width: | Height: | Size: 95 KiB After Width: | Height: | Size: 95 KiB |