MCPcopy
hub / github.com/razorjack/quicksand / unmatrix

Function unmatrix

jquery.transform2d.js:370–418  ·  view source on GitHub ↗
(matrix)

Source from the content-addressed store, hash-verified

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
370function 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

Callers 2

interpolationListFunction · 0.85
parseFunctionFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…