diff options
| author | jmoenig <jens@moenig.org> | 2014-12-03 12:42:46 +0100 |
|---|---|---|
| committer | jmoenig <jens@moenig.org> | 2014-12-03 12:42:46 +0100 |
| commit | d94d9ff4e85b50ce57e4c62d63250994c4b9b4c7 (patch) | |
| tree | 28382f0dcebf183defae6a86ae221eb4a2244101 | |
| parent | 19736839b7c73af5ae3b40d826bc161a78dd0114 (diff) | |
| download | snap-d94d9ff4e85b50ce57e4c62d63250994c4b9b4c7.tar.gz snap-d94d9ff4e85b50ce57e4c62d63250994c4b9b4c7.zip | |
Cache actual bounding box of the Pen arrow shape
for improved collision detection
| -rw-r--r-- | morphic.js | 19 |
1 files changed, 13 insertions, 6 deletions
@@ -1041,7 +1041,7 @@ /*global window, HTMLCanvasElement, getMinimumFontHeight, FileReader, Audio, FileList, getBlurredShadowSupport*/ -var morphicVersion = '2014-November-20'; +var morphicVersion = '2014-December-03'; var modules = {}; // keep track of additional loaded modules var useBlurredShadows = getBlurredShadowSupport(); // check for Chrome-bug @@ -3978,6 +3978,7 @@ PenMorph.prototype.init = function () { this.size = 1; this.wantsRedraw = false; this.penPoint = 'tip'; // or 'center" + this.penBounds = null; // rect around the visible arrow shape HandleMorph.uber.init.call(this); this.setExtent(new Point(size, size)); @@ -4000,11 +4001,9 @@ PenMorph.prototype.changed = function () { // PenMorph display: PenMorph.prototype.drawNew = function (facing) { -/* - my orientation can be overridden with the "facing" parameter to - implement Scratch-style rotation styles + // my orientation can be overridden with the "facing" parameter to + // implement Scratch-style rotation styles -*/ var context, start, dest, left, right, len, direction = facing || this.heading; @@ -4027,6 +4026,15 @@ PenMorph.prototype.drawNew = function (facing) { right = start.distanceAngle(len * 0.33, direction - 230); } + // cache penBounds + this.penBounds = new Rectangle( + Math.min(start.x, dest.x, left.x, right.x), + Math.min(start.y, dest.y, left.y, right.y), + Math.max(start.x, dest.x, left.x, right.x), + Math.max(start.y, dest.y, left.y, right.y) + ); + + // draw arrow shape context.fillStyle = this.color.toString(); context.beginPath(); @@ -4043,7 +4051,6 @@ PenMorph.prototype.drawNew = function (facing) { context.lineWidth = 1; context.stroke(); context.fill(); - }; // PenMorph access: |
