Replace overlay e2e test with integration tests (#7218)

* expand xstate unit tests

* remove .only 🙄

* add tests for remove constraints (with todos)

* expand to invididual constraints too

* re-organise

* fix tests

* fmt

* remove log

* clean up

* type clean up

* add delete tests too

* remove redundant tests<

* fix e2e

* lints
This commit is contained in:
Kurt Hutten
2025-05-29 22:31:57 +10:00
committed by GitHub
parent 87e3588ceb
commit b123dacc41
6 changed files with 1363 additions and 1313 deletions

File diff suppressed because it is too large Load Diff

View File

@ -16,7 +16,6 @@ import {
addSketchTo,
deleteSegmentFromPipeExpression,
moveValueIntoNewVariable,
removeSingleConstraintInfo,
sketchOnExtrudedFace,
splitPipedProfile,
} from '@src/lang/modifyAst'
@ -24,11 +23,6 @@ import { findUsesOfTagInPipe } from '@src/lang/queryAst'
import { getNodePathFromSourceRange } from '@src/lang/queryAstNodePathUtils'
import type { Artifact } from '@src/lang/std/artifactGraph'
import { codeRefFromRange } from '@src/lang/std/artifactGraph'
import type {
InputArg,
InputArgKeys,
SimplifiedArgDetails,
} from '@src/lang/std/stdTypes'
import { topLevelRange } from '@src/lang/util'
import type { Identifier, Literal, LiteralValue } from '@src/lang/wasm'
import { assertParse, recast } from '@src/lang/wasm'
@ -666,189 +660,6 @@ ${!replace1 ? ` |> ${line}\n` : ''} |> angledLine(angle = -65, length = ${
})
})
describe('Testing removeSingleConstraintInfo', () => {
describe('with mostly object notation', () => {
const code = `part001 = startSketchOn(-XZ)
|> startProfile(at = [0, 0])
|> line(end = [3 + 0, 4 + 0])
|> /*0*/ angledLine(angle = 3 + 0, length = 3.14 + 0)
|> line(endAbsolute = [6.14 + 0, 3.14 + 0])
|> xLine(/*xAbs*/ endAbsolute = 8 + 0)
|> yLine(/*yAbs*/ endAbsolute = 5 + 0)
|> yLine(/*yRel*/ length = 3.14 + 0, tag = $a)
|> xLine(/*xRel*/ length = 3.14 + 0)
|> /*1*/ angledLine(angle = 3 + 0, lengthX = 3.14 + 0)
|> /*2*/ angledLine(angle = 30 + 0, lengthY = 3 + 0)
|> /*3*/ angledLine(angle = 12.14 + 0, endAbsoluteX = 12 + 0)
|> /*4*/ angledLine(angle = 30 + 0, endAbsoluteY = 10.14 + 0)
|> angledLineThatIntersects(angle = 3.14 + 0, intersectTag = a, offset = 0 + 0)
|> tangentialArc(endAbsolute = [3.14 + 0, 13.14 + 0])`
const cases: [string, InputArg['type'], number | string, string][] = [
[' line(end = [3 + 0, 4])', 'arrayItem', 1, ''],
[
'/*0*/ angledLine(angle = 3, length = 3.14 + 0)',
'labeledArg',
'angle',
'',
],
['line(endAbsolute = [6.14 + 0, 3.14 + 0])', 'arrayItem', 0, ''],
['xLine(endAbsolute = 8)', 'singleValue', '', '/*xAbs*/'],
['yLine(endAbsolute = 5)', 'singleValue', '', '/*yAbs*/'],
['yLine(length = 3.14, tag = $a)', 'singleValue', '', '/*yRel*/'],
['xLine(length = 3.14)', 'singleValue', '', '/*xRel*/'],
[
'/*1*/ angledLine(angle = 3, lengthX = 3.14 + 0)',
'labeledArg',
'angle',
'',
],
[
'/*2*/ angledLine(angle = 30 + 0, lengthY = 3)',
'labeledArg',
'length',
'',
],
[
'/*3*/ angledLine(angle = 12.14 + 0, endAbsoluteX = 12)',
'labeledArg',
'endAbsoluteX',
'',
],
[
'/*4*/ angledLine(angle = 30, endAbsoluteY = 10.14 + 0)',
'labeledArg',
'angle',
'',
],
[
`angledLineThatIntersects(angle = 3.14 + 0, intersectTag = a, offset = 0)`,
'labeledArg',
'offset',
'',
],
[
'tangentialArc(endAbsolute = [3.14 + 0, 13.14])',
'labeledArgArrayItem',
'endAbsolute',
'',
],
]
test.each(cases)(
'stdlib fn: %s',
async (expectedFinish, key, value, commentLabel) => {
const ast = assertParse(code)
const execState = await enginelessExecutor(ast)
const lineOfInterest =
commentLabel.length > 0
? expectedFinish.split(commentLabel)[0]
: expectedFinish.split('(')[0] + '('
const start = code.indexOf(lineOfInterest)
const range = topLevelRange(start + 1, start + lineOfInterest.length)
const pathToNode = getNodePathFromSourceRange(ast, range)
let argPosition: SimplifiedArgDetails
if (key === 'arrayItem' && typeof value === 'number') {
argPosition = {
type: 'arrayItem',
index: value === 0 ? 0 : 1,
}
} else if (key === 'singleValue') {
argPosition = {
type: 'singleValue',
}
} else if (key === 'labeledArg' && typeof value === 'string') {
argPosition = {
type: 'labeledArg',
key: value as any,
}
} else if (key === 'labeledArgArrayItem') {
argPosition = {
type: 'labeledArgArrayItem',
key: value as any,
index: 1,
}
} else {
throw new Error('argPosition is undefined')
}
const mod = removeSingleConstraintInfo(
pathToNode,
argPosition,
ast,
execState.variables
)
if (!mod) return new Error('mod is undefined')
const recastCode = recast(mod.modifiedAst)
expect(recastCode).toContain(expectedFinish)
}
)
})
describe('with array notation', () => {
const code = `part001 = startSketchOn(-XZ)
|> startProfile(at = [0, 0])
|> /*0*/ angledLine(angle = 3.14 + 0, length = 3.14 + 0)
|> /*1*/ angledLine(angle = 3 + 0, lengthX = 3.14 + 0)
|> /*2*/ angledLine(angle = 30 + 0, lengthY = 3 + 0)
|> /*3*/ angledLine(angle = 12.14 + 0, endAbsoluteX = 12 + 0)
|> /*4*/ angledLine(angle = 30 + 0, endAbsoluteY = 10.14 + 0)`
const ang: InputArgKeys = 'angle'
test.each([
['/*0*/ angledLine(angle = 3, length = 3.14 + 0)', 'labeledArg', ang],
[
'/*1*/ angledLine(angle = 3, lengthX = 3.14 + 0)',
'labeledArg',
'angle',
],
[
'/*2*/ angledLine(angle = 30 + 0, lengthY = 3)',
'labeledArg',
'lengthY',
],
[
'/*3*/ angledLine(angle = 12.14 + 0, endAbsoluteX = 12)',
'labeledArg',
'endAbsoluteX',
],
[
'/*4*/ angledLine(angle = 30, endAbsoluteY = 10.14 + 0)',
'labeledArg',
'angle',
],
])('stdlib fn: %s', async (expectedFinish, key, value) => {
const ast = assertParse(code)
const execState = await enginelessExecutor(ast)
const lineOfInterest = expectedFinish.split('(')[0] + '('
const start = code.indexOf(lineOfInterest)
expect(start).toBeGreaterThanOrEqual(0)
const range = topLevelRange(start + 1, start + lineOfInterest.length)
let argPosition: SimplifiedArgDetails
if (key === 'arrayIndex' && typeof value === 'number') {
argPosition = {
type: 'arrayItem',
index: value === 0 ? 0 : 1,
}
} else if (key === 'labeledArg') {
argPosition = {
type: 'labeledArg',
key: value as InputArgKeys,
}
} else {
throw new Error('argPosition is undefined')
}
const pathToNode = getNodePathFromSourceRange(ast, range)
const mod = removeSingleConstraintInfo(
pathToNode,
argPosition,
ast,
execState.variables
)
if (!mod) return new Error('mod is undefined')
const recastCode = recast(mod.modifiedAst)
expect(recastCode).toContain(expectedFinish)
})
})
})
describe('Testing deleteFromSelection', () => {
const cases = [
[

View File

@ -320,7 +320,11 @@ describe('testing getConstraintInfo', () => {
isConstrained: false,
value: '6.14',
sourceRange: [expect.any(Number), expect.any(Number), 0],
argPosition: { type: 'arrayItem', index: 0 },
argPosition: {
type: 'labeledArgArrayItem',
key: 'endAbsolute',
index: 0,
},
pathToNode: expect.any(Array),
stdLibFnName: 'line',
},
@ -329,7 +333,11 @@ describe('testing getConstraintInfo', () => {
isConstrained: false,
value: '3.14',
sourceRange: [expect.any(Number), expect.any(Number), 0],
argPosition: { type: 'arrayItem', index: 1 },
argPosition: {
type: 'labeledArgArrayItem',
key: 'endAbsolute',
index: 1,
},
pathToNode: expect.any(Array),
stdLibFnName: 'line',
},
@ -352,7 +360,7 @@ describe('testing getConstraintInfo', () => {
isConstrained: false,
value: '8',
sourceRange: [expect.any(Number), expect.any(Number), 0],
argPosition: { type: 'singleValue' },
argPosition: { type: 'labeledArg', key: 'endAbsolute' },
pathToNode: expect.any(Array),
stdLibFnName: 'xLineTo',
},
@ -375,7 +383,7 @@ describe('testing getConstraintInfo', () => {
isConstrained: false,
value: '5',
sourceRange: [expect.any(Number), expect.any(Number), 0],
argPosition: { type: 'singleValue' },
argPosition: { type: 'labeledArg', key: 'endAbsolute' },
pathToNode: expect.any(Array),
stdLibFnName: 'yLineTo',
},
@ -437,7 +445,7 @@ describe('testing getConstraintInfo', () => {
sourceRange: [expect.any(Number), expect.any(Number), 0],
argPosition: { type: 'labeledArg', key: 'angle' },
pathToNode: expect.any(Array),
stdLibFnName: 'angledLineOfXLength',
stdLibFnName: 'angledLine',
},
{
type: 'xRelative',
@ -446,7 +454,7 @@ describe('testing getConstraintInfo', () => {
sourceRange: [expect.any(Number), expect.any(Number), 0],
argPosition: { type: 'labeledArg', key: 'lengthX' },
pathToNode: expect.any(Array),
stdLibFnName: 'angledLineOfXLength',
stdLibFnName: 'angledLine',
},
],
],
@ -668,7 +676,7 @@ describe('testing getConstraintInfo', () => {
sourceRange: [expect.any(Number), expect.any(Number), 0],
argPosition: { type: 'labeledArg', key: 'angle' },
pathToNode: expect.any(Array),
stdLibFnName: 'angledLineOfXLength',
stdLibFnName: 'angledLine',
},
{
type: 'xRelative',
@ -677,7 +685,7 @@ describe('testing getConstraintInfo', () => {
sourceRange: [expect.any(Number), expect.any(Number), 0],
argPosition: { type: 'labeledArg', key: 'lengthX' },
pathToNode: expect.any(Array),
stdLibFnName: 'angledLineOfXLength',
stdLibFnName: 'angledLine',
},
],
],
@ -845,7 +853,11 @@ describe('testing getConstraintInfo', () => {
isConstrained: true,
value: '6.14 + 0',
sourceRange: [expect.any(Number), expect.any(Number), 0],
argPosition: { type: 'arrayItem', index: 0 },
argPosition: {
type: 'labeledArgArrayItem',
key: 'endAbsolute',
index: 0,
},
pathToNode: expect.any(Array),
stdLibFnName: 'line',
},
@ -854,7 +866,11 @@ describe('testing getConstraintInfo', () => {
isConstrained: true,
value: '3.14 + 0',
sourceRange: [expect.any(Number), expect.any(Number), 0],
argPosition: { type: 'arrayItem', index: 1 },
argPosition: {
type: 'labeledArgArrayItem',
key: 'endAbsolute',
index: 1,
},
pathToNode: expect.any(Array),
stdLibFnName: 'line',
},
@ -877,7 +893,7 @@ describe('testing getConstraintInfo', () => {
isConstrained: true,
value: '8 + 0',
sourceRange: [expect.any(Number), expect.any(Number), 0],
argPosition: { type: 'singleValue' },
argPosition: { type: 'labeledArg', key: 'endAbsolute' },
pathToNode: expect.any(Array),
stdLibFnName: 'xLineTo',
},
@ -900,7 +916,7 @@ describe('testing getConstraintInfo', () => {
isConstrained: true,
value: '5 + 0',
sourceRange: [expect.any(Number), expect.any(Number), 0],
argPosition: { type: 'singleValue' },
argPosition: { type: 'labeledArg', key: 'endAbsolute' },
pathToNode: expect.any(Array),
stdLibFnName: 'yLineTo',
},
@ -962,7 +978,7 @@ describe('testing getConstraintInfo', () => {
sourceRange: [expect.any(Number), expect.any(Number), 0],
argPosition: { type: 'labeledArg', key: 'angle' },
pathToNode: expect.any(Array),
stdLibFnName: 'angledLineOfXLength',
stdLibFnName: 'angledLine',
},
{
type: 'xRelative',
@ -971,7 +987,7 @@ describe('testing getConstraintInfo', () => {
sourceRange: [expect.any(Number), expect.any(Number), 0],
argPosition: { type: 'labeledArg', key: 'lengthX' },
pathToNode: expect.any(Array),
stdLibFnName: 'angledLineOfXLength',
stdLibFnName: 'angledLine',
},
],
],

View File

@ -86,9 +86,8 @@ import { err } from '@src/lib/trap'
import { allLabels, getAngle, getLength, roundOff } from '@src/lib/utils'
import type { EdgeCutInfo } from '@src/machines/modelingMachine'
const STRAIGHT_SEGMENT_ERR = new Error(
'Invalid input, expected "straight-segment"'
)
const STRAIGHT_SEGMENT_ERR = () =>
new Error('Invalid input, expected "straight-segment"')
const ARC_SEGMENT_ERR = () => new Error('Invalid input, expected "arc-segment"')
const CIRCLE_THREE_POINT_SEGMENT_ERR = new Error(
'Invalid input, expected "circle-three-point-segment"'
@ -133,6 +132,8 @@ const constrainInfo = (
: typeof g === 'string'
? { type: 'objectProperty', key: g }
: g?.type === 'labeledArg'
? g
: g?.type === 'labeledArgArrayItem'
? g
: undefined
@ -365,7 +366,7 @@ const horzVertConstraintInfoHelper = (
if (argIndex === undefined) {
return []
}
const firstArg = callExp.arguments?.[argIndex].arg
const mainArg = callExp.arguments?.[argIndex].arg
const callee = callExp.callee
const pathToFirstArg: PathToNode = [
...pathToNode,
@ -389,11 +390,11 @@ const horzVertConstraintInfoHelper = (
),
constrainInfo(
inputConstrainTypes[1],
isNotLiteralArrayOrStatic(firstArg),
code.slice(firstArg.start, firstArg.end),
isNotLiteralArrayOrStatic(mainArg),
code.slice(mainArg.start, mainArg.end),
stdLibFnName,
abbreviatedInput,
topLevelRange(firstArg.start, firstArg.end),
topLevelRange(mainArg.start, mainArg.end),
pathToFirstArg
),
]
@ -420,7 +421,7 @@ export const line: SketchLineHelperKw = {
replaceExistingCallback,
spliceBetween,
}) => {
if (segmentInput.type !== 'straight-segment') return STRAIGHT_SEGMENT_ERR
if (segmentInput.type !== 'straight-segment') return STRAIGHT_SEGMENT_ERR()
const { from, to } = segmentInput
const _node = { ...node }
const nodeMeta = getNodeFromPath<PipeExpression | CallExpressionKw>(
@ -520,7 +521,7 @@ export const line: SketchLineHelperKw = {
}
},
updateArgs: ({ node, pathToNode, input }) => {
if (input.type !== 'straight-segment') return STRAIGHT_SEGMENT_ERR
if (input.type !== 'straight-segment') return STRAIGHT_SEGMENT_ERR()
const { to, from } = input
const _node = { ...node }
const nodeMeta = getNodeFromPath<CallExpressionKw>(_node, pathToNode)
@ -559,7 +560,7 @@ export const lineTo: SketchLineHelperKw = {
replaceExistingCallback,
spliceBetween,
}) => {
if (segmentInput.type !== 'straight-segment') return STRAIGHT_SEGMENT_ERR
if (segmentInput.type !== 'straight-segment') return STRAIGHT_SEGMENT_ERR()
const to = segmentInput.to
const _node = structuredClone(node)
const nodeMeta = getNodeFromPath<PipeExpression | CallExpressionKw>(
@ -618,15 +619,17 @@ export const lineTo: SketchLineHelperKw = {
const { index: callIndex } = splitPathAtPipeExpression(pathToNode)
const result = replaceExistingCallback([
{
type: 'arrayItem',
type: 'labeledArgArrayItem',
key: ARG_END_ABSOLUTE,
index: 0,
argType: 'xRelative',
argType: 'xAbsolute',
expr: newXVal,
},
{
type: 'arrayItem',
type: 'labeledArgArrayItem',
key: ARG_END_ABSOLUTE,
index: 1,
argType: 'yRelative',
argType: 'yAbsolute',
expr: newYVal,
},
])
@ -669,7 +672,7 @@ export const lineTo: SketchLineHelperKw = {
}
},
updateArgs: ({ node, pathToNode, input }) => {
if (input.type !== 'straight-segment') return STRAIGHT_SEGMENT_ERR
if (input.type !== 'straight-segment') return STRAIGHT_SEGMENT_ERR()
const { to } = input
const _node = { ...node }
const nodeMeta = getNodeFromPath<CallExpressionKw>(_node, pathToNode)
@ -689,19 +692,58 @@ export const lineTo: SketchLineHelperKw = {
},
getTag: getTagKwArg(),
addTag: addTagKw(),
getConstraintInfo: (callExp, ...args) =>
commonConstraintInfoHelper(
callExp,
['xAbsolute', 'yAbsolute'],
getConstraintInfo: (callExp, code, pathToNode) => {
const endAbsoluteArg = findKwArgWithIndex(ARG_END_ABSOLUTE, callExp)
if (endAbsoluteArg === undefined) {
return []
}
const { expr, argIndex } = endAbsoluteArg
const constraints: ConstrainInfo[] = []
if (!(expr.type === 'ArrayExpression' && expr.elements.length === 2)) {
return []
}
const pipeExpressionIndex = pathToNode.findIndex(
([_, nodeName]) => nodeName === 'PipeExpression'
)
const pathToArg: PathToNode = [
...pathToNode.slice(0, pipeExpressionIndex + 2),
['arguments', 'CallExpressionKw'],
[argIndex, ARG_INDEX_FIELD],
['arg', LABELED_ARG_FIELD],
['elements', 'ArrayExpression'],
]
const pathToXArg: PathToNode = [...pathToArg, [0, 'index']]
const pathToYArg: PathToNode = [...pathToArg, [1, 'index']]
constraints.push(
constrainInfo(
'xAbsolute',
isNotLiteralArrayOrStatic(expr.elements[0]),
code.slice(expr.elements[0].start, expr.elements[0].end),
'line',
[{ arrayInput: 0 }, { arrayInput: 1 }],
...args
),
{ type: 'labeledArgArrayItem', index: 0, key: ARG_END_ABSOLUTE },
topLevelRange(expr.elements[0].start, expr.elements[0].end),
pathToXArg
)
)
constraints.push(
constrainInfo(
'yAbsolute',
isNotLiteralArrayOrStatic(expr.elements[1]),
code.slice(expr.elements[1].start, expr.elements[1].end),
'line',
{ type: 'labeledArgArrayItem', index: 1, key: ARG_END_ABSOLUTE },
topLevelRange(expr.elements[1].start, expr.elements[1].end),
pathToYArg
)
)
return constraints
},
}
export const xLineTo: SketchLineHelperKw = {
add: ({ node, pathToNode, segmentInput, replaceExistingCallback }) => {
if (segmentInput.type !== 'straight-segment') return STRAIGHT_SEGMENT_ERR
if (segmentInput.type !== 'straight-segment') return STRAIGHT_SEGMENT_ERR()
const { to } = segmentInput
const _node = { ...node }
const getNode = getNodeFromPathCurry(_node, pathToNode)
@ -714,7 +756,8 @@ export const xLineTo: SketchLineHelperKw = {
const { index: callIndex } = splitPathAtPipeExpression(pathToNode)
const result = replaceExistingCallback([
{
type: 'singleValue',
type: 'labeledArg',
key: ARG_END_ABSOLUTE,
argType: 'xAbsolute',
expr: createLiteral(roundOff(to[0], 2)),
},
@ -738,7 +781,7 @@ export const xLineTo: SketchLineHelperKw = {
}
},
updateArgs: ({ node, pathToNode, input }) => {
if (input.type !== 'straight-segment') return STRAIGHT_SEGMENT_ERR
if (input.type !== 'straight-segment') return STRAIGHT_SEGMENT_ERR()
const { to } = input
const _node = { ...node }
const nodeMeta = getNodeFromPath<CallExpressionKw>(_node, pathToNode)
@ -759,14 +802,14 @@ export const xLineTo: SketchLineHelperKw = {
callExp,
['horizontal', 'xAbsolute'],
'xLineTo',
'singleValue',
{ type: 'labeledArg', key: ARG_END_ABSOLUTE },
...args
),
}
export const yLineTo: SketchLineHelperKw = {
add: ({ node, pathToNode, segmentInput, replaceExistingCallback }) => {
if (segmentInput.type !== 'straight-segment') return STRAIGHT_SEGMENT_ERR
if (segmentInput.type !== 'straight-segment') return STRAIGHT_SEGMENT_ERR()
const { to } = segmentInput
const _node = { ...node }
const getNode = getNodeFromPathCurry(_node, pathToNode)
@ -780,7 +823,8 @@ export const yLineTo: SketchLineHelperKw = {
const { index: callIndex } = splitPathAtPipeExpression(pathToNode)
const result = replaceExistingCallback([
{
type: 'singleValue',
type: 'labeledArg',
key: ARG_END_ABSOLUTE,
argType: 'yAbsolute',
expr: newVal,
},
@ -804,7 +848,7 @@ export const yLineTo: SketchLineHelperKw = {
}
},
updateArgs: ({ node, pathToNode, input }) => {
if (input.type !== 'straight-segment') return STRAIGHT_SEGMENT_ERR
if (input.type !== 'straight-segment') return STRAIGHT_SEGMENT_ERR()
const { to } = input
const _node = { ...node }
const nodeMeta = getNodeFromPath<CallExpressionKw>(_node, pathToNode)
@ -825,14 +869,14 @@ export const yLineTo: SketchLineHelperKw = {
callExp,
['vertical', 'yAbsolute'],
'yLineTo',
'singleValue',
{ type: 'labeledArg', key: ARG_END_ABSOLUTE },
...args
),
}
export const xLine: SketchLineHelperKw = {
add: ({ node, pathToNode, segmentInput, replaceExistingCallback }) => {
if (segmentInput.type !== 'straight-segment') return STRAIGHT_SEGMENT_ERR
if (segmentInput.type !== 'straight-segment') return STRAIGHT_SEGMENT_ERR()
const { from, to } = segmentInput
const _node = structuredClone(node)
const getNode = getNodeFromPathCurry(_node, pathToNode)
@ -876,7 +920,7 @@ export const xLine: SketchLineHelperKw = {
return { modifiedAst: _node, pathToNode }
},
updateArgs: ({ node, pathToNode, input }) => {
if (input.type !== 'straight-segment') return STRAIGHT_SEGMENT_ERR
if (input.type !== 'straight-segment') return STRAIGHT_SEGMENT_ERR()
const { to, from } = input
const _node = { ...node }
const nodeMeta = getNodeFromPath<CallExpressionKw>(_node, pathToNode)
@ -904,7 +948,7 @@ export const xLine: SketchLineHelperKw = {
export const yLine: SketchLineHelperKw = {
add: ({ node, pathToNode, segmentInput, replaceExistingCallback }) => {
if (segmentInput.type !== 'straight-segment') return STRAIGHT_SEGMENT_ERR
if (segmentInput.type !== 'straight-segment') return STRAIGHT_SEGMENT_ERR()
const { from, to } = segmentInput
const _node = structuredClone(node)
const getNode = getNodeFromPathCurry(_node, pathToNode)
@ -946,7 +990,7 @@ export const yLine: SketchLineHelperKw = {
return { modifiedAst: _node, pathToNode }
},
updateArgs: ({ node, pathToNode, input }) => {
if (input.type !== 'straight-segment') return STRAIGHT_SEGMENT_ERR
if (input.type !== 'straight-segment') return STRAIGHT_SEGMENT_ERR()
const { to, from } = input
const _node = { ...node }
const nodeMeta = getNodeFromPath<CallExpressionKw>(_node, pathToNode)
@ -974,7 +1018,7 @@ export const yLine: SketchLineHelperKw = {
export const tangentialArc: SketchLineHelperKw = {
add: ({ node, pathToNode, segmentInput, replaceExistingCallback }) => {
if (segmentInput.type !== 'straight-segment') return STRAIGHT_SEGMENT_ERR
if (segmentInput.type !== 'straight-segment') return STRAIGHT_SEGMENT_ERR()
const { to } = segmentInput
const _node = { ...node }
const getNode = getNodeFromPathCurry(_node, pathToNode)
@ -1046,7 +1090,7 @@ export const tangentialArc: SketchLineHelperKw = {
}
},
updateArgs: ({ node, pathToNode, input }) => {
if (input.type !== 'straight-segment') return STRAIGHT_SEGMENT_ERR
if (input.type !== 'straight-segment') return STRAIGHT_SEGMENT_ERR()
const { to } = input
const _node = { ...node }
const nodeMeta = getNodeFromPath<CallExpressionKw>(_node, pathToNode)
@ -1190,7 +1234,7 @@ export const tangentialArc: SketchLineHelperKw = {
export const startProfile: SketchLineHelperKw = {
updateArgs: ({ node, pathToNode, input }) => {
if (input.type !== 'straight-segment') return STRAIGHT_SEGMENT_ERR
if (input.type !== 'straight-segment') return STRAIGHT_SEGMENT_ERR()
const { to } = input
const _node = { ...node }
const nodeMeta = getNodeFromPath<CallExpressionKw>(_node, pathToNode)
@ -1211,8 +1255,7 @@ export const startProfile: SketchLineHelperKw = {
getTag: getTagKwArg(),
addTag: addTagKw(),
add: ({ node, pathToNode, replaceExistingCallback, segmentInput }) => {
console.log('segmentInput', segmentInput)
if (segmentInput.type !== 'straight-segment') return STRAIGHT_SEGMENT_ERR
if (segmentInput.type !== 'straight-segment') return STRAIGHT_SEGMENT_ERR()
const { to } = segmentInput
const _node = structuredClone(node)
const nodeMeta = getNodeFromPath<PipeExpression | CallExpressionKw>(
@ -2136,7 +2179,7 @@ export const arcTo: SketchLineHelperKw = {
interiorAbsoluteArr.elements[0].start,
interiorAbsoluteArr.elements[0].end
),
stdLibFnName: 'arc',
stdLibFnName: 'arcTo',
argPosition: {
type: 'labeledArgArrayItem',
key: ARG_INTERIOR_ABSOLUTE,
@ -2158,7 +2201,7 @@ export const arcTo: SketchLineHelperKw = {
interiorAbsoluteArr.elements[1].start,
interiorAbsoluteArr.elements[1].end
),
stdLibFnName: 'arc',
stdLibFnName: 'arcTo',
argPosition: {
type: 'labeledArgArrayItem',
key: ARG_INTERIOR_ABSOLUTE,
@ -2175,7 +2218,7 @@ export const arcTo: SketchLineHelperKw = {
type: 'xAbsolute',
isConstrained: isNotLiteralArrayOrStatic(endArr.elements[0]),
value: code.slice(endArr.elements[0].start, endArr.elements[0].end),
stdLibFnName: 'arc',
stdLibFnName: 'arcTo',
argPosition: {
type: 'labeledArgArrayItem',
key: 'endAbsolute',
@ -2192,7 +2235,7 @@ export const arcTo: SketchLineHelperKw = {
type: 'yAbsolute',
isConstrained: isNotLiteralArrayOrStatic(endArr.elements[1]),
value: code.slice(endArr.elements[1].start, endArr.elements[1].end),
stdLibFnName: 'arc',
stdLibFnName: 'arcTo',
argPosition: {
type: 'labeledArgArrayItem',
key: 'endAbsolute',
@ -2242,42 +2285,42 @@ export const circleThreePoint: SketchLineHelperKw = {
if (replaceExistingCallback) {
const result = replaceExistingCallback([
{
type: 'arrayInObject',
type: 'labeledArgArrayItem',
index: 0,
key: 'p1',
argType: 'xAbsolute',
expr: createRoundedLiteral(p1[0]),
},
{
type: 'arrayInObject',
type: 'labeledArgArrayItem',
index: 1,
key: 'p1',
argType: 'yAbsolute',
expr: createRoundedLiteral(p1[1]),
},
{
type: 'arrayInObject',
type: 'labeledArgArrayItem',
index: 0,
key: 'p2',
argType: 'xAbsolute',
expr: createRoundedLiteral(p2[0]),
},
{
type: 'arrayInObject',
type: 'labeledArgArrayItem',
index: 1,
key: 'p2',
argType: 'yAbsolute',
expr: createRoundedLiteral(p2[1]),
},
{
type: 'arrayInObject',
type: 'labeledArgArrayItem',
index: 0,
key: 'p3',
argType: 'xAbsolute',
expr: createRoundedLiteral(p3[0]),
},
{
type: 'arrayInObject',
type: 'labeledArgArrayItem',
index: 1,
key: 'p3',
argType: 'yAbsolute',
@ -2344,21 +2387,21 @@ export const circleThreePoint: SketchLineHelperKw = {
...pathToNode,
['arguments', 'CallExpressionKw'],
[p1Details.argIndex, 'arg index'],
['arg', 'labeledArg -> Arg'],
['arg', LABELED_ARG_FIELD],
['elements', 'ArrayExpression'],
]
const pathToP2ArrayExpression: PathToNode = [
...pathToNode,
['arguments', 'CallExpressionKw'],
[p2Details.argIndex, 'arg index'],
['arg', 'labeledArg -> Arg'],
['arg', LABELED_ARG_FIELD],
['elements', 'ArrayExpression'],
]
const pathToP3ArrayExpression: PathToNode = [
...pathToNode,
['arguments', 'CallExpressionKw'],
[p3Details.argIndex, 'arg index'],
['arg', 'labeledArg -> Arg'],
['arg', LABELED_ARG_FIELD],
['elements', 'ArrayExpression'],
]
@ -2385,7 +2428,7 @@ export const circleThreePoint: SketchLineHelperKw = {
p1Details.expr.elements[0].end
),
argPosition: {
type: 'arrayInObject',
type: 'labeledArgArrayItem',
index: 0,
key: 'p1',
},
@ -2406,7 +2449,7 @@ export const circleThreePoint: SketchLineHelperKw = {
p1Details.expr.elements[1].end
),
argPosition: {
type: 'arrayInObject',
type: 'labeledArgArrayItem',
index: 1,
key: 'p1',
},
@ -2427,7 +2470,7 @@ export const circleThreePoint: SketchLineHelperKw = {
p2Details.expr.elements[0].end
),
argPosition: {
type: 'arrayInObject',
type: 'labeledArgArrayItem',
index: 0,
key: 'p2',
},
@ -2448,7 +2491,7 @@ export const circleThreePoint: SketchLineHelperKw = {
p2Details.expr.elements[1].end
),
argPosition: {
type: 'arrayInObject',
type: 'labeledArgArrayItem',
index: 1,
key: 'p2',
},
@ -2469,7 +2512,7 @@ export const circleThreePoint: SketchLineHelperKw = {
p3Details.expr.elements[0].end
),
argPosition: {
type: 'arrayInObject',
type: 'labeledArgArrayItem',
index: 0,
key: 'p3',
},
@ -2490,7 +2533,7 @@ export const circleThreePoint: SketchLineHelperKw = {
p3Details.expr.elements[1].end
),
argPosition: {
type: 'arrayInObject',
type: 'labeledArgArrayItem',
index: 1,
key: 'p3',
},
@ -2512,7 +2555,7 @@ export const circleThreePoint: SketchLineHelperKw = {
export const angledLine: SketchLineHelperKw = {
add: ({ node, pathToNode, segmentInput, replaceExistingCallback, snaps }) => {
if (segmentInput.type !== 'straight-segment') return STRAIGHT_SEGMENT_ERR
if (segmentInput.type !== 'straight-segment') return STRAIGHT_SEGMENT_ERR()
const { from, to } = segmentInput
const _node = { ...node }
const getNode = getNodeFromPathCurry(_node, pathToNode)
@ -2585,7 +2628,7 @@ export const angledLine: SketchLineHelperKw = {
}
},
updateArgs: ({ node, pathToNode, input }) => {
if (input.type !== 'straight-segment') return STRAIGHT_SEGMENT_ERR
if (input.type !== 'straight-segment') return STRAIGHT_SEGMENT_ERR()
const { to, from } = input
const _node = { ...node }
const nodeMeta = getNodeFromPath<CallExpressionKw>(_node, pathToNode)
@ -2628,7 +2671,7 @@ export const angledLineOfXLength: SketchLineHelperKw = {
segmentInput,
replaceExistingCallback,
}) => {
if (segmentInput.type !== 'straight-segment') return STRAIGHT_SEGMENT_ERR
if (segmentInput.type !== 'straight-segment') return STRAIGHT_SEGMENT_ERR()
const { from, to } = segmentInput
const _node = { ...node }
const nodeMeta = getNodeFromPath<PipeExpression>(
@ -2657,16 +2700,14 @@ export const angledLineOfXLength: SketchLineHelperKw = {
if (replaceExistingCallback) {
const result = replaceExistingCallback([
{
type: 'arrayOrObjItem',
index: 0,
type: 'labeledArg',
key: 'angle',
argType: 'angle',
expr: angle,
},
{
type: 'arrayOrObjItem',
index: 1,
key: 'length',
type: 'labeledArg',
key: 'lengthX',
argType: 'xRelative',
expr: xLength,
},
@ -2691,7 +2732,7 @@ export const angledLineOfXLength: SketchLineHelperKw = {
}
},
updateArgs: ({ node, pathToNode, input }) => {
if (input.type !== 'straight-segment') return STRAIGHT_SEGMENT_ERR
if (input.type !== 'straight-segment') return STRAIGHT_SEGMENT_ERR()
const { to, from } = input
const _node = { ...node }
const nodeMeta = getNodeFromPath<CallExpressionKw>(_node, pathToNode)
@ -2730,7 +2771,7 @@ export const angledLineOfXLength: SketchLineHelperKw = {
commonConstraintInfoHelper(
callExp,
['angle', 'xRelative'],
'angledLineOfXLength',
'angledLine',
[{ argLabel: 'angle' }, { argLabel: 'lengthX' }],
...args
),
@ -2744,7 +2785,7 @@ export const angledLineOfYLength: SketchLineHelperKw = {
segmentInput,
replaceExistingCallback,
}) => {
if (segmentInput.type !== 'straight-segment') return STRAIGHT_SEGMENT_ERR
if (segmentInput.type !== 'straight-segment') return STRAIGHT_SEGMENT_ERR()
const { from, to } = segmentInput
const _node = { ...node }
const nodeMeta = getNodeFromPath<PipeExpression>(
@ -2771,16 +2812,14 @@ export const angledLineOfYLength: SketchLineHelperKw = {
if (replaceExistingCallback) {
const result = replaceExistingCallback([
{
type: 'arrayOrObjItem',
index: 0,
type: 'labeledArg',
key: 'angle',
argType: 'angle',
expr: angle,
},
{
type: 'arrayOrObjItem',
index: 1,
key: 'length',
type: 'labeledArg',
key: 'lengthY',
argType: 'yRelative',
expr: yLength,
},
@ -2805,7 +2844,7 @@ export const angledLineOfYLength: SketchLineHelperKw = {
}
},
updateArgs: ({ node, pathToNode, input }) => {
if (input.type !== 'straight-segment') return STRAIGHT_SEGMENT_ERR
if (input.type !== 'straight-segment') return STRAIGHT_SEGMENT_ERR()
const { to, from } = input
const _node = { ...node }
const nodeMeta = getNodeFromPath<CallExpressionKw>(_node, pathToNode)
@ -2852,7 +2891,7 @@ export const angledLineOfYLength: SketchLineHelperKw = {
export const angledLineToX: SketchLineHelperKw = {
add: ({ node, pathToNode, segmentInput, replaceExistingCallback }) => {
if (segmentInput.type !== 'straight-segment') return STRAIGHT_SEGMENT_ERR
if (segmentInput.type !== 'straight-segment') return STRAIGHT_SEGMENT_ERR()
const { from, to } = segmentInput
const _node = { ...node }
const nodeMeta = getNodeFromPath<PipeExpression>(
@ -2868,16 +2907,14 @@ export const angledLineToX: SketchLineHelperKw = {
if (replaceExistingCallback) {
const result = replaceExistingCallback([
{
type: 'arrayOrObjItem',
index: 0,
type: 'labeledArg',
key: 'angle',
argType: 'angle',
expr: angle,
},
{
type: 'arrayOrObjItem',
index: 1,
key: 'to',
type: 'labeledArg',
key: 'endAbsoluteX',
argType: 'xAbsolute',
expr: xArg,
},
@ -2904,7 +2941,7 @@ export const angledLineToX: SketchLineHelperKw = {
}
},
updateArgs: ({ node, pathToNode, input }) => {
if (input.type !== 'straight-segment') return STRAIGHT_SEGMENT_ERR
if (input.type !== 'straight-segment') return STRAIGHT_SEGMENT_ERR()
const { to, from } = input
const _node = { ...node }
const nodeMeta = getNodeFromPath<CallExpressionKw>(_node, pathToNode)
@ -2941,7 +2978,7 @@ export const angledLineToX: SketchLineHelperKw = {
export const angledLineToY: SketchLineHelperKw = {
add: ({ node, pathToNode, segmentInput, replaceExistingCallback }) => {
if (segmentInput.type !== 'straight-segment') return STRAIGHT_SEGMENT_ERR
if (segmentInput.type !== 'straight-segment') return STRAIGHT_SEGMENT_ERR()
const { from, to } = segmentInput
const _node = { ...node }
const nodeMeta = getNodeFromPath<PipeExpression>(
@ -2959,16 +2996,14 @@ export const angledLineToY: SketchLineHelperKw = {
if (replaceExistingCallback) {
const result = replaceExistingCallback([
{
type: 'arrayOrObjItem',
index: 0,
type: 'labeledArg',
key: 'angle',
argType: 'angle',
expr: angle,
},
{
type: 'arrayOrObjItem',
index: 1,
key: 'to',
type: 'labeledArg',
key: 'endAbsoluteY',
argType: 'yAbsolute',
expr: yArg,
},
@ -2995,7 +3030,7 @@ export const angledLineToY: SketchLineHelperKw = {
}
},
updateArgs: ({ node, pathToNode, input }) => {
if (input.type !== 'straight-segment') return STRAIGHT_SEGMENT_ERR
if (input.type !== 'straight-segment') return STRAIGHT_SEGMENT_ERR()
const { to, from } = input
const _node = { ...node }
const nodeMeta = getNodeFromPath<CallExpressionKw>(_node, pathToNode)
@ -3038,7 +3073,7 @@ export const angledLineThatIntersects: SketchLineHelperKw = {
replaceExistingCallback,
referencedSegment,
}) => {
if (segmentInput.type !== 'straight-segment') return STRAIGHT_SEGMENT_ERR
if (segmentInput.type !== 'straight-segment') return STRAIGHT_SEGMENT_ERR()
const { from, to } = segmentInput
const _node = { ...node }
const nodeMeta = getNodeFromPath<PipeExpression>(
@ -3094,7 +3129,7 @@ export const angledLineThatIntersects: SketchLineHelperKw = {
return new Error('not implemented')
},
updateArgs: ({ node, pathToNode, input, variables }) => {
if (input.type !== 'straight-segment') return STRAIGHT_SEGMENT_ERR
if (input.type !== 'straight-segment') return STRAIGHT_SEGMENT_ERR()
const { to, from } = input
const _node = { ...node }
const nodeMeta = getNodeFromPath<CallExpressionKw>(_node, pathToNode)
@ -3215,7 +3250,7 @@ export const updateStartProfileAtArgs: SketchLineHelperKw['updateArgs'] = ({
pathToNode,
input,
}) => {
if (input.type !== 'straight-segment') return STRAIGHT_SEGMENT_ERR
if (input.type !== 'straight-segment') return STRAIGHT_SEGMENT_ERR()
const { to } = input
const _node = { ...node }
const nodeMeta = getNodeFromPath<CallExpressionKw>(_node, pathToNode)
@ -3370,6 +3405,7 @@ export function fnNameToToolTipFromSegment(
case 'tangentialArc':
case 'angledLine':
case 'startProfile':
case 'arcTo':
return fnName
default:
const err = `Unknown sketch line function ${fnName}`

View File

@ -1350,8 +1350,15 @@ export function removeSingleConstraint({
return false
}
const toolTip = fnNameToTooltip(
allLabels(callExp.node),
callExp.node.callee.name.name
)
const transform: TransformInfo = {
tooltip: callExp.node.callee.name.name as any,
tooltip: err(toolTip)
? (callExp.node.callee.name.name as ToolTip)
: toolTip,
createNode: ({ tag, inputs, rawArgs }) => {
// inputs is the current values for each of the inputs
// rawValues is the raw 'literal' values equivalent to the inputs

File diff suppressed because it is too large Load Diff