Skip to content

Commit 36e618c

Browse files
committed
Address Yury's review comments + remove call to addCtxCurrentTransform in pattern.js as the contet is added during the CanvasGraphics constructor already
1 parent a30f0ff commit 36e618c

File tree

2 files changed

+23
-20
lines changed

2 files changed

+23
-20
lines changed

src/canvas.js

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ function ScratchCanvas(width, height) {
5959
return canvas;
6060
}
6161

62-
function addCtxCurrentTransform(ctx) {
62+
function addContextCurrentTransform(ctx) {
6363
// If the context doesn't expose a `mozCurrentTransform`, add a JS based on.
6464
if (!ctx.mozCurrentTransform) {
6565
// Store the original context
@@ -73,29 +73,34 @@ function addCtxCurrentTransform(ctx) {
7373
ctx._transformMatrix = [1, 0, 0, 1, 0, 0];
7474
ctx._transformStack = [];
7575

76-
ctx.__defineGetter__('mozCurrentTransform', function getCurrentTransform() {
77-
return this._transformMatrix;
76+
Object.defineProperty(ctx, 'mozCurrentTransform', {
77+
get: function getCurrentTransform() {
78+
return this._transformMatrix;
79+
}
7880
});
7981

80-
ctx.__defineGetter__('mozCurrentTransformInverse',
81-
function getCurrentTransformInverse() {
82+
Object.defineProperty(ctx, 'mozCurrentTransformInverse', {
83+
get: function getCurrentTransformInverse() {
8284
// Calculation done using WolframAlpha:
8385
// http://www.wolframalpha.com/input/?
8486
// i=Inverse+{{a%2C+c%2C+e}%2C+{b%2C+d%2C+f}%2C+{0%2C+0%2C+1}}
8587

8688
var m = this._transformMatrix;
8789
var a = m[0], b = m[1], c = m[2], d = m[3], e = m[4], f = m[5];
8890

91+
var ad_bc = a * d - b * c;
92+
var bc_ad = b * c - a * d;
93+
8994
return [
90-
d / (a * d - b * c),
91-
b / (b * c - a * d),
92-
c / (b * c - a * d),
93-
a / (a * d - b * c),
94-
(d * e - c * f) / (b * c - a * d),
95-
(b * e - a * f) / (a * d - b * c)
95+
d / ad_bc,
96+
b / bc_ad,
97+
c / bc_ad,
98+
a / ad_bc,
99+
(d * e - c * f) / bc_ad,
100+
(b * e - a * f) / ad_bc
96101
];
97102
}
98-
);
103+
});
99104

100105
ctx.save = function ctxSave() {
101106
var old = this._transformMatrix;
@@ -111,15 +116,15 @@ function addCtxCurrentTransform(ctx) {
111116
this._transformMatrix = prev;
112117
this._originalRestore();
113118
}
114-
}
119+
};
115120

116121
ctx.translate = function ctxTranslate(x, y) {
117122
var m = this._transformMatrix;
118123
m[4] = m[0] * x + m[2] * y + m[4];
119124
m[5] = m[1] * x + m[3] * y + m[5];
120125

121126
this._originalTranslate(x, y);
122-
}
127+
};
123128

124129
ctx.scale = function ctxScale(x, y) {
125130
var m = this._transformMatrix;
@@ -129,7 +134,7 @@ function addCtxCurrentTransform(ctx) {
129134
m[3] = m[3] * y;
130135

131136
this._originalScale(x, y);
132-
}
137+
};
133138

134139
ctx.transform = function ctxTransform(a, b, c, d, e, f) {
135140
var m = this._transformMatrix;
@@ -143,7 +148,7 @@ function addCtxCurrentTransform(ctx) {
143148
];
144149

145150
ctx._originalTransform(a, b, c, d, e, f);
146-
}
151+
};
147152

148153
ctx.rotate = function ctxRotate(angle) {
149154
var cosValue = Math.cos(angle);
@@ -160,7 +165,7 @@ function addCtxCurrentTransform(ctx) {
160165
];
161166

162167
this._originalRotate(angle);
163-
}
168+
};
164169
}
165170
}
166171

@@ -184,7 +189,7 @@ var CanvasGraphics = (function canvasGraphics() {
184189
this.objs = objs;
185190

186191
if (canvasCtx) {
187-
addCtxCurrentTransform(canvasCtx);
192+
addContextCurrentTransform(canvasCtx);
188193
}
189194
}
190195

src/pattern.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,6 @@ var TilingPattern = (function tilingPattern() {
217217

218218
// set the new canvas element context as the graphics context
219219
var tmpCtx = tmpCanvas.getContext('2d');
220-
addCtxCurrentTransform(tmpCtx);
221-
222220
var graphics = new CanvasGraphics(tmpCtx, objs);
223221

224222
switch (paintType) {

0 commit comments

Comments
 (0)