Skip to content

Commit 116e4a6

Browse files
committed
fence bounds
1 parent bf47f69 commit 116e4a6

File tree

4 files changed

+12
-5
lines changed

4 files changed

+12
-5
lines changed

src/BitmapSkin.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,11 @@ class BitmapSkin extends Skin {
6262
/**
6363
* Get the bounds of the drawable for determining its fenced position.
6464
* @param {Array<number>} drawable - The Drawable instance this skin is using.
65+
* @param {?Rectangle} bounds - Optional destination for bounds calculation.
6566
* @return {!Rectangle} The drawable's bounds. For compatibility with Scratch 2, we always use getAABB for bitmaps.
6667
*/
67-
getFenceBounds (drawable) {
68-
return drawable.getAABB();
68+
getFenceBounds (drawable, bounds) {
69+
return drawable.getAABB(bounds);
6970
}
7071

7172
/**

src/Drawable.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,7 @@ class Drawable {
451451
* This function applies the transform matrix to the known convex hull,
452452
* and then finds the minimum box along the axes.
453453
* Before calling this, ensure the renderer has updated convex hull points.
454+
* @param {?Rectangle} bounds optional destination for bounds calculation
454455
* @return {!Rectangle} Bounds for a tight box around the Drawable.
455456
*/
456457
getBounds (bounds) {
@@ -471,6 +472,7 @@ class Drawable {
471472
* Get the precise bounds for the upper 8px slice of the Drawable.
472473
* Used for calculating where to position a text bubble.
473474
* Before calling this, ensure the renderer has updated convex hull points.
475+
* @param {?Rectangle} bounds optional destination for bounds calculation
474476
* @return {!Rectangle} Bounds for a tight box around a slice of the Drawable.
475477
*/
476478
getBoundsForBubble (bounds) {
@@ -497,6 +499,7 @@ class Drawable {
497499
* which is tightly snapped to account for a Drawable's transparent regions.
498500
* `getAABB` returns a much less accurate bounding box, but will be much
499501
* faster to calculate so may be desired for quick checks/optimizations.
502+
* @param {?Rectangle} bounds optional destination for bounds calculation
500503
* @return {!Rectangle} Rough axis-aligned bounding box for Drawable.
501504
*/
502505
getAABB (bounds) {
@@ -513,6 +516,7 @@ class Drawable {
513516
* Return the best Drawable bounds possible without performing graphics queries.
514517
* I.e., returns the tight bounding box when the convex hull points are already
515518
* known, but otherwise return the rough AABB of the Drawable.
519+
* @param {?Rectangle} bounds optional destination for bounds calculation
516520
* @return {!Rectangle} Bounds for the Drawable.
517521
*/
518522
getFastBounds (bounds) {

src/RenderWebGL.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const log = require('./util/log');
1616

1717
const __isTouchingDrawablesPoint = twgl.v3.create();
1818
const __candidatesBounds = new Rectangle();
19+
const __fenceBounds = new Rectangle();
1920
const __touchingColor = new Uint8ClampedArray(4);
2021
const __blendColor = new Uint8ClampedArray(4);
2122

@@ -1357,7 +1358,7 @@ class RenderWebGL extends EventEmitter {
13571358

13581359
const dx = x - drawable._position[0];
13591360
const dy = y - drawable._position[1];
1360-
const aabb = drawable._skin.getFenceBounds(drawable);
1361+
const aabb = drawable._skin.getFenceBounds(drawable, __fenceBounds);
13611362
const inset = Math.floor(Math.min(aabb.width, aabb.height) / 2);
13621363

13631364
const sx = this._xRight - Math.min(FENCE_WIDTH, inset);
@@ -1627,14 +1628,14 @@ class RenderWebGL extends EventEmitter {
16271628
}
16281629

16291630
twgl.setUniforms(currentShader, uniforms);
1630-
1631+
16311632
/* adjust blend function for this skin */
16321633
if (drawable.skin.hasPremultipliedAlpha){
16331634
gl.blendFuncSeparate(gl.ONE, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
16341635
} else {
16351636
gl.blendFuncSeparate(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
16361637
}
1637-
1638+
16381639
twgl.drawBufferInfo(gl, this._bufferInfo, gl.TRIANGLES);
16391640
}
16401641

src/Skin.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ class Skin extends EventEmitter {
146146
/**
147147
* Get the bounds of the drawable for determining its fenced position.
148148
* @param {Array<number>} drawable - The Drawable instance this skin is using.
149+
* @param {?Rectangle} bounds - Optional destination for bounds calculation.
149150
* @return {!Rectangle} The drawable's bounds.
150151
*/
151152
getFenceBounds (drawable, bounds) {

0 commit comments

Comments
 (0)