Skip to content

Instantly share code, notes, and snippets.

@Zonciu
Created March 15, 2019 08:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Zonciu/8344c0cde9014dfb65cea0624f0b7b72 to your computer and use it in GitHub Desktop.
Save Zonciu/8344c0cde9014dfb65cea0624f0b7b72 to your computer and use it in GitHub Desktop.
Calculate point's real position after svg transforming.
/**
*
*
* @param {SVGSVGElement} svg: root svg element
* @param {number} x
* @param {number} y
* @param {SVGMatrix} ctm: element.getScreemCTM()
* @returns {SVGPoint} real position in container
*/
function GetPoint(svg: SVGSVGElement, x: number, y: number, ctm: SVGMatrix): SVGPoint {
let pt1 = svg.createSVGPoint();
pt1.x = x;
pt1.y = y;
const rootCTM = svg.getScreenCTM()!;
return pt1.matrixTransform(rootCTM.inverse().multiply(ctm));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment