Skip to content

Commit

Permalink
Fix #977: Apply hit-testing tolerance to fills in Shape.
Browse files Browse the repository at this point in the history
  • Loading branch information
lehni committed Feb 15, 2016
1 parent 6975690 commit 4081afb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
14 changes: 9 additions & 5 deletions src/item/Shape.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,13 +344,17 @@ new function() { // Scope for _contains() and _hitTestSelf() code.
_hitTestSelf: function _hitTestSelf(point, options, viewMatrix,
strokeMatrix) {
var hit = false,
style = this._style;
if (options.stroke && style.hasStroke()) {
style = this._style,
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,
radius = this._radius,
strokeWidth = style.getStrokeWidth(),
strokeRadius = hitStroke ? style.getStrokeWidth() / 2 : 0;
strokePadding = options._tolerancePadding.add(
Path._getStrokePadding(strokeWidth / 2,
Path._getStrokePadding(strokeRadius,
!style.getStrokeScaling() && strokeMatrix));
if (type === 'rectangle') {
var padding = strokePadding.multiply(2),
Expand All @@ -370,7 +374,7 @@ new function() { // Scope for _contains() and _hitTestSelf() code.
hit = isOnEllipseStroke(point, radius, strokePadding);
}
}
return hit ? new HitResult('stroke', this)
return hit ? new HitResult(hitStroke ? 'stroke' : 'fill', this)
: _hitTestSelf.base.apply(this, arguments);
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/path/Path.js
Original file line number Diff line number Diff line change
Expand Up @@ -1577,7 +1577,7 @@ var Path = PathItem.extend(/** @lends Path# */{
miterLimit = strokeRadius * style.getMiterLimit();
// Add the stroke radius to tolerance padding, taking
// #strokeScaling into account through _getStrokeMatrix().
strokePadding = tolerancePadding.add(
strokePadding = strokePadding.add(
Path._getStrokePadding(strokeRadius,
!style.getStrokeScaling() && strokeMatrix));
} else {
Expand Down

0 comments on commit 4081afb

Please sign in to comment.