-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Nadro/adhoc/center rectangle #4480
base: main
Are you sure you want to change the base?
Changes from all commits
46c2d41
913025a
5e92dff
04e0306
ed34c08
bf69461
e4cc180
1a30ddb
2209535
e9c9902
471f227
4f2a3e0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (comment): Kurt's done some cool work to make this stuff less boilerplate-filled, and I'd love your ideas as you touch code like this on how to take it further, because it still feels repetitive and "getting your hands dirty", na mean? |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (comment): I didn't know about this syntax, super cool |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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,64 @@ 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 | ||
;((pipeExpression.body[1] as CallExpression) | ||
.arguments[0] as ArrayExpression) = createArrayExpression([ | ||
Comment on lines
+123
to
+124
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (nit): Should this make use of your new cool type narrowing functions as well? |
||
createLiteral(roundOff(startX)), | ||
createLiteral(roundOff(startY)), | ||
]) | ||
|
||
const twoX = deltaX * 2 | ||
const twoY = deltaY * 2 | ||
|
||
let callExpression = pipeExpression.body[2] | ||
if (isCallExpression(callExpression)) { | ||
let 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)) { | ||
let 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 | ||
]) | ||
} | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(comment):
...followed by like 40 lines of JSX lol