Add more tests for sweep sectional (#5930)
* Add more tests for sweep sectional * A snapshot a day keeps the bugs away! 📷🐛 * Add rust doc test for sectional * A snapshot a day keeps the bugs away! 📷🐛 * Ran redo-kcl-stdlib-docs * A snapshot a day keeps the bugs away! 📷🐛 --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
This commit is contained in:
@ -311371,7 +311371,8 @@
|
|||||||
"examples": [
|
"examples": [
|
||||||
"// Create a pipe using a sweep.\n\n// Create a path for the sweep.\nsweepPath = startSketchOn(XZ)\n |> startProfileAt([0.05, 0.05], %)\n |> line(end = [0, 7])\n |> tangentialArc({ offset = 90, radius = 5 }, %)\n |> line(end = [-3, 0])\n |> tangentialArc({ offset = -90, radius = 5 }, %)\n |> line(end = [0, 7])\n\n// Create a hole for the pipe.\npipeHole = startSketchOn(XY)\n |> circle(center = [0, 0], radius = 1.5)\n\nsweepSketch = startSketchOn(XY)\n |> circle(center = [0, 0], radius = 2)\n |> hole(pipeHole, %)\n |> sweep(path = sweepPath)",
|
"// Create a pipe using a sweep.\n\n// Create a path for the sweep.\nsweepPath = startSketchOn(XZ)\n |> startProfileAt([0.05, 0.05], %)\n |> line(end = [0, 7])\n |> tangentialArc({ offset = 90, radius = 5 }, %)\n |> line(end = [-3, 0])\n |> tangentialArc({ offset = -90, radius = 5 }, %)\n |> line(end = [0, 7])\n\n// Create a hole for the pipe.\npipeHole = startSketchOn(XY)\n |> circle(center = [0, 0], radius = 1.5)\n\nsweepSketch = startSketchOn(XY)\n |> circle(center = [0, 0], radius = 2)\n |> hole(pipeHole, %)\n |> sweep(path = sweepPath)",
|
||||||
"// Create a spring by sweeping around a helix path.\n\n// Create a helix around the Z axis.\nhelixPath = helix(\n angleStart = 0,\n ccw = true,\n revolutions = 4,\n length = 10,\n radius = 5,\n axis = 'Z',\n)\n\n// Create a spring by sweeping around the helix path.\nspringSketch = startSketchOn(YZ)\n |> circle(center = [0, 0], radius = 1)\n |> sweep(path = helixPath)",
|
"// Create a spring by sweeping around a helix path.\n\n// Create a helix around the Z axis.\nhelixPath = helix(\n angleStart = 0,\n ccw = true,\n revolutions = 4,\n length = 10,\n radius = 5,\n axis = 'Z',\n)\n\n// Create a spring by sweeping around the helix path.\nspringSketch = startSketchOn(YZ)\n |> circle(center = [0, 0], radius = 1)\n |> sweep(path = helixPath)",
|
||||||
"// Sweep two sketches along the same path.\n\n\nsketch001 = startSketchOn(XY)\nrectangleSketch = startProfileAt([-200, 23.86], sketch001)\n |> angledLine([0, 73.47], %, $rectangleSegmentA001)\n |> angledLine([\n segAng(rectangleSegmentA001) - 90,\n 50.61\n ], %)\n |> angledLine([\n segAng(rectangleSegmentA001),\n -segLen(rectangleSegmentA001)\n ], %)\n |> line(endAbsolute = [profileStartX(%), profileStartY(%)])\n |> close()\n\ncircleSketch = circle(sketch001, center = [200, -30.29], radius = 32.63)\n\nsketch002 = startSketchOn(YZ)\nsweepPath = startProfileAt([0, 0], sketch002)\n |> yLine(length = 231.81)\n |> tangentialArc({ radius = 80, offset = -90 }, %)\n |> xLine(length = 384.93)\n\nsweep([rectangleSketch, circleSketch], path = sweepPath)"
|
"// Sweep two sketches along the same path.\n\n\nsketch001 = startSketchOn(XY)\nrectangleSketch = startProfileAt([-200, 23.86], sketch001)\n |> angledLine([0, 73.47], %, $rectangleSegmentA001)\n |> angledLine([\n segAng(rectangleSegmentA001) - 90,\n 50.61\n ], %)\n |> angledLine([\n segAng(rectangleSegmentA001),\n -segLen(rectangleSegmentA001)\n ], %)\n |> line(endAbsolute = [profileStartX(%), profileStartY(%)])\n |> close()\n\ncircleSketch = circle(sketch001, center = [200, -30.29], radius = 32.63)\n\nsketch002 = startSketchOn(YZ)\nsweepPath = startProfileAt([0, 0], sketch002)\n |> yLine(length = 231.81)\n |> tangentialArc({ radius = 80, offset = -90 }, %)\n |> xLine(length = 384.93)\n\nsweep([rectangleSketch, circleSketch], path = sweepPath)",
|
||||||
|
"// Sectionally sweep one sketch along the path\n\n\nsketch001 = startSketchOn(XY)\ncircleSketch = circle(sketch001, center = [200, -30.29], radius = 32.63)\n\nsketch002 = startSketchOn(YZ)\nsweepPath = startProfileAt([0, 0], sketch002)\n |> yLine(length = 231.81)\n |> tangentialArc({ radius = 80, offset = -90 }, %)\n |> xLine(length = 384.93)\n\nsweep(circleSketch, path = sweepPath, sectional = true)"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
File diff suppressed because one or more lines are too long
@ -1336,7 +1336,41 @@ loft001 = loft([sketch001, sketch002])
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
test(`Sweep point-and-click base`, async ({
|
const sweepCases = [
|
||||||
|
{
|
||||||
|
targetType: 'circle',
|
||||||
|
testPoint: { x: 700, y: 250 },
|
||||||
|
initialCode: `sketch001 = startSketchOn('YZ')
|
||||||
|
profile001 = circle(sketch001, center = [0, 0], radius = 500)
|
||||||
|
sketch002 = startSketchOn('XZ')
|
||||||
|
|> startProfileAt([0, 0], %)
|
||||||
|
|> xLine(length = -500)
|
||||||
|
|> tangentialArcTo([-2000, 500], %)`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
targetType: 'rectangle',
|
||||||
|
testPoint: { x: 710, y: 255 },
|
||||||
|
initialCode: `sketch001 = startSketchOn('YZ')
|
||||||
|
profile001 = startProfileAt([-400, -400], sketch001)
|
||||||
|
|> angledLine([0, 800], %, $rectangleSegmentA001)
|
||||||
|
|> angledLine([
|
||||||
|
segAng(rectangleSegmentA001) + 90,
|
||||||
|
800
|
||||||
|
], %)
|
||||||
|
|> angledLine([
|
||||||
|
segAng(rectangleSegmentA001),
|
||||||
|
-segLen(rectangleSegmentA001)
|
||||||
|
], %)
|
||||||
|
|> line(endAbsolute = [profileStartX(%), profileStartY(%)])
|
||||||
|
|> close()
|
||||||
|
sketch002 = startSketchOn('XZ')
|
||||||
|
|> startProfileAt([0, 0], %)
|
||||||
|
|> xLine(length = -500)
|
||||||
|
|> tangentialArcTo([-2000, 500], %)`,
|
||||||
|
},
|
||||||
|
]
|
||||||
|
sweepCases.map(({ initialCode, targetType, testPoint }) => {
|
||||||
|
test(`Sweep point-and-click ${targetType}`, async ({
|
||||||
context,
|
context,
|
||||||
page,
|
page,
|
||||||
homePage,
|
homePage,
|
||||||
@ -1345,16 +1379,6 @@ loft001 = loft([sketch001, sketch002])
|
|||||||
toolbar,
|
toolbar,
|
||||||
cmdBar,
|
cmdBar,
|
||||||
}) => {
|
}) => {
|
||||||
const initialCode = `sketch001 = startSketchOn(YZ)
|
|
||||||
|> circle(
|
|
||||||
center = [0, 0],
|
|
||||||
radius = 500
|
|
||||||
)
|
|
||||||
sketch002 = startSketchOn(XZ)
|
|
||||||
|> startProfileAt([0, 0], %)
|
|
||||||
|> xLine(length = -500)
|
|
||||||
|> tangentialArcTo([-2000, 500], %)
|
|
||||||
`
|
|
||||||
await context.addInitScript((initialCode) => {
|
await context.addInitScript((initialCode) => {
|
||||||
localStorage.setItem('persistCode', initialCode)
|
localStorage.setItem('persistCode', initialCode)
|
||||||
}, initialCode)
|
}, initialCode)
|
||||||
@ -1363,16 +1387,15 @@ sketch002 = startSketchOn(XZ)
|
|||||||
await scene.waitForExecutionDone()
|
await scene.waitForExecutionDone()
|
||||||
|
|
||||||
// One dumb hardcoded screen pixel value
|
// One dumb hardcoded screen pixel value
|
||||||
const testPoint = { x: 700, y: 250 }
|
|
||||||
const [clickOnSketch1] = scene.makeMouseHelpers(testPoint.x, testPoint.y)
|
const [clickOnSketch1] = scene.makeMouseHelpers(testPoint.x, testPoint.y)
|
||||||
const [clickOnSketch2] = scene.makeMouseHelpers(
|
const [clickOnSketch2] = scene.makeMouseHelpers(
|
||||||
testPoint.x - 50,
|
testPoint.x - 50,
|
||||||
testPoint.y
|
testPoint.y
|
||||||
)
|
)
|
||||||
const sweepDeclaration =
|
const sweepDeclaration =
|
||||||
'sweep001 = sweep(sketch001, path = sketch002, sectional = false)'
|
'sweep001 = sweep(profile001, path = sketch002, sectional = false)'
|
||||||
const editedSweepDeclaration =
|
const editedSweepDeclaration =
|
||||||
'sweep001 = sweep(sketch001, path = sketch002, sectional = true)'
|
'sweep001 = sweep(profile001, path = sketch002, sectional = true)'
|
||||||
|
|
||||||
await test.step(`Look for sketch001`, async () => {
|
await test.step(`Look for sketch001`, async () => {
|
||||||
await toolbar.closePane('code')
|
await toolbar.closePane('code')
|
||||||
@ -1424,12 +1447,16 @@ sketch002 = startSketchOn(XZ)
|
|||||||
await test.step(`Confirm code is added to the editor, scene has changed`, async () => {
|
await test.step(`Confirm code is added to the editor, scene has changed`, async () => {
|
||||||
await toolbar.openPane('code')
|
await toolbar.openPane('code')
|
||||||
await editor.expectEditor.toContain(sweepDeclaration)
|
await editor.expectEditor.toContain(sweepDeclaration)
|
||||||
|
await scene.expectPixelColor([120, 120, 120], testPoint, 40)
|
||||||
await toolbar.closePane('code')
|
await toolbar.closePane('code')
|
||||||
})
|
})
|
||||||
|
|
||||||
await test.step('Edit sweep via feature tree selection works', async () => {
|
await test.step('Edit sweep via feature tree selection works', async () => {
|
||||||
await toolbar.openPane('feature-tree')
|
await toolbar.openPane('feature-tree')
|
||||||
const operationButton = await toolbar.getFeatureTreeOperation('Sweep', 0)
|
const operationButton = await toolbar.getFeatureTreeOperation(
|
||||||
|
'Sweep',
|
||||||
|
0
|
||||||
|
)
|
||||||
await operationButton.dblclick({ button: 'left' })
|
await operationButton.dblclick({ button: 'left' })
|
||||||
await cmdBar.expectState({
|
await cmdBar.expectState({
|
||||||
commandName: 'Sweep',
|
commandName: 'Sweep',
|
||||||
@ -1459,7 +1486,10 @@ sketch002 = startSketchOn(XZ)
|
|||||||
await test.step('Delete sweep via feature tree selection', async () => {
|
await test.step('Delete sweep via feature tree selection', async () => {
|
||||||
await toolbar.openPane('feature-tree')
|
await toolbar.openPane('feature-tree')
|
||||||
await page.waitForTimeout(500)
|
await page.waitForTimeout(500)
|
||||||
const operationButton = await toolbar.getFeatureTreeOperation('Sweep', 0)
|
const operationButton = await toolbar.getFeatureTreeOperation(
|
||||||
|
'Sweep',
|
||||||
|
0
|
||||||
|
)
|
||||||
await operationButton.click({ button: 'left' })
|
await operationButton.click({ button: 'left' })
|
||||||
await page.keyboard.press('Delete')
|
await page.keyboard.press('Delete')
|
||||||
await page.waitForTimeout(500)
|
await page.waitForTimeout(500)
|
||||||
@ -1467,6 +1497,7 @@ sketch002 = startSketchOn(XZ)
|
|||||||
await scene.expectPixelColor([53, 53, 53], testPoint, 15)
|
await scene.expectPixelColor([53, 53, 53], testPoint, 15)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
})
|
||||||
|
|
||||||
test(`Sweep point-and-click failing validation`, async ({
|
test(`Sweep point-and-click failing validation`, async ({
|
||||||
context,
|
context,
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 65 KiB After Width: | Height: | Size: 65 KiB |
Binary file not shown.
Before Width: | Height: | Size: 68 KiB After Width: | Height: | Size: 68 KiB |
@ -134,6 +134,25 @@ pub async fn sweep(exec_state: &mut ExecState, args: Args) -> Result<KclValue, K
|
|||||||
///
|
///
|
||||||
/// sweep([rectangleSketch, circleSketch], path = sweepPath)
|
/// sweep([rectangleSketch, circleSketch], path = sweepPath)
|
||||||
/// ```
|
/// ```
|
||||||
|
/// ```
|
||||||
|
/// // Sectionally sweep one sketch along the path
|
||||||
|
///
|
||||||
|
/// sketch001 = startSketchOn('XY')
|
||||||
|
/// circleSketch = circle(sketch001, center = [200, -30.29], radius = 32.63)
|
||||||
|
///
|
||||||
|
/// sketch002 = startSketchOn('YZ')
|
||||||
|
/// sweepPath = startProfileAt([0, 0], sketch002)
|
||||||
|
/// |> yLine(length = 231.81)
|
||||||
|
/// |> tangentialArc({
|
||||||
|
/// radius = 80,
|
||||||
|
/// offset = -90,
|
||||||
|
/// }, %)
|
||||||
|
/// |> xLine(length = 384.93)
|
||||||
|
///
|
||||||
|
/// sweep(circleSketch, path = sweepPath, sectional = true)
|
||||||
|
/// ```
|
||||||
|
///
|
||||||
|
|
||||||
#[stdlib {
|
#[stdlib {
|
||||||
name = "sweep",
|
name = "sweep",
|
||||||
feature_tree_operation = true,
|
feature_tree_operation = true,
|
||||||
|
BIN
rust/kcl-lib/tests/outputs/serial_test_example_sweep3.png
Normal file
BIN
rust/kcl-lib/tests/outputs/serial_test_example_sweep3.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 65 KiB |
Reference in New Issue
Block a user