Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit fcdcffe

Browse files
authoredJul 9, 2020
Merge pull request #581 from adroitwhiz/remove-set-rotation-center
Remove setRotationCenter API
2 parents 1c0928f + d9c854f commit fcdcffe

File tree

6 files changed

+24
-82
lines changed

6 files changed

+24
-82
lines changed
 

‎src/BitmapSkin.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ class BitmapSkin extends Skin {
9898
this._textureSize = BitmapSkin._getBitmapSize(bitmapData);
9999

100100
if (typeof rotationCenter === 'undefined') rotationCenter = this.calculateRotationCenter();
101-
this.setRotationCenter.apply(this, rotationCenter);
101+
this._rotationCenter[0] = rotationCenter[0];
102+
this._rotationCenter[1] = rotationCenter[1];
102103

103104
this.emit(Skin.Events.WasAltered);
104105
}

‎src/RenderWebGL.js

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1337,32 +1337,6 @@ class RenderWebGL extends EventEmitter {
13371337
drawable.skin = this._allSkins[skinId];
13381338
}
13391339

1340-
/**
1341-
* Update a drawable's skin rotation center.
1342-
* @param {number} drawableID The drawable's id.
1343-
* @param {Array.<number>} rotationCenter The rotation center for the skin.
1344-
*/
1345-
updateDrawableRotationCenter (drawableID, rotationCenter) {
1346-
const drawable = this._allDrawables[drawableID];
1347-
// TODO: https://github.com/LLK/scratch-vm/issues/2288
1348-
if (!drawable) return;
1349-
drawable.skin.setRotationCenter(rotationCenter[0], rotationCenter[1]);
1350-
}
1351-
1352-
/**
1353-
* Update a drawable's skin and rotation center together.
1354-
* @param {number} drawableID The drawable's id.
1355-
* @param {number} skinId The skin to update to.
1356-
* @param {Array.<number>} rotationCenter The rotation center for the skin.
1357-
*/
1358-
updateDrawableSkinIdRotationCenter (drawableID, skinId, rotationCenter) {
1359-
const drawable = this._allDrawables[drawableID];
1360-
// TODO: https://github.com/LLK/scratch-vm/issues/2288
1361-
if (!drawable) return;
1362-
drawable.skin = this._allSkins[skinId];
1363-
drawable.skin.setRotationCenter(rotationCenter[0], rotationCenter[1]);
1364-
}
1365-
13661340
/**
13671341
* Update a drawable's position.
13681342
* @param {number} drawableID The drawable's id.
@@ -1456,9 +1430,6 @@ class RenderWebGL extends EventEmitter {
14561430
if ('skinId' in properties) {
14571431
this.updateDrawableSkinId(drawableID, properties.skinId);
14581432
}
1459-
if ('rotationCenter' in properties) {
1460-
this.updateDrawableRotationCenter(drawableID, properties.rotationCenter);
1461-
}
14621433
drawable.updateProperties(properties);
14631434
}
14641435

‎src/SVGSkin.js

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,6 @@ class SVGSkin extends Skin {
5858
return this._svgRenderer.size;
5959
}
6060

61-
/**
62-
* Set the origin, in object space, about which this Skin should rotate.
63-
* @param {number} x - The x coordinate of the new rotation center.
64-
* @param {number} y - The y coordinate of the new rotation center.
65-
*/
66-
setRotationCenter (x, y) {
67-
const viewOffset = this._svgRenderer.viewOffset;
68-
super.setRotationCenter(x - viewOffset[0], y - viewOffset[1]);
69-
}
70-
7161
/**
7262
* Create a MIP for a given scale.
7363
* @param {number} scale - The relative size of the MIP
@@ -174,7 +164,10 @@ class SVGSkin extends Skin {
174164
this.resetMIPs();
175165

176166
if (typeof rotationCenter === 'undefined') rotationCenter = this.calculateRotationCenter();
177-
this.setRotationCenter.apply(this, rotationCenter);
167+
const viewOffset = this._svgRenderer.viewOffset;
168+
this._rotationCenter[0] = rotationCenter[0] - viewOffset[0];
169+
this._rotationCenter[1] = rotationCenter[1] - viewOffset[1];
170+
178171
this.emit(Skin.Events.WasAltered);
179172
});
180173
}

‎src/Skin.js

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,6 @@ const twgl = require('twgl.js');
55
const RenderConstants = require('./RenderConstants');
66
const Silhouette = require('./Silhouette');
77

8-
/**
9-
* Truncate a number into what could be stored in a 32 bit floating point value.
10-
* @param {number} num Number to truncate.
11-
* @return {number} Truncated value.
12-
*/
13-
const toFloat32 = (function () {
14-
const memory = new Float32Array(1);
15-
return function (num) {
16-
memory[0] = num;
17-
return memory[0];
18-
};
19-
}());
20-
218
class Skin extends EventEmitter {
229
/**
2310
* Create a Skin, which stores and/or generates textures for use in rendering.
@@ -101,26 +88,6 @@ class Skin extends EventEmitter {
10188
return [0, 0];
10289
}
10390

104-
/**
105-
* Set the origin, in object space, about which this Skin should rotate.
106-
* @param {number} x - The x coordinate of the new rotation center.
107-
* @param {number} y - The y coordinate of the new rotation center.
108-
* @fires Skin.event:WasAltered
109-
*/
110-
setRotationCenter (x, y) {
111-
const emptySkin = this.size[0] === 0 && this.size[1] === 0;
112-
// Compare a 32 bit x and y value against the stored 32 bit center
113-
// values.
114-
const changed = (
115-
toFloat32(x) !== this._rotationCenter[0] ||
116-
toFloat32(y) !== this._rotationCenter[1]);
117-
if (!emptySkin && changed) {
118-
this._rotationCenter[0] = x;
119-
this._rotationCenter[1] = y;
120-
this.emit(Skin.Events.WasAltered);
121-
}
122-
}
123-
12491
/**
12592
* Get the center of the current bounding box
12693
* @return {Array<number>} the center of the current bounding box

‎test/fixtures/MockSkin.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,16 @@ class MockSkin extends Skin {
88
get size () {
99
return this.dimensions || [0, 0];
1010
}
11+
12+
set rotationCenter (center) {
13+
this._rotationCenter[0] = center[0];
14+
this._rotationCenter[1] = center[1];
15+
this.emit(Skin.Events.WasAltered);
16+
}
17+
18+
get rotationCenter () {
19+
return this._rotationCenter;
20+
}
1121
}
1222

1323
module.exports = MockSkin;

‎test/unit/DrawableTests.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@ test('translate by costume center', t => {
4848
drawable.skin = new MockSkin();
4949
drawable.skin.size = [200, 50];
5050

51-
drawable.skin.setRotationCenter(1, 0);
51+
drawable.skin.rotationCenter = [1, 0];
5252
expected.initFromBounds(-1, 199, -50, 0);
5353
t.same(snapToNearest(drawable.getAABB()), expected);
5454

55-
drawable.skin.setRotationCenter(0, -2);
55+
drawable.skin.rotationCenter = [0, -2];
5656
expected.initFromBounds(0, 200, -52, -2);
5757
t.same(snapToNearest(drawable.getAABB()), expected);
5858

@@ -73,7 +73,7 @@ test('translate and rotate', t => {
7373
expected.initFromBounds(-49, 1, -198, 2);
7474
t.same(snapToNearest(drawable.getAABB()), expected);
7575

76-
drawable.skin.setRotationCenter(100, 25);
76+
drawable.skin.rotationCenter = [100, 25];
7777
drawable.updateProperties({direction: 270, position: [0, 0]});
7878
expected.initFromBounds(-100, 100, -25, 25);
7979
t.same(snapToNearest(drawable.getAABB()), expected);
@@ -89,7 +89,7 @@ test('rotate by non-right-angles', t => {
8989
const drawable = new Drawable();
9090
drawable.skin = new MockSkin();
9191
drawable.skin.size = [10, 10];
92-
drawable.skin.setRotationCenter(5, 5);
92+
drawable.skin.rotationCenter = [5, 5];
9393

9494
expected.initFromBounds(-5, 5, -5, 5);
9595
t.same(snapToNearest(drawable.getAABB()), expected);
@@ -111,11 +111,11 @@ test('scale', t => {
111111
expected.initFromBounds(0, 200, -25, 0);
112112
t.same(snapToNearest(drawable.getAABB()), expected);
113113

114-
drawable.skin.setRotationCenter(0, 25);
114+
drawable.skin.rotationCenter = [0, 25];
115115
expected.initFromBounds(0, 200, -12.5, 12.5);
116116
t.same(snapToNearest(drawable.getAABB()), expected);
117117

118-
drawable.skin.setRotationCenter(150, 50);
118+
drawable.skin.rotationCenter = [150, 50];
119119
drawable.updateProperties({scale: [50, 50]});
120120
expected.initFromBounds(-75, 25, 0, 25);
121121
t.same(snapToNearest(drawable.getAABB()), expected);
@@ -129,12 +129,12 @@ test('rotate and scale', t => {
129129
drawable.skin = new MockSkin();
130130
drawable.skin.size = [100, 1000];
131131

132-
drawable.skin.setRotationCenter(50, 50);
132+
drawable.skin.rotationCenter = [50, 50];
133133
expected.initFromBounds(-50, 50, -950, 50);
134134
t.same(snapToNearest(drawable.getAABB()), expected);
135135

136136
drawable.updateProperties({scale: [40, 60]});
137-
drawable.skin.setRotationCenter(50, 50);
137+
drawable.skin.rotationCenter = [50, 50];
138138
expected.initFromBounds(-20, 20, -570, 30);
139139
t.same(snapToNearest(drawable.getAABB()), expected);
140140

0 commit comments

Comments
 (0)
Please sign in to comment.