mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-07 13:22:07 -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) {
|
_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);
|
||||||
|
|
Loading…
Reference in a new issue