Implement stroke hittesting for Shape.Rectangle.

This commit is contained in:
Jürg Lehni 2013-06-13 10:40:54 -07:00
parent 48fa889e0d
commit ae474131cc

View file

@ -69,7 +69,7 @@ var Shape = Item.extend(/** @lends Shape# */{
_getBounds: function(getter, matrix) { _getBounds: function(getter, matrix) {
var rect = new Rectangle(this._size).setCenter(0, 0); var rect = new Rectangle(this._size).setCenter(0, 0);
if (this.hasStroke()) if (getter !== 'getBounds' && this.hasStroke())
rect = rect.expand(this.getStrokeWidth()); rect = rect.expand(this.getStrokeWidth());
return matrix ? matrix._transformBounds(rect) : rect; return matrix ? matrix._transformBounds(rect) : rect;
}, },
@ -90,7 +90,11 @@ var Shape = Item.extend(/** @lends Shape# */{
strokeWidth = this.getStrokeWidth(); strokeWidth = this.getStrokeWidth();
switch (type) { switch (type) {
case 'rect': case 'rect':
// TODO: Implement stroke! var rect = new Rectangle(this._size).setCenter(0, 0),
outer = rect.expand(strokeWidth),
inner = rect.expand(-strokeWidth);
if (outer._containsPoint(point) && !inner._containsPoint(point))
return new HitResult('stroke', this);
break; break;
case 'circle': case 'circle':
case 'ellipse': case 'ellipse':
@ -110,6 +114,7 @@ var Shape = Item.extend(/** @lends Shape# */{
} }
if (2 * Math.abs(point.getLength() - radius) <= strokeWidth) if (2 * Math.abs(point.getLength() - radius) <= strokeWidth)
return new HitResult('stroke', this); return new HitResult('stroke', this);
break;
} }
} }
return _hitTest.base.apply(this, arguments); return _hitTest.base.apply(this, arguments);