/* * Copyright (C) 2019 Intel Corporation * SPDX-License-Identifier: MIT */ // Translate point array from the client coordinate system // to a coordinate system of a canvas export function translateFromSVG(svg: SVGSVGElement, points: number[]): number[] { const output = []; const transformationMatrix = svg.getScreenCTM(); let pt = svg.createSVGPoint(); for (let i = 0; i < points.length - 1; i += 2) { pt.x = points[i]; pt.y = points[i + 1]; pt = pt.matrixTransform(transformationMatrix); output.push(pt.x, pt.y); } return output; } // Translate point array from a coordinate system of a canvas // to the client coordinate system export function translateToSVG(svg: SVGSVGElement, points: number[]): number[] { const output = []; const transformationMatrix = svg.getScreenCTM().inverse(); let pt = svg.createSVGPoint(); for (let i = 0; i < points.length; i += 2) { pt.x = points[i]; pt.y = points[i + 1]; pt = pt.matrixTransform(transformationMatrix); output.push(pt.x, pt.y); } return output; }