Fix: applies the transformation of the parent element in addition to … (#839)

* Fix: applies the transformation of the parent element in addition to that of the selected element

* Fix:  delete debug logs and use a ternary operator
master
cg-scorpio 2022-10-14 20:17:49 +02:00 committed by GitHub
parent b6f8158200
commit e2ad8211a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 18 additions and 2 deletions

View File

@ -8,7 +8,8 @@
import { isWebkit } from '../../src/common/browser.js'
import { getRotationAngle, getBBox, getStrokedBBox } from './utilities.js'
import { transformListToTransform, transformBox, transformPoint } from './math.js'
import { transformListToTransform, transformBox, transformPoint, matrixMultiply } from './math.js'
import { NS } from './namespaces'
let svgCanvas
let selectorManager_ // A Singleton
@ -122,9 +123,24 @@ export class Selector {
offset += 2 / zoom
}
// find the transformations applied to the parent of the selected element
const svg = document.createElementNS(NS.SVG, 'svg')
let parentTransformationMatrix = svg.createSVGMatrix()
let currentElt = selected
while (currentElt.parentNode) {
if (currentElt.parentNode && currentElt.parentNode.tagName === 'g' && currentElt.parentNode.transform) {
if (currentElt.parentNode.transform.baseVal.numberOfItems) {
parentTransformationMatrix = matrixMultiply(transformListToTransform(selected.parentNode.transform.baseVal).matrix, parentTransformationMatrix)
}
}
currentElt = currentElt.parentNode
}
// loop and transform our bounding box until we reach our first rotation
const tlist = selected.transform.baseVal
const m = transformListToTransform(tlist).matrix
// combines the parent transformation with that of the selected element if necessary
const m = parentTransformationMatrix ? matrixMultiply(parentTransformationMatrix, transformListToTransform(tlist).matrix) : transformListToTransform(tlist).matrix
// This should probably be handled somewhere else, but for now
// it keeps the selection box correctly positioned when zoomed