Minor clean-ups and optimizations of stroke hit-test code.

This commit is contained in:
Jürg Lehni 2013-06-15 05:21:17 -07:00
parent 8c09d19f7c
commit 79785afa2a

View file

@ -1734,8 +1734,8 @@ var Path = PathItem.extend(/** @lends Path# */{
// If we're asked to query for segments, ends or handles, do all that // If we're asked to query for segments, ends or handles, do all that
// before stroke or fill. // before stroke or fill.
if (options.ends && !options.segments && !closed) { if (options.ends && !options.segments && !closed) {
if (res = checkSegmentPoints(this.getFirstSegment(), true) if (res = checkSegmentPoints(segments[0], true)
|| checkSegmentPoints(this.getLastSegment(), true)) || checkSegmentPoints(segments[segments.length - 1], true))
return res; return res;
} else if (options.segments || options.handles) { } else if (options.segments || options.handles) {
for (var i = 0, l = segments.length; i < l; i++) { for (var i = 0, l = segments.length; i < l; i++) {
@ -1750,8 +1750,8 @@ var Path = PathItem.extend(/** @lends Path# */{
// Now see if we're on a segment, and if so, check for its // Now see if we're on a segment, and if so, check for its
// stroke join / cap first. If not, do a normal radius check // stroke join / cap first. If not, do a normal radius check
// for round strokes. // for round strokes.
var param = loc.getParameter(); var parameter = loc.getParameter();
if (param === 0 || param === 1) { if (parameter === 0 || parameter === 1) {
if (!checkSegmentStroke(loc.getSegment())) if (!checkSegmentStroke(loc.getSegment()))
loc = null; loc = null;
} else if (loc._distance > radius) { } else if (loc._distance > radius) {
@ -1764,8 +1764,10 @@ var Path = PathItem.extend(/** @lends Path# */{
for (var i = 0, l = segments.length; i < l; i++) { for (var i = 0, l = segments.length; i < l; i++) {
var segment = segments[i]; var segment = segments[i];
if (point.getDistance(segment._point) <= miterLimit if (point.getDistance(segment._point) <= miterLimit
&& checkSegmentStroke(segment)) && checkSegmentStroke(segment)) {
loc = segment.getLocation(); loc = segment.getLocation();
break;
}
} }
} }
} }
@ -2586,10 +2588,12 @@ statics: {
// possible. // possible.
var strokeWidth = style.getStrokeColor() ? style.getStrokeWidth() : 0, var strokeWidth = style.getStrokeColor() ? style.getStrokeWidth() : 0,
joinWidth = strokeWidth; joinWidth = strokeWidth;
if (style.getStrokeJoin() === 'miter') if (strokeWidth > 0) {
joinWidth = strokeWidth * style.getMiterLimit(); if (style.getStrokeJoin() === 'miter')
if (style.getStrokeCap() === 'square') joinWidth = strokeWidth * style.getMiterLimit();
joinWidth = Math.max(joinWidth, strokeWidth * Math.sqrt(2)); if (style.getStrokeCap() === 'square')
joinWidth = Math.max(joinWidth, strokeWidth * Math.sqrt(2));
}
return Path.getHandleBounds(segments, closed, style, matrix, return Path.getHandleBounds(segments, closed, style, matrix,
strokeWidth, joinWidth); strokeWidth, joinWidth);
} }