Created
March 15, 2019 08:47
-
-
Save Zonciu/8344c0cde9014dfb65cea0624f0b7b72 to your computer and use it in GitHub Desktop.
Calculate point's real position after svg transforming.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* | |
* | |
* @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