```  1 /**
2  * Returns a new identity transform.
3  *
4  * @class Represents a transformation matrix. The transformation matrix is
5  * limited to expressing translate and uniform scale transforms only; shearing,
6  * rotation, general affine, and other transforms are not supported.
7  *
8  * <p>The methods on this class treat the transform as immutable, returning a
9  * copy of the transformation matrix with the specified transform applied. Note,
10  * alternatively, that the matrix fields can be get and set directly.
11  */
12 pv.Transform = function() {};
13 pv.Transform.prototype = {k: 1, x: 0, y: 0};
14
15 /**
16  * The scale magnitude; defaults to 1.
17  *
18  * @type number
19  * @name pv.Transform.prototype.k
20  */
21
22 /**
23  * The x-offset; defaults to 0.
24  *
25  * @type number
26  * @name pv.Transform.prototype.x
27  */
28
29 /**
30  * The y-offset; defaults to 0.
31  *
32  * @type number
33  * @name pv.Transform.prototype.y
34  */
35
36 /**
37  * @private The identity transform.
38  *
39  * @type pv.Transform
40  */
41 pv.Transform.identity = new pv.Transform();
42
43 // k 0 x   1 0 a   k 0 ka+x
44 // 0 k y * 0 1 b = 0 k kb+y
45 // 0 0 1   0 0 1   0 0 1
46
47 /**
48  * Returns a translated copy of this transformation matrix.
49  *
50  * @param {number} x the x-offset.
51  * @param {number} y the y-offset.
52  * @returns {pv.Transform} the translated transformation matrix.
53  */
54 pv.Transform.prototype.translate = function(x, y) {
55   var v = new pv.Transform();
56   v.k = this.k;
57   v.x = this.k * x + this.x;
58   v.y = this.k * y + this.y;
59   return v;
60 };
61
62 // k 0 x   d 0 0   kd  0 x
63 // 0 k y * 0 d 0 =  0 kd y
64 // 0 0 1   0 0 1    0  0 1
65
66 /**
67  * Returns a scaled copy of this transformation matrix.
68  *
69  * @param {number} k
70  * @returns {pv.Transform} the scaled transformation matrix.
71  */
72 pv.Transform.prototype.scale = function(k) {
73   var v = new pv.Transform();
74   v.k = this.k * k;
75   v.x = this.x;
76   v.y = this.y;
77   return v;
78 };
79
80 /**
81  * Returns the inverse of this transformation matrix.
82  *
83  * @returns {pv.Transform} the inverted transformation matrix.
84  */
85 pv.Transform.prototype.invert = function() {
86   var v = new pv.Transform(), k = 1 / this.k;
87   v.k = k;
88   v.x = -this.x * k;
89   v.y = -this.y * k;
90   return v;
91 };
92
93 // k 0 x   d 0 a   kd  0 ka+x
94 // 0 k y * 0 d b =  0 kd kb+y
95 // 0 0 1   0 0 1    0  0    1
96
97 /**
98  * Returns this matrix post-multiplied by the specified matrix <i>m</i>.
99  *
100  * @param {pv.Transform} m
101  * @returns {pv.Transform} the post-multiplied transformation matrix.
102  */
103 pv.Transform.prototype.times = function(m) {
104   var v = new pv.Transform();
105   v.k = this.k * m.k;
106   v.x = this.k * m.x + this.x;
107   v.y = this.k * m.y + this.y;
108   return v;
109 };
110 ```