1 export class Geometry {
3 static distance(x1: number, y1: number, x2: number, y2: number) {
4 return Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2));
7 static getTransformToElement(from: SVGElement, to: SVGElement) {
8 const getPosition = (node: SVGGElement, addE = 0, addF = 0): SVGMatrix => {
10 if (!node.ownerSVGElement) {
11 // node is the root svg element
12 const matrix = (node as SVGSVGElement).createSVGMatrix();
17 // node still has parent elements
18 const {e, f} = node.transform.baseVal.getItem(0).matrix;
19 return getPosition(<SVGGElement>node.parentNode, e + addE, f + addF);
23 const toPosition = getPosition(to as SVGAElement);
24 const fromPosition = getPosition(from as SVGAElement);
26 const result = from.ownerSVGElement!.createSVGMatrix();
27 result.e = toPosition.e - fromPosition.e;
28 result.f = toPosition.f - fromPosition.f;
30 return result.inverse();