import type { PropertyBag } from '../model/Properties'; import { defaultsFor } from './PropertySchema'; /** Axis-aligned rectangle in world units. */ export interface WorldRect { left: number; top: number; right: number; bottom: number; } /** * Size of the world region a camera shows, in world units: its view size divided by its * zoom. This is the frame drawn in edit mode and the only region rendered in play mode. */ export function cameraFrame(props: PropertyBag): { w: number; h: number } { const d = defaultsFor('camera'); const zoom = Math.max(0.01, Number(props.zoom ?? d.zoom)); return { w: Number(props.width ?? d.width) / zoom, h: Number(props.height ?? d.height) / zoom }; } export function rectAround(cx: number, cy: number, w: number, h: number): WorldRect { return { left: cx - w / 2, top: cy - h / 2, right: cx + w / 2, bottom: cy + h / 2 }; } export function rectsIntersect(a: WorldRect, b: WorldRect): boolean { return a.left < b.right && a.right > b.left && a.top < b.bottom && a.bottom > b.top; }