Move turns to a submodule of std (#6039)

* Move turns to a submodule of std

Signed-off-by: Nick Cameron <nrc@ncameron.org>

* Cache module infos as well as memory; fix a bug with deprecated constants

Signed-off-by: Nick Cameron <nrc@ncameron.org>

---------

Signed-off-by: Nick Cameron <nrc@ncameron.org>
This commit is contained in:
Nick Cameron
2025-03-30 11:10:44 +13:00
committed by GitHub
parent 51c16d0048
commit db5ce7ba85
56 changed files with 2678 additions and 2637 deletions

View File

@ -13,10 +13,7 @@ import {
SetAngleLengthModal,
createSetAngleLengthModal,
} from '../SetAngleLengthModal'
import {
createLocalName,
createVariableDeclaration,
} from '../../lang/modifyAst'
import { createName, createVariableDeclaration } from '../../lang/modifyAst'
import { removeDoubleNegatives } from '../AvailableVarsHelpers'
import { kclManager } from 'lib/singletons'
import { err } from 'lib/trap'
@ -169,7 +166,7 @@ export function applyConstraintAxisAlign({
if (err(info)) return info
const transformInfos = info.transforms
let finalValue = createLocalName('ZERO')
let finalValue = createName(['turns'], 'ZERO')
return transformAstSketchLines({
ast: structuredClone(kclManager.ast),

View File

@ -16,6 +16,7 @@ import {
import {
createBinaryExpressionWithUnary,
createLocalName,
createName,
createVariableDeclaration,
} from '../../lang/modifyAst'
import { removeDoubleNegatives } from '../AvailableVarsHelpers'
@ -167,14 +168,16 @@ export async function applyConstraintAngleLength({
isReferencingXAxis && angleOrLength === 'setAngle'
let forceVal = valueUsedInTransform || 0
let calcIdentifier = createLocalName('ZERO')
let calcIdentifier = createName(['turns'], 'ZERO')
if (isReferencingYAxisAngle) {
calcIdentifier = createLocalName(
calcIdentifier = createName(
['turns'],
forceVal < 0 ? 'THREE_QUARTER_TURN' : 'QUARTER_TURN'
)
forceVal = normaliseAngle(forceVal + (forceVal < 0 ? 90 : -90))
} else if (isReferencingXAxisAngle) {
calcIdentifier = createLocalName(
calcIdentifier = createName(
['turns'],
Math.abs(forceVal) > 90 ? 'HALF_TURN' : 'ZERO'
)
forceVal =

View File

@ -1087,6 +1087,22 @@ export function createLocalName(name: string): Node<Name> {
}
}
export function createName(path: [string], name: string): Node<Name> {
return {
type: 'Name',
start: 0,
end: 0,
moduleId: 0,
outerAttrs: [],
preComments: [],
commentStart: 0,
abs_path: false,
path: path.map(createIdentifier),
name: createIdentifier(name),
}
}
export function createPipeSubstitution(): Node<PipeSubstitution> {
return {
type: 'PipeSubstitution',

View File

@ -35,6 +35,7 @@ import {
createLabeledArg,
createLiteral,
createLocalName,
createName,
createObjectExpression,
createPipeSubstitution,
createUnaryExpression,
@ -612,7 +613,7 @@ const setAngledIntersectLineForLines: CreateStdLibSketchCallExpr = ({
270: 'THREE_QUARTER_TURN',
}
const angleVal = [0, 90, 180, 270].includes(angle)
? createLocalName(varNamMap[angle])
? createName(['turns'], varNamMap[angle])
: createLiteral(angle)
return intersectCallWrapper({
fnName: 'angledLineThatIntersects',
@ -665,7 +666,7 @@ const setAngleBetweenCreateNode =
firstHalfValue = createBinaryExpression([
firstHalfValue,
'+',
createLocalName('HALF_TURN'),
createName(['turns'], 'HALF_TURN'),
])
valueUsedInTransform = normaliseAngle(valueUsedInTransform - 180)
}