fix(core): Fixed bug in matrixTransform disregarding the rotation center if centerX is falsy
This commit is contained in:
parent
af0d371da3
commit
0ea7f192c4
1 changed files with 3 additions and 31 deletions
|
@ -803,7 +803,7 @@ function matrixTransform(transformationType, matrix, values) {
|
||||||
const centerY = values[2]
|
const centerY = values[2]
|
||||||
|
|
||||||
// if there's a rotation center, we need to move the origin to that center
|
// if there's a rotation center, we need to move the origin to that center
|
||||||
if (centerX) {
|
if (centerX !== undefined) {
|
||||||
matrix = matrixTransform('translate', matrix, [centerX, centerY])
|
matrix = matrixTransform('translate', matrix, [centerX, centerY])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -820,7 +820,7 @@ function matrixTransform(transformationType, matrix, values) {
|
||||||
]
|
]
|
||||||
|
|
||||||
// move the origin back to origin
|
// move the origin back to origin
|
||||||
if (centerX) {
|
if (centerX !== undefined) {
|
||||||
matrix = matrixTransform('translate', matrix, [-centerX, -centerY])
|
matrix = matrixTransform('translate', matrix, [-centerX, -centerY])
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
|
@ -875,35 +875,7 @@ export function applyTransformToPoint(transform, point) {
|
||||||
|
|
||||||
// The starting matrix
|
// The starting matrix
|
||||||
let matrix = [1, 0, 0, 1, 0, 0]
|
let matrix = [1, 0, 0, 1, 0, 0]
|
||||||
|
matrix = matrixTransform(name, matrix, values)
|
||||||
// Update matrix for transform
|
|
||||||
switch (name) {
|
|
||||||
case 'matrix':
|
|
||||||
matrix = values
|
|
||||||
break
|
|
||||||
case 'translate':
|
|
||||||
matrix[4] = values[0]
|
|
||||||
matrix[5] = values[1]
|
|
||||||
break
|
|
||||||
case 'scale':
|
|
||||||
matrix[0] = values[0]
|
|
||||||
matrix[3] = values[1]
|
|
||||||
break
|
|
||||||
case 'rotate': {
|
|
||||||
const angle = (values[0] * Math.PI) / 180
|
|
||||||
const cos = Math.cos(angle)
|
|
||||||
const sin = Math.sin(angle)
|
|
||||||
console.log('in rotate', { angle })
|
|
||||||
matrix = [cos, sin, -sin, cos, 0, 0]
|
|
||||||
break
|
|
||||||
}
|
|
||||||
case 'skewX':
|
|
||||||
matrix[2] = Math.tan((values[0] * Math.PI) / 180)
|
|
||||||
break
|
|
||||||
case 'skewY':
|
|
||||||
matrix[1] = Math.tan((values[0] * Math.PI) / 180)
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
// Apply the matrix transform to the coordinates
|
// Apply the matrix transform to the coordinates
|
||||||
const newX = point.x * matrix[0] + point.y * matrix[2] + matrix[4]
|
const newX = point.x * matrix[0] + point.y * matrix[2] + matrix[4]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue