Lengths and angles should be set with |abs| values (#93)

* Lengths and angles should be set with |abs| values

* clean up
This commit is contained in:
Kurt Hutten
2023-04-02 17:20:11 +10:00
committed by GitHub
parent b279daa8e0
commit 01bf3c1049
13 changed files with 159 additions and 55 deletions

View File

@ -5,7 +5,6 @@ import { Value } from '../../lang/abstractSyntaxTree'
import {
getNodePathFromSourceRange,
getNodeFromPath,
findAllPreviousVariables,
} from '../../lang/queryAst'
import {
TransformInfo,
@ -13,10 +12,8 @@ import {
transformAstSketchLines,
} from '../../lang/std/sketchcombos'
import { SetAngleLengthModal } from '../SetAngleLengthModal'
import {
createIdentifier,
createVariableDeclaration,
} from '../../lang/modifyAst'
import { createVariableDeclaration } from '../../lang/modifyAst'
import { removeDoubleNegatives } from '../AvailableVarsHelpers'
const getModalInfo = create(SetAngleLengthModal as any)
@ -71,11 +68,16 @@ export const SetAngleLength = ({
referenceSegName: '',
})
try {
const { valueNode, variableName, newVariableInsertIndex } =
const { valueNode, variableName, newVariableInsertIndex, sign } =
await getModalInfo({
value: valueUsedInTransform,
valueName: angleOrLength === 'setAngle' ? 'angle' : 'length',
} as any)
const finalValue = removeDoubleNegatives(
valueNode,
sign,
variableName
)
const { modifiedAst: _modifiedAst } = transformAstSketchLines({
ast: JSON.parse(JSON.stringify(ast)),
@ -83,9 +85,7 @@ export const SetAngleLength = ({
transformInfos,
programMemory,
referenceSegName: '',
forceValueUsedInTransform: variableName
? createIdentifier(variableName)
: valueNode,
forceValueUsedInTransform: finalValue,
})
if (variableName) {
const newBody = [..._modifiedAst.body]