Shorten code a bit.

This commit is contained in:
Jürg Lehni 2014-01-02 21:47:20 +01:00
parent ad34bbf7aa
commit 541ac6acce

View file

@ -55,10 +55,9 @@ new function() {
attrs[center ? 'cy' : 'y'] = point.y; attrs[center ? 'cy' : 'y'] = point.y;
trans = null; trans = null;
} }
if (matrix.isIdentity()) if (!matrix.isIdentity()) {
return attrs; // See if we can decompose the matrix and can formulate it as a
// See if we can decompose the matrix and can formulate it as a simple // simple translate/scale/rotate command sequence.
// translate/scale/rotate command sequence.
var decomposed = matrix.decompose(); var decomposed = matrix.decompose();
if (decomposed && !decomposed.shearing) { if (decomposed && !decomposed.shearing) {
var parts = [], var parts = [],
@ -68,12 +67,14 @@ new function() {
parts.push('translate(' + formatter.point(trans) + ')'); parts.push('translate(' + formatter.point(trans) + ')');
if (angle) if (angle)
parts.push('rotate(' + formatter.number(angle) + ')'); parts.push('rotate(' + formatter.number(angle) + ')');
if (!Numerical.isZero(scale.x - 1) || !Numerical.isZero(scale.y - 1)) if (!Numerical.isZero(scale.x - 1)
|| !Numerical.isZero(scale.y - 1))
parts.push('scale(' + formatter.point(scale) +')'); parts.push('scale(' + formatter.point(scale) +')');
attrs.transform = parts.join(' '); attrs.transform = parts.join(' ');
} else { } else {
attrs.transform = 'matrix(' + matrix.getValues().join(',') + ')'; attrs.transform = 'matrix(' + matrix.getValues().join(',') + ')';
} }
}
return attrs; return attrs;
} }