Nadro/adhoc/center rectangle (#4480)
* fix: big commit, doing this to save work then do a PR cleanup; center rectangle * fix: making a center function for each scenario * fix: reverting the update rectangle code since I have a center rectangle one * fix: does not allow seletcing circle or rectangle tool while selecting a face * chore: adding comment to better read the HTML * fix: cleaning up for PR * fix: pushing broken code for someone to checkout * fix: fixed the typescript issues, removed the as keyword for my center rectangle expressions * fix: removing comment * fix: removed as for type narrowing checks
This commit is contained in:
@ -9,8 +9,16 @@ import {
|
||||
createUnaryExpression,
|
||||
} from 'lang/modifyAst'
|
||||
import { ArrayExpression, CallExpression, PipeExpression } from 'lang/wasm'
|
||||
import { roundOff } from 'lib/utils'
|
||||
import {
|
||||
isCallExpression,
|
||||
isArrayExpression,
|
||||
isLiteral,
|
||||
isBinaryExpression,
|
||||
} from 'lang/util'
|
||||
|
||||
/**
|
||||
* It does not create the startSketchOn and it does not create the startProfileAt.
|
||||
* Returns AST expressions for this KCL code:
|
||||
* const yo = startSketchOn('XY')
|
||||
* |> startProfileAt([0, 0], %)
|
||||
@ -92,3 +100,69 @@ export function updateRectangleSketch(
|
||||
createLiteral(Math.abs(y)), // This will be the height of the rectangle
|
||||
])
|
||||
}
|
||||
|
||||
/**
|
||||
* Mutates the pipeExpression to update the center rectangle sketch
|
||||
* @param pipeExpression
|
||||
* @param x
|
||||
* @param y
|
||||
* @param tag
|
||||
*/
|
||||
export function updateCenterRectangleSketch(
|
||||
pipeExpression: PipeExpression,
|
||||
deltaX: number,
|
||||
deltaY: number,
|
||||
tag: string,
|
||||
originX: number,
|
||||
originY: number
|
||||
) {
|
||||
let startX = originX - Math.abs(deltaX)
|
||||
let startY = originY - Math.abs(deltaY)
|
||||
|
||||
// pipeExpression.body[1] is startProfileAt
|
||||
let callExpression = pipeExpression.body[1]
|
||||
if (isCallExpression(callExpression)) {
|
||||
const arrayExpression = callExpression.arguments[0]
|
||||
if (isArrayExpression(arrayExpression)) {
|
||||
callExpression.arguments[0] = createArrayExpression([
|
||||
createLiteral(roundOff(startX)),
|
||||
createLiteral(roundOff(startY)),
|
||||
])
|
||||
}
|
||||
}
|
||||
|
||||
const twoX = deltaX * 2
|
||||
const twoY = deltaY * 2
|
||||
|
||||
callExpression = pipeExpression.body[2]
|
||||
if (isCallExpression(callExpression)) {
|
||||
const arrayExpression = callExpression.arguments[0]
|
||||
if (isArrayExpression(arrayExpression)) {
|
||||
const literal = arrayExpression.elements[0]
|
||||
if (isLiteral(literal)) {
|
||||
callExpression.arguments[0] = createArrayExpression([
|
||||
createLiteral(literal.value),
|
||||
createLiteral(Math.abs(twoX)),
|
||||
])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
callExpression = pipeExpression.body[3]
|
||||
if (isCallExpression(callExpression)) {
|
||||
const arrayExpression = callExpression.arguments[0]
|
||||
if (isArrayExpression(arrayExpression)) {
|
||||
const binaryExpression = arrayExpression.elements[0]
|
||||
if (isBinaryExpression(binaryExpression)) {
|
||||
callExpression.arguments[0] = createArrayExpression([
|
||||
createBinaryExpression([
|
||||
createCallExpressionStdLib('segAng', [createIdentifier(tag)]),
|
||||
binaryExpression.operator,
|
||||
createLiteral(90),
|
||||
]), // 90 offset from the previous line
|
||||
createLiteral(Math.abs(twoY)), // This will be the height of the rectangle
|
||||
])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user