libraries/EaselJS_docs/files/easeljs_geom_Matrix2D.js.html (view raw)
1<!DOCTYPE html>
2<html lang="en">
3<head>
4 <meta charset="utf-8">
5 <link rel="stylesheet" href="../assets/css/yui-cssgrids-min.css">
6 <link rel="stylesheet" href="../assets/vendor/prettify/prettify-min.css">
7 <link rel="stylesheet" href="../assets/css/main.css" id="site_styles">
8 <link rel="shortcut icon" type="image/x-icon" href="../assets/favicon.ico">
9 <script src="../assets/js/yui-source.js"></script>
10 <title>EaselJS v1.0.0 API Documentation : easeljs/geom/Matrix2D.js</title>
11</head>
12<body class="yui3-skin-sam">
13
14<div id="doc">
15 <div id="hd" class="yui3-g header">
16 <div class="yui3-u-3-4">
17
18 <h1><a href="http://www.createjs.com/easeljs"><img src="../assets/docs-icon-EaselJS.png" title="EaselJS"></a></h1>
19
20 </div>
21 <div class="version">
22 <em>API Documentation for: 1.0.0</em>
23 </div>
24 </div>
25 <div id="bd" class="yui3-g">
26
27 <div class="yui3-u-1-4">
28 <div id="docs-sidebar" class="sidebar apidocs">
29 <div id="api-list">
30 <h2 class="off-left">APIs</h2>
31 <div id="api-tabview" class="tabview">
32 <ul class="tabs">
33 <li><a href="#api-classes">Classes</a></li>
34 </ul>
35
36 <div id="api-tabview-filter">
37 <input type="search" id="api-filter" placeholder="Type to filter APIs">
38 </div>
39
40 <div id="api-tabview-panel">
41 <ul id="api-classes" class="apis classes">
42
43 <li><a href="../classes/AlphaMapFilter.html">AlphaMapFilter</a></li>
44
45 <li><a href="../classes/AlphaMaskFilter.html">AlphaMaskFilter</a></li>
46
47 <li><a href="../classes/Bitmap.html">Bitmap</a></li>
48
49 <li><a href="../classes/BitmapCache.html">BitmapCache</a></li>
50
51 <li><a href="../classes/BitmapText.html">BitmapText</a></li>
52
53 <li><a href="../classes/BlurFilter.html">BlurFilter</a></li>
54
55 <li><a href="../classes/ButtonHelper.html">ButtonHelper</a></li>
56
57 <li><a href="../classes/ColorFilter.html">ColorFilter</a></li>
58
59 <li><a href="../classes/ColorMatrix.html">ColorMatrix</a></li>
60
61 <li><a href="../classes/ColorMatrixFilter.html">ColorMatrixFilter</a></li>
62
63 <li><a href="../classes/Container.html">Container</a></li>
64
65 <li><a href="../classes/DisplayObject.html">DisplayObject</a></li>
66
67 <li><a href="../classes/DisplayProps.html">DisplayProps</a></li>
68
69 <li><a href="../classes/DOMElement.html">DOMElement</a></li>
70
71 <li><a href="../classes/EaselJS.html">EaselJS</a></li>
72
73 <li><a href="../classes/Event.html">Event</a></li>
74
75 <li><a href="../classes/EventDispatcher.html">EventDispatcher</a></li>
76
77 <li><a href="../classes/Filter.html">Filter</a></li>
78
79 <li><a href="../classes/Graphics.html">Graphics</a></li>
80
81 <li><a href="../classes/Graphics.Arc.html">Graphics.Arc</a></li>
82
83 <li><a href="../classes/Graphics.ArcTo.html">Graphics.ArcTo</a></li>
84
85 <li><a href="../classes/Graphics.BeginPath.html">Graphics.BeginPath</a></li>
86
87 <li><a href="../classes/Graphics.BezierCurveTo.html">Graphics.BezierCurveTo</a></li>
88
89 <li><a href="../classes/Graphics.Circle.html">Graphics.Circle</a></li>
90
91 <li><a href="../classes/Graphics.ClosePath.html">Graphics.ClosePath</a></li>
92
93 <li><a href="../classes/Graphics.Ellipse.html">Graphics.Ellipse</a></li>
94
95 <li><a href="../classes/Graphics.Fill.html">Graphics.Fill</a></li>
96
97 <li><a href="../classes/Graphics.LineTo.html">Graphics.LineTo</a></li>
98
99 <li><a href="../classes/Graphics.MoveTo.html">Graphics.MoveTo</a></li>
100
101 <li><a href="../classes/Graphics.PolyStar.html">Graphics.PolyStar</a></li>
102
103 <li><a href="../classes/Graphics.QuadraticCurveTo.html">Graphics.QuadraticCurveTo</a></li>
104
105 <li><a href="../classes/Graphics.Rect.html">Graphics.Rect</a></li>
106
107 <li><a href="../classes/Graphics.RoundRect.html">Graphics.RoundRect</a></li>
108
109 <li><a href="../classes/Graphics.Stroke.html">Graphics.Stroke</a></li>
110
111 <li><a href="../classes/Graphics.StrokeDash.html">Graphics.StrokeDash</a></li>
112
113 <li><a href="../classes/Graphics.StrokeStyle.html">Graphics.StrokeStyle</a></li>
114
115 <li><a href="../classes/Matrix2D.html">Matrix2D</a></li>
116
117 <li><a href="../classes/MouseEvent.html">MouseEvent</a></li>
118
119 <li><a href="../classes/MovieClip.html">MovieClip</a></li>
120
121 <li><a href="../classes/MovieClipPlugin.html">MovieClipPlugin</a></li>
122
123 <li><a href="../classes/Point.html">Point</a></li>
124
125 <li><a href="../classes/Rectangle.html">Rectangle</a></li>
126
127 <li><a href="../classes/Shadow.html">Shadow</a></li>
128
129 <li><a href="../classes/Shape.html">Shape</a></li>
130
131 <li><a href="../classes/Sprite.html">Sprite</a></li>
132
133 <li><a href="../classes/SpriteSheet.html">SpriteSheet</a></li>
134
135 <li><a href="../classes/SpriteSheetBuilder.html">SpriteSheetBuilder</a></li>
136
137 <li><a href="../classes/SpriteSheetUtils.html">SpriteSheetUtils</a></li>
138
139 <li><a href="../classes/Stage.html">Stage</a></li>
140
141 <li><a href="../classes/StageGL.html">StageGL</a></li>
142
143 <li><a href="../classes/Text.html">Text</a></li>
144
145 <li><a href="../classes/Ticker.html">Ticker</a></li>
146
147 <li><a href="../classes/Touch.html">Touch</a></li>
148
149 <li><a href="../classes/UID.html">UID</a></li>
150
151 <li><a href="../classes/Utility Methods.html">Utility Methods</a></li>
152
153 <li><a href="../classes/VideoBuffer.html">VideoBuffer</a></li>
154
155 <li><a href="../classes/WebGLInspector.html">WebGLInspector</a></li>
156
157 </ul>
158
159 <ul id="api-modules" class="apis modules">
160
161 <li><a href="../modules/CreateJS.html">CreateJS</a></li>
162
163 <li><a href="../modules/EaselJS.html">EaselJS</a></li>
164
165 </ul>
166 </div>
167 </div>
168</div>
169
170 </div>
171 </div>
172 <div class="yui3-u-3-4">
173 <div id="api-options">
174 Show:
175 <label for="api-show-inherited">
176 <input type="checkbox" id="api-show-inherited" checked>
177 Inherited
178 </label>
179
180 <label for="api-show-protected">
181 <input type="checkbox" id="api-show-protected">
182 Protected
183 </label>
184
185 <label for="api-show-private">
186 <input type="checkbox" id="api-show-private">
187 Private
188 </label>
189 <label for="api-show-deprecated">
190 <input type="checkbox" id="api-show-deprecated">
191 Deprecated
192 </label>
193
194 </div>
195 <div class="apidocs">
196 <div id="docs-main">
197 <div class="content source-content">
198 <script>
199 var name = easeljs/geom/Matrix2D.js
200</script>
201<h1 class="file-heading">File:Matrix2D.js</h1>
202
203<div class="file">
204 <pre class="code prettyprint linenums">
205/*
206* Matrix2D
207* Visit http://createjs.com/ for documentation, updates and examples.
208*
209* Copyright (c) 2010 gskinner.com, inc.
210*
211* Permission is hereby granted, free of charge, to any person
212* obtaining a copy of this software and associated documentation
213* files (the "Software"), to deal in the Software without
214* restriction, including without limitation the rights to use,
215* copy, modify, merge, publish, distribute, sublicense, and/or sell
216* copies of the Software, and to permit persons to whom the
217* Software is furnished to do so, subject to the following
218* conditions:
219*
220* The above copyright notice and this permission notice shall be
221* included in all copies or substantial portions of the Software.
222*
223* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
224* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
225* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
226* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
227* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
228* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
229* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
230* OTHER DEALINGS IN THE SOFTWARE.
231*/
232
233/**
234 * @module EaselJS
235 */
236
237// namespace:
238this.createjs = this.createjs||{};
239
240(function() {
241 "use strict";
242
243
244// constructor:
245 /**
246 * Represents an affine transformation matrix, and provides tools for constructing and concatenating matrices.
247 *
248 * This matrix can be visualized as:
249 *
250 * [ a c tx
251 * b d ty
252 * 0 0 1 ]
253 *
254 * Note the locations of b and c.
255 *
256 * @class Matrix2D
257 * @param {Number} [a=1] Specifies the a property for the new matrix.
258 * @param {Number} [b=0] Specifies the b property for the new matrix.
259 * @param {Number} [c=0] Specifies the c property for the new matrix.
260 * @param {Number} [d=1] Specifies the d property for the new matrix.
261 * @param {Number} [tx=0] Specifies the tx property for the new matrix.
262 * @param {Number} [ty=0] Specifies the ty property for the new matrix.
263 * @constructor
264 **/
265 function Matrix2D(a, b, c, d, tx, ty) {
266 this.setValues(a,b,c,d,tx,ty);
267
268 // public properties:
269 // assigned in the setValues method.
270 /**
271 * Position (0, 0) in a 3x3 affine transformation matrix.
272 * @property a
273 * @type Number
274 **/
275
276 /**
277 * Position (0, 1) in a 3x3 affine transformation matrix.
278 * @property b
279 * @type Number
280 **/
281
282 /**
283 * Position (1, 0) in a 3x3 affine transformation matrix.
284 * @property c
285 * @type Number
286 **/
287
288 /**
289 * Position (1, 1) in a 3x3 affine transformation matrix.
290 * @property d
291 * @type Number
292 **/
293
294 /**
295 * Position (2, 0) in a 3x3 affine transformation matrix.
296 * @property tx
297 * @type Number
298 **/
299
300 /**
301 * Position (2, 1) in a 3x3 affine transformation matrix.
302 * @property ty
303 * @type Number
304 **/
305 }
306 var p = Matrix2D.prototype;
307
308// constants:
309 /**
310 * Multiplier for converting degrees to radians. Used internally by Matrix2D.
311 * @property DEG_TO_RAD
312 * @static
313 * @final
314 * @type Number
315 * @readonly
316 **/
317 Matrix2D.DEG_TO_RAD = Math.PI/180;
318
319
320// static public properties:
321 /**
322 * An identity matrix, representing a null transformation.
323 * @property identity
324 * @static
325 * @type Matrix2D
326 * @readonly
327 **/
328 Matrix2D.identity = null; // set at bottom of class definition.
329
330
331// public methods:
332 /**
333 * Sets the specified values on this instance.
334 * @method setValues
335 * @param {Number} [a=1] Specifies the a property for the new matrix.
336 * @param {Number} [b=0] Specifies the b property for the new matrix.
337 * @param {Number} [c=0] Specifies the c property for the new matrix.
338 * @param {Number} [d=1] Specifies the d property for the new matrix.
339 * @param {Number} [tx=0] Specifies the tx property for the new matrix.
340 * @param {Number} [ty=0] Specifies the ty property for the new matrix.
341 * @return {Matrix2D} This instance. Useful for chaining method calls.
342 */
343 p.setValues = function(a, b, c, d, tx, ty) {
344 // don't forget to update docs in the constructor if these change:
345 this.a = (a == null) ? 1 : a;
346 this.b = b || 0;
347 this.c = c || 0;
348 this.d = (d == null) ? 1 : d;
349 this.tx = tx || 0;
350 this.ty = ty || 0;
351 return this;
352 };
353
354 /**
355 * Appends the specified matrix properties to this matrix. All parameters are required.
356 * This is the equivalent of multiplying `(this matrix) * (specified matrix)`.
357 * @method append
358 * @param {Number} a
359 * @param {Number} b
360 * @param {Number} c
361 * @param {Number} d
362 * @param {Number} tx
363 * @param {Number} ty
364 * @return {Matrix2D} This matrix. Useful for chaining method calls.
365 **/
366 p.append = function(a, b, c, d, tx, ty) {
367 var a1 = this.a;
368 var b1 = this.b;
369 var c1 = this.c;
370 var d1 = this.d;
371 if (a != 1 || b != 0 || c != 0 || d != 1) {
372 this.a = a1*a+c1*b;
373 this.b = b1*a+d1*b;
374 this.c = a1*c+c1*d;
375 this.d = b1*c+d1*d;
376 }
377 this.tx = a1*tx+c1*ty+this.tx;
378 this.ty = b1*tx+d1*ty+this.ty;
379 return this;
380 };
381
382 /**
383 * Prepends the specified matrix properties to this matrix.
384 * This is the equivalent of multiplying `(specified matrix) * (this matrix)`.
385 * All parameters are required.
386 * @method prepend
387 * @param {Number} a
388 * @param {Number} b
389 * @param {Number} c
390 * @param {Number} d
391 * @param {Number} tx
392 * @param {Number} ty
393 * @return {Matrix2D} This matrix. Useful for chaining method calls.
394 **/
395 p.prepend = function(a, b, c, d, tx, ty) {
396 var a1 = this.a;
397 var c1 = this.c;
398 var tx1 = this.tx;
399
400 this.a = a*a1+c*this.b;
401 this.b = b*a1+d*this.b;
402 this.c = a*c1+c*this.d;
403 this.d = b*c1+d*this.d;
404 this.tx = a*tx1+c*this.ty+tx;
405 this.ty = b*tx1+d*this.ty+ty;
406 return this;
407 };
408
409 /**
410 * Appends the specified matrix to this matrix.
411 * This is the equivalent of multiplying `(this matrix) * (specified matrix)`.
412 * @method appendMatrix
413 * @param {Matrix2D} matrix
414 * @return {Matrix2D} This matrix. Useful for chaining method calls.
415 **/
416 p.appendMatrix = function(matrix) {
417 return this.append(matrix.a, matrix.b, matrix.c, matrix.d, matrix.tx, matrix.ty);
418 };
419
420 /**
421 * Prepends the specified matrix to this matrix.
422 * This is the equivalent of multiplying `(specified matrix) * (this matrix)`.
423 * For example, you could calculate the combined transformation for a child object using:
424 *
425 * var o = myDisplayObject;
426 * var mtx = o.getMatrix();
427 * while (o = o.parent) {
428 * // prepend each parent's transformation in turn:
429 * o.prependMatrix(o.getMatrix());
430 * }
431 * @method prependMatrix
432 * @param {Matrix2D} matrix
433 * @return {Matrix2D} This matrix. Useful for chaining method calls.
434 **/
435 p.prependMatrix = function(matrix) {
436 return this.prepend(matrix.a, matrix.b, matrix.c, matrix.d, matrix.tx, matrix.ty);
437 };
438
439 /**
440 * Generates matrix properties from the specified display object transform properties, and appends them to this matrix.
441 * For example, you can use this to generate a matrix representing the transformations of a display object:
442 *
443 * var mtx = new createjs.Matrix2D();
444 * mtx.appendTransform(o.x, o.y, o.scaleX, o.scaleY, o.rotation);
445 * @method appendTransform
446 * @param {Number} x
447 * @param {Number} y
448 * @param {Number} scaleX
449 * @param {Number} scaleY
450 * @param {Number} rotation
451 * @param {Number} skewX
452 * @param {Number} skewY
453 * @param {Number} regX Optional.
454 * @param {Number} regY Optional.
455 * @return {Matrix2D} This matrix. Useful for chaining method calls.
456 **/
457 p.appendTransform = function(x, y, scaleX, scaleY, rotation, skewX, skewY, regX, regY) {
458 if (rotation%360) {
459 var r = rotation*Matrix2D.DEG_TO_RAD;
460 var cos = Math.cos(r);
461 var sin = Math.sin(r);
462 } else {
463 cos = 1;
464 sin = 0;
465 }
466
467 if (skewX || skewY) {
468 // TODO: can this be combined into a single append operation?
469 skewX *= Matrix2D.DEG_TO_RAD;
470 skewY *= Matrix2D.DEG_TO_RAD;
471 this.append(Math.cos(skewY), Math.sin(skewY), -Math.sin(skewX), Math.cos(skewX), x, y);
472 this.append(cos*scaleX, sin*scaleX, -sin*scaleY, cos*scaleY, 0, 0);
473 } else {
474 this.append(cos*scaleX, sin*scaleX, -sin*scaleY, cos*scaleY, x, y);
475 }
476
477 if (regX || regY) {
478 // append the registration offset:
479 this.tx -= regX*this.a+regY*this.c;
480 this.ty -= regX*this.b+regY*this.d;
481 }
482 return this;
483 };
484
485 /**
486 * Generates matrix properties from the specified display object transform properties, and prepends them to this matrix.
487 * For example, you could calculate the combined transformation for a child object using:
488 *
489 * var o = myDisplayObject;
490 * var mtx = new createjs.Matrix2D();
491 * do {
492 * // prepend each parent's transformation in turn:
493 * mtx.prependTransform(o.x, o.y, o.scaleX, o.scaleY, o.rotation, o.skewX, o.skewY, o.regX, o.regY);
494 * } while (o = o.parent);
495 *
496 * Note that the above example would not account for {{#crossLink "DisplayObject/transformMatrix:property"}}{{/crossLink}}
497 * values. See {{#crossLink "Matrix2D/prependMatrix"}}{{/crossLink}} for an example that does.
498 * @method prependTransform
499 * @param {Number} x
500 * @param {Number} y
501 * @param {Number} scaleX
502 * @param {Number} scaleY
503 * @param {Number} rotation
504 * @param {Number} skewX
505 * @param {Number} skewY
506 * @param {Number} regX Optional.
507 * @param {Number} regY Optional.
508 * @return {Matrix2D} This matrix. Useful for chaining method calls.
509 **/
510 p.prependTransform = function(x, y, scaleX, scaleY, rotation, skewX, skewY, regX, regY) {
511 if (rotation%360) {
512 var r = rotation*Matrix2D.DEG_TO_RAD;
513 var cos = Math.cos(r);
514 var sin = Math.sin(r);
515 } else {
516 cos = 1;
517 sin = 0;
518 }
519
520 if (regX || regY) {
521 // prepend the registration offset:
522 this.tx -= regX; this.ty -= regY;
523 }
524 if (skewX || skewY) {
525 // TODO: can this be combined into a single prepend operation?
526 skewX *= Matrix2D.DEG_TO_RAD;
527 skewY *= Matrix2D.DEG_TO_RAD;
528 this.prepend(cos*scaleX, sin*scaleX, -sin*scaleY, cos*scaleY, 0, 0);
529 this.prepend(Math.cos(skewY), Math.sin(skewY), -Math.sin(skewX), Math.cos(skewX), x, y);
530 } else {
531 this.prepend(cos*scaleX, sin*scaleX, -sin*scaleY, cos*scaleY, x, y);
532 }
533 return this;
534 };
535
536 /**
537 * Applies a clockwise rotation transformation to the matrix.
538 * @method rotate
539 * @param {Number} angle The angle to rotate by, in degrees. To use a value in radians, multiply it by `180/Math.PI`.
540 * @return {Matrix2D} This matrix. Useful for chaining method calls.
541 **/
542 p.rotate = function(angle) {
543 angle = angle*Matrix2D.DEG_TO_RAD;
544 var cos = Math.cos(angle);
545 var sin = Math.sin(angle);
546
547 var a1 = this.a;
548 var b1 = this.b;
549
550 this.a = a1*cos+this.c*sin;
551 this.b = b1*cos+this.d*sin;
552 this.c = -a1*sin+this.c*cos;
553 this.d = -b1*sin+this.d*cos;
554 return this;
555 };
556
557 /**
558 * Applies a skew transformation to the matrix.
559 * @method skew
560 * @param {Number} skewX The amount to skew horizontally in degrees. To use a value in radians, multiply it by `180/Math.PI`.
561 * @param {Number} skewY The amount to skew vertically in degrees.
562 * @return {Matrix2D} This matrix. Useful for chaining method calls.
563 */
564 p.skew = function(skewX, skewY) {
565 skewX = skewX*Matrix2D.DEG_TO_RAD;
566 skewY = skewY*Matrix2D.DEG_TO_RAD;
567 this.append(Math.cos(skewY), Math.sin(skewY), -Math.sin(skewX), Math.cos(skewX), 0, 0);
568 return this;
569 };
570
571 /**
572 * Applies a scale transformation to the matrix.
573 * @method scale
574 * @param {Number} x The amount to scale horizontally. E.G. a value of 2 will double the size in the X direction, and 0.5 will halve it.
575 * @param {Number} y The amount to scale vertically.
576 * @return {Matrix2D} This matrix. Useful for chaining method calls.
577 **/
578 p.scale = function(x, y) {
579 this.a *= x;
580 this.b *= x;
581 this.c *= y;
582 this.d *= y;
583 //this.tx *= x;
584 //this.ty *= y;
585 return this;
586 };
587
588 /**
589 * Translates the matrix on the x and y axes.
590 * @method translate
591 * @param {Number} x
592 * @param {Number} y
593 * @return {Matrix2D} This matrix. Useful for chaining method calls.
594 **/
595 p.translate = function(x, y) {
596 this.tx += this.a*x + this.c*y;
597 this.ty += this.b*x + this.d*y;
598 return this;
599 };
600
601 /**
602 * Sets the properties of the matrix to those of an identity matrix (one that applies a null transformation).
603 * @method identity
604 * @return {Matrix2D} This matrix. Useful for chaining method calls.
605 **/
606 p.identity = function() {
607 this.a = this.d = 1;
608 this.b = this.c = this.tx = this.ty = 0;
609 return this;
610 };
611
612 /**
613 * Inverts the matrix, causing it to perform the opposite transformation.
614 * @method invert
615 * @return {Matrix2D} This matrix. Useful for chaining method calls.
616 **/
617 p.invert = function() {
618 var a1 = this.a;
619 var b1 = this.b;
620 var c1 = this.c;
621 var d1 = this.d;
622 var tx1 = this.tx;
623 var n = a1*d1-b1*c1;
624
625 this.a = d1/n;
626 this.b = -b1/n;
627 this.c = -c1/n;
628 this.d = a1/n;
629 this.tx = (c1*this.ty-d1*tx1)/n;
630 this.ty = -(a1*this.ty-b1*tx1)/n;
631 return this;
632 };
633
634 /**
635 * Returns true if the matrix is an identity matrix.
636 * @method isIdentity
637 * @return {Boolean}
638 **/
639 p.isIdentity = function() {
640 return this.tx === 0 && this.ty === 0 && this.a === 1 && this.b === 0 && this.c === 0 && this.d === 1;
641 };
642
643 /**
644 * Returns true if this matrix is equal to the specified matrix (all property values are equal).
645 * @method equals
646 * @param {Matrix2D} matrix The matrix to compare.
647 * @return {Boolean}
648 **/
649 p.equals = function(matrix) {
650 return this.tx === matrix.tx && this.ty === matrix.ty && this.a === matrix.a && this.b === matrix.b && this.c === matrix.c && this.d === matrix.d;
651 };
652
653 /**
654 * Transforms a point according to this matrix.
655 * @method transformPoint
656 * @param {Number} x The x component of the point to transform.
657 * @param {Number} y The y component of the point to transform.
658 * @param {Point | Object} [pt] An object to copy the result into. If omitted a generic object with x/y properties will be returned.
659 * @return {Point} This matrix. Useful for chaining method calls.
660 **/
661 p.transformPoint = function(x, y, pt) {
662 pt = pt||{};
663 pt.x = x*this.a+y*this.c+this.tx;
664 pt.y = x*this.b+y*this.d+this.ty;
665 return pt;
666 };
667
668 /**
669 * Decomposes the matrix into transform properties (x, y, scaleX, scaleY, and rotation). Note that these values
670 * may not match the transform properties you used to generate the matrix, though they will produce the same visual
671 * results.
672 * @method decompose
673 * @param {Object} target The object to apply the transform properties to. If null, then a new object will be returned.
674 * @return {Object} The target, or a new generic object with the transform properties applied.
675 */
676 p.decompose = function(target) {
677 // TODO: it would be nice to be able to solve for whether the matrix can be decomposed into only scale/rotation even when scale is negative
678 if (target == null) { target = {}; }
679 target.x = this.tx;
680 target.y = this.ty;
681 target.scaleX = Math.sqrt(this.a * this.a + this.b * this.b);
682 target.scaleY = Math.sqrt(this.c * this.c + this.d * this.d);
683
684 var skewX = Math.atan2(-this.c, this.d);
685 var skewY = Math.atan2(this.b, this.a);
686
687 var delta = Math.abs(1-skewX/skewY);
688 if (delta < 0.00001) { // effectively identical, can use rotation:
689 target.rotation = skewY/Matrix2D.DEG_TO_RAD;
690 if (this.a < 0 && this.d >= 0) {
691 target.rotation += (target.rotation <= 0) ? 180 : -180;
692 }
693 target.skewX = target.skewY = 0;
694 } else {
695 target.skewX = skewX/Matrix2D.DEG_TO_RAD;
696 target.skewY = skewY/Matrix2D.DEG_TO_RAD;
697 }
698 return target;
699 };
700
701 /**
702 * Copies all properties from the specified matrix to this matrix.
703 * @method copy
704 * @param {Matrix2D} matrix The matrix to copy properties from.
705 * @return {Matrix2D} This matrix. Useful for chaining method calls.
706 */
707 p.copy = function(matrix) {
708 return this.setValues(matrix.a, matrix.b, matrix.c, matrix.d, matrix.tx, matrix.ty);
709 };
710
711 /**
712 * Returns a clone of the Matrix2D instance.
713 * @method clone
714 * @return {Matrix2D} a clone of the Matrix2D instance.
715 **/
716 p.clone = function() {
717 return new Matrix2D(this.a, this.b, this.c, this.d, this.tx, this.ty);
718 };
719
720 /**
721 * Returns a string representation of this object.
722 * @method toString
723 * @return {String} a string representation of the instance.
724 **/
725 p.toString = function() {
726 return "[Matrix2D (a="+this.a+" b="+this.b+" c="+this.c+" d="+this.d+" tx="+this.tx+" ty="+this.ty+")]";
727 };
728
729 // this has to be populated after the class is defined:
730 Matrix2D.identity = new Matrix2D();
731
732
733 createjs.Matrix2D = Matrix2D;
734}());
735
736 </pre>
737</div>
738
739 </div>
740 </div>
741 </div>
742 </div>
743 </div>
744</div>
745<script src="../assets/vendor/prettify/prettify-min.js"></script>
746<script>prettyPrint();</script>
747<script src="../assets/js/yui-prettify.js"></script>
748<script src="../assets/../api.js"></script>
749<script src="../assets/js/api-filter.js"></script>
750<script src="../assets/js/api-list.js"></script>
751<script src="../assets/js/api-search.js"></script>
752<script src="../assets/js/apidocs.js"></script>
753</body>
754</html>