move some more stuff around

This commit is contained in:
Joeri Exelmans 2025-10-25 23:46:35 +02:00
parent 400efff3a1
commit 99180e63ce
18 changed files with 32 additions and 32 deletions

30
src/util/svg_helper.ts Normal file
View file

@ -0,0 +1,30 @@
import { Rect2D } from "./geometry";
// author: ChatGPT
export function getBBoxInSvgCoords(el: SVGGraphicsElement, svg: SVGSVGElement): Rect2D {
const b = el.getBBox();
const m = el.getCTM()!;
const toSvg = (x: number, y: number) => {
const p = svg.createSVGPoint();
p.x = x; p.y = y;
return p.matrixTransform(m);
};
const pts = [
toSvg(b.x, b.y),
toSvg(b.x + b.width, b.y),
toSvg(b.x, b.y + b.height),
toSvg(b.x + b.width, b.y + b.height)
];
const xs = pts.map(p => p.x);
const ys = pts.map(p => p.y);
return {
topLeft: {
x: Math.min(...xs),
y: Math.min(...ys),
},
size: {
x: Math.max(...xs) - Math.min(...xs),
y: Math.max(...ys) - Math.min(...ys),
},
};
}