13 lines
558 B
TypeScript
13 lines
558 B
TypeScript
import type { Rect } from "@core/geometry";
|
|
import type { ViewportState } from "@editor/state";
|
|
import type { ScreenRect } from "./types";
|
|
|
|
export function documentRectToScreenRect(canvas: HTMLCanvasElement, rect: Rect, viewport: ViewportState): ScreenRect {
|
|
return {
|
|
x: Math.round(canvas.width / 2 + (rect.x - viewport.center.x) * viewport.zoom),
|
|
y: Math.round(canvas.height / 2 + (rect.y - viewport.center.y) * viewport.zoom),
|
|
w: Math.max(0, Math.round(rect.w * viewport.zoom)),
|
|
h: Math.max(0, Math.round(rect.h * viewport.zoom)),
|
|
};
|
|
}
|