Fix matrix cloning for groups with #applyMatrix = false

Closes #1225
This commit is contained in:
Jürg Lehni 2016-12-30 13:25:08 +01:00
parent c12f7c4a64
commit 771bb61038
4 changed files with 30 additions and 7 deletions

View file

@ -70,16 +70,20 @@ var Matrix = Base.extend(/** @lends Matrix# */{
* @name Matrix#initialize
* @param {Matrix} matrix the matrix to copy the values from
*/
initialize: function Matrix(arg) {
initialize: function Matrix(arg, _dontNotify) {
var count = arguments.length,
ok = true;
if (count === 6) {
if (count >= 6) { // >= 6 to pass on optional _dontNotify argument.
this._set.apply(this, arguments);
} else if (count === 1) {
} else if (count === 1 || count === 2) {
// Support both Matrix and Array arguments through #_set(), and pass
// on the optional _dontNotify argument:
if (arg instanceof Matrix) {
this._set(arg._a, arg._b, arg._c, arg._d, arg._tx, arg._ty);
this._set(arg._a, arg._b, arg._c, arg._d, arg._tx, arg._ty,
_dontNotify);
} else if (Array.isArray(arg)) {
this._set.apply(this, arg);
this._set.apply(this,
_dontNotify ? arg.concat([_dontNotify]) : arg);
} else {
ok = false;
}

View file

@ -1562,7 +1562,7 @@ new function() { // Injection scope for various item event handlers
}
// Use Matrix#initialize to easily copy over values.
if (!excludeMatrix)
this._matrix.set(source._matrix);
this._matrix.set(source._matrix, true);
// We can't just set _applyMatrix as many item types won't allow it,
// e.g. creating a Shape in Path#toShape().
// Using the setter instead takes care of it.

View file

@ -179,3 +179,22 @@ test('Item#clone() Hierarchy', function() {
return clone.isBelow(path2);
}, true);
});
test('Item#clone() and #applyMatrix (#1225)', function() {
var group = new Group({
applyMatrix: false,
children: [
new Shape.Rectangle({
size: [100, 100],
point: [100, 100],
strokeColor: 'red',
})
]
});
group.translate(300, 300);
equals(function() {
return group.clone().matrix.translation;
}, new Point(300, 300));
});

View file

@ -122,7 +122,7 @@ test('PathItem#create() with SVG path-data (#1101)', function() {
test('PathItem#compare()', function() {
var empty = new Path();
var circle = new Path.Circle({
point: [100, 100],
center: [100, 100],
radius: 100
});
var square = new Path.Rectangle({