mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-03 19:45:44 -05:00
Implement stroke hittesting for Shape.Rectangle.
This commit is contained in:
parent
48fa889e0d
commit
ae474131cc
1 changed files with 7 additions and 2 deletions
|
@ -69,7 +69,7 @@ var Shape = Item.extend(/** @lends Shape# */{
|
|||
|
||||
_getBounds: function(getter, matrix) {
|
||||
var rect = new Rectangle(this._size).setCenter(0, 0);
|
||||
if (this.hasStroke())
|
||||
if (getter !== 'getBounds' && this.hasStroke())
|
||||
rect = rect.expand(this.getStrokeWidth());
|
||||
return matrix ? matrix._transformBounds(rect) : rect;
|
||||
},
|
||||
|
@ -90,7 +90,11 @@ var Shape = Item.extend(/** @lends Shape# */{
|
|||
strokeWidth = this.getStrokeWidth();
|
||||
switch (type) {
|
||||
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;
|
||||
case 'circle':
|
||||
case 'ellipse':
|
||||
|
@ -110,6 +114,7 @@ var Shape = Item.extend(/** @lends Shape# */{
|
|||
}
|
||||
if (2 * Math.abs(point.getLength() - radius) <= strokeWidth)
|
||||
return new HitResult('stroke', this);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return _hitTest.base.apply(this, arguments);
|
||||
|
|
Loading…
Reference in a new issue