addNewSketchLn should close when latest point matches start (#479)

* addNewSketchLn should close when latest point matches start

* Fix types

* Include close in test case

* Add handling for continuing to sketch

* Fix types again

* close line edits (#523)

* add close to pipe

* undo some previous changes

---------

Co-authored-by: Kurt Hutten <k.hutten@protonmail.ch>
This commit is contained in:
Adam Sunderland
2023-09-14 09:34:37 -04:00
committed by GitHub
parent 66ba60dc8e
commit cdb4c36cf5
3 changed files with 111 additions and 18 deletions

View File

@ -4,6 +4,7 @@ import {
addNewSketchLn,
getYComponent,
getXComponent,
addCloseToPipe,
} from './sketch'
import { parser_wasm } from '../abstractSyntaxTree'
import { getNodePathFromSourceRange } from '../queryAst'
@ -146,7 +147,7 @@ show(mySketch001)`
const programMemory = await enginelessExecutor(ast)
const sourceStart = code.indexOf(lineToChange)
expect(sourceStart).toBe(66)
const { modifiedAst } = addNewSketchLn({
let { modifiedAst } = addNewSketchLn({
node: ast,
programMemory,
to: [2, 3],
@ -160,12 +161,33 @@ show(mySketch001)`
],
})
// Enable rotations #152
const expectedCode = `const mySketch001 = startSketchAt([0, 0])
let expectedCode = `const mySketch001 = startSketchAt([0, 0])
// |> rx(45, %)
|> lineTo([-1.59, -1.54], %)
|> lineTo([0.46, -5.82], %)
|> lineTo([2, 3], %)
show(mySketch001)
`
expect(recast(modifiedAst)).toBe(expectedCode)
modifiedAst = addCloseToPipe({
node: ast,
programMemory,
pathToNode: [
['body', ''],
[0, 'index'],
['declarations', 'VariableDeclaration'],
[0, 'index'],
['init', 'VariableDeclarator'],
],
})
expectedCode = `const mySketch001 = startSketchAt([0, 0])
// |> rx(45, %)
|> lineTo([-1.59, -1.54], %)
|> lineTo([0.46, -5.82], %)
|> close(%)
show(mySketch001)
`
expect(recast(modifiedAst)).toBe(expectedCode)
})