(matrix)
| 368 | // turns a matrix into its rotate, scale and skew components |
| 369 | // algorithm from http://hg.mozilla.org/mozilla-central/file/7cb3e9795d04/layout/style/nsStyleAnimation.cpp |
| 370 | function unmatrix(matrix) { |
| 371 | var |
| 372 | scaleX |
| 373 | , scaleY |
| 374 | , skew |
| 375 | , A = matrix[0] |
| 376 | , B = matrix[1] |
| 377 | , C = matrix[2] |
| 378 | , D = matrix[3] |
| 379 | ; |
| 380 | |
| 381 | // Make sure matrix is not singular |
| 382 | if ( A * D - B * C ) { |
| 383 | // step (3) |
| 384 | scaleX = Math.sqrt( A * A + B * B ); |
| 385 | A /= scaleX; |
| 386 | B /= scaleX; |
| 387 | // step (4) |
| 388 | skew = A * C + B * D; |
| 389 | C -= A * skew; |
| 390 | D -= B * skew; |
| 391 | // step (5) |
| 392 | scaleY = Math.sqrt( C * C + D * D ); |
| 393 | C /= scaleY; |
| 394 | D /= scaleY; |
| 395 | skew /= scaleY; |
| 396 | // step (6) |
| 397 | if ( A * D < B * C ) { |
| 398 | A = -A; |
| 399 | B = -B; |
| 400 | skew = -skew; |
| 401 | scaleX = -scaleX; |
| 402 | } |
| 403 | |
| 404 | // matrix is singular and cannot be interpolated |
| 405 | } else { |
| 406 | // In this case the elem shouldn't be rendered, hence scale == 0 |
| 407 | scaleX = scaleY = skew = 0; |
| 408 | } |
| 409 | |
| 410 | // The recomposition order is very important |
| 411 | // see http://hg.mozilla.org/mozilla-central/file/7cb3e9795d04/layout/style/nsStyleAnimation.cpp#l971 |
| 412 | return [ |
| 413 | [_translate, [+matrix[4], +matrix[5]]], |
| 414 | [_rotate, Math.atan2(B, A)], |
| 415 | [_skew + "X", Math.atan(skew)], |
| 416 | [_scale, [scaleX, scaleY]] |
| 417 | ]; |
| 418 | } |
| 419 | |
| 420 | // build the list of transform functions to interpolate |
| 421 | // use the algorithm described at http://dev.w3.org/csswg/css3-2d-transforms/#animation |
no outgoing calls
no test coverage detected
searching dependent graphs…