Use Math.ceil and Math.floor to match Scratch 2 logic

This commit is contained in:
Katie Broida 2019-02-04 15:46:01 -05:00
parent b4f9f28417
commit c8b9516219
2 changed files with 4 additions and 5 deletions
src
test/integration/scratch-tests

View file

@ -1316,21 +1316,20 @@ class RenderWebGL extends EventEmitter {
const dx = x - drawable._position[0];
const dy = y - drawable._position[1];
const aabb = drawable.getFastBounds();
const inset = Math.floor(Math.min(aabb.width, aabb.height) / 2);
const sx = this._xRight - Math.min(FENCE_WIDTH, inset);
if (aabb.right + dx < -sx) {
x = drawable._position[0] - (sx + aabb.right);
x = Math.ceil(drawable._position[0] - (sx + aabb.right));
} else if (aabb.left + dx > sx) {
x = drawable._position[0] + (sx - aabb.left);
x = Math.floor(drawable._position[0] + (sx - aabb.left));
}
const sy = this._yTop - Math.min(FENCE_WIDTH, inset);
if (aabb.top + dy < -sy) {
y = drawable._position[1] - (sy + aabb.top);
y = Math.ceil(drawable._position[1] - (sy + aabb.top));
} else if (aabb.bottom + dy > sy) {
y = drawable._position[1] + (sy - aabb.bottom);
y = Math.floor(drawable._position[1] + (sy - aabb.bottom));
}
return [x, y];
}