chore: add test helpers for connecting blocks (#7258)

* chore: get procedure test passing on linux

* chore: cleanup

* chore: format
This commit is contained in:
Beka Westberg
2023-07-06 15:35:58 -07:00
committed by GitHub
parent eb4025bb61
commit 07ba841850
4 changed files with 121 additions and 31 deletions

View File

@@ -262,7 +262,6 @@ export class RenderedConnection extends Connection {
* Get the offset of this connection relative to the top left of its block.
*
* @returns The offset of the connection.
* @internal
*/
getOffsetInBlock(): Coordinate {
return this.offsetInBlock;

View File

@@ -175,6 +175,34 @@ export function screenToWsCoordinates(
return finalOffsetMainWs;
}
/**
* Converts workspace coordinates to screen coordinates.
*
* @param ws The workspace to get the coordinates out of.
* @param workspaceCoordinates The workspace coordinates to be converted
* to screen coordinates.
* @returns The screen coordinates.
*/
export function wsToScreenCoordinates(
ws: WorkspaceSvg,
workspaceCoordinates: Coordinate
): Coordinate {
// Fix workspace scale vs browser scale.
const screenCoordinates = workspaceCoordinates.scale(ws.scale);
const screenX = screenCoordinates.x;
const screenY = screenCoordinates.y;
const injectionDiv = ws.getInjectionDiv();
const boundingRect = injectionDiv.getBoundingClientRect();
const mainOffset = ws.getOriginOffsetInPixels();
// Fix workspace origin vs browser origin.
return new Coordinate(
screenX + boundingRect.left + mainOffset.x,
screenY + boundingRect.top + mainOffset.y
);
}
export const TEST_ONLY = {
XY_REGEX,
XY_STYLE_REGEX,