mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-19 14:10:14 -05:00
Fix #977: Apply hit-testing tolerance to fills in Shape.
This commit is contained in:
parent
6975690824
commit
4081afb635
2 changed files with 10 additions and 6 deletions
|
@ -344,13 +344,17 @@ new function() { // Scope for _contains() and _hitTestSelf() code.
|
||||||
_hitTestSelf: function _hitTestSelf(point, options, viewMatrix,
|
_hitTestSelf: function _hitTestSelf(point, options, viewMatrix,
|
||||||
strokeMatrix) {
|
strokeMatrix) {
|
||||||
var hit = false,
|
var hit = false,
|
||||||
style = this._style;
|
style = this._style,
|
||||||
if (options.stroke && style.hasStroke()) {
|
hitStroke = options.stroke && style.hasStroke(),
|
||||||
|
hitFill = options.fill && style.hasFill();
|
||||||
|
// Just like in Path, use stroke-hit-tests also for hitting fill
|
||||||
|
// with tolerance:
|
||||||
|
if (hitStroke || hitFill) {
|
||||||
var type = this._type,
|
var type = this._type,
|
||||||
radius = this._radius,
|
radius = this._radius,
|
||||||
strokeWidth = style.getStrokeWidth(),
|
strokeRadius = hitStroke ? style.getStrokeWidth() / 2 : 0;
|
||||||
strokePadding = options._tolerancePadding.add(
|
strokePadding = options._tolerancePadding.add(
|
||||||
Path._getStrokePadding(strokeWidth / 2,
|
Path._getStrokePadding(strokeRadius,
|
||||||
!style.getStrokeScaling() && strokeMatrix));
|
!style.getStrokeScaling() && strokeMatrix));
|
||||||
if (type === 'rectangle') {
|
if (type === 'rectangle') {
|
||||||
var padding = strokePadding.multiply(2),
|
var padding = strokePadding.multiply(2),
|
||||||
|
@ -370,7 +374,7 @@ new function() { // Scope for _contains() and _hitTestSelf() code.
|
||||||
hit = isOnEllipseStroke(point, radius, strokePadding);
|
hit = isOnEllipseStroke(point, radius, strokePadding);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return hit ? new HitResult('stroke', this)
|
return hit ? new HitResult(hitStroke ? 'stroke' : 'fill', this)
|
||||||
: _hitTestSelf.base.apply(this, arguments);
|
: _hitTestSelf.base.apply(this, arguments);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -1577,7 +1577,7 @@ var Path = PathItem.extend(/** @lends Path# */{
|
||||||
miterLimit = strokeRadius * style.getMiterLimit();
|
miterLimit = strokeRadius * style.getMiterLimit();
|
||||||
// Add the stroke radius to tolerance padding, taking
|
// Add the stroke radius to tolerance padding, taking
|
||||||
// #strokeScaling into account through _getStrokeMatrix().
|
// #strokeScaling into account through _getStrokeMatrix().
|
||||||
strokePadding = tolerancePadding.add(
|
strokePadding = strokePadding.add(
|
||||||
Path._getStrokePadding(strokeRadius,
|
Path._getStrokePadding(strokeRadius,
|
||||||
!style.getStrokeScaling() && strokeMatrix));
|
!style.getStrokeScaling() && strokeMatrix));
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue