mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-01 02:38:43 -05:00
Shorten code a bit.
This commit is contained in:
parent
ad34bbf7aa
commit
541ac6acce
1 changed files with 19 additions and 18 deletions
|
@ -55,24 +55,25 @@ new function() {
|
|||
attrs[center ? 'cy' : 'y'] = point.y;
|
||||
trans = null;
|
||||
}
|
||||
if (matrix.isIdentity())
|
||||
return attrs;
|
||||
// See if we can decompose the matrix and can formulate it as a simple
|
||||
// translate/scale/rotate command sequence.
|
||||
var decomposed = matrix.decompose();
|
||||
if (decomposed && !decomposed.shearing) {
|
||||
var parts = [],
|
||||
angle = decomposed.rotation,
|
||||
scale = decomposed.scaling;
|
||||
if (trans && !trans.isZero())
|
||||
parts.push('translate(' + formatter.point(trans) + ')');
|
||||
if (angle)
|
||||
parts.push('rotate(' + formatter.number(angle) + ')');
|
||||
if (!Numerical.isZero(scale.x - 1) || !Numerical.isZero(scale.y - 1))
|
||||
parts.push('scale(' + formatter.point(scale) +')');
|
||||
attrs.transform = parts.join(' ');
|
||||
} else {
|
||||
attrs.transform = 'matrix(' + matrix.getValues().join(',') + ')';
|
||||
if (!matrix.isIdentity()) {
|
||||
// See if we can decompose the matrix and can formulate it as a
|
||||
// simple translate/scale/rotate command sequence.
|
||||
var decomposed = matrix.decompose();
|
||||
if (decomposed && !decomposed.shearing) {
|
||||
var parts = [],
|
||||
angle = decomposed.rotation,
|
||||
scale = decomposed.scaling;
|
||||
if (trans && !trans.isZero())
|
||||
parts.push('translate(' + formatter.point(trans) + ')');
|
||||
if (angle)
|
||||
parts.push('rotate(' + formatter.number(angle) + ')');
|
||||
if (!Numerical.isZero(scale.x - 1)
|
||||
|| !Numerical.isZero(scale.y - 1))
|
||||
parts.push('scale(' + formatter.point(scale) +')');
|
||||
attrs.transform = parts.join(' ');
|
||||
} else {
|
||||
attrs.transform = 'matrix(' + matrix.getValues().join(',') + ')';
|
||||
}
|
||||
}
|
||||
return attrs;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue