From 3b0b1184a36f00cbcf856927116646d22664541d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Sun, 25 Dec 2011 12:34:51 +0100 Subject: [PATCH] Implement checkSegment() without relying on #_transformCoordinates(). --- src/path/Path.js | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/src/path/Path.js b/src/path/Path.js index 43275936..667dadf2 100644 --- a/src/path/Path.js +++ b/src/path/Path.js @@ -1263,20 +1263,19 @@ var Path = this.Path = PathItem.extend(/** @lends Path# */{ // before stroke or fill. var coords = [], that = this; - function checkSegment(segment, ends) { - // TODO: Convert to not using _transformCoordinates to get - // untransformed bounds - segment._transformCoordinates(null, coords); - for (var j = ends || options.segments ? 0 : 2, - m = !ends && options.handles ? 6 : 2; j < m; j += 2) { - if (point.getDistance(coords[j], coords[j + 1]) < tolerance) { - return new HitResult(j == 0 ? 'segment' - : 'handle-' + (j == 2 ? 'in' : 'out'), that, { - segment: segment, - point: Point.create(coords[j], coords[j + 1]) - }); - } - } + function checkPoint(seg, pt, name) { + if (point.getDistance(pt) < tolerance) + return new HitResult(name, that, { segment: seg, point: pt }); + } + function checkSegment(seg, ends) { + var point = seg._point; + // Note, when checking for ends, we don't also check for handles, + // since this will happen afterwards in a separate loop, see below. + return (ends || options.segments) + && checkPoint(seg, point, 'point') + || (!ends && options.handles) && ( + checkPoint(seg, point.add(seg._handleIn), 'handle-in') || + checkPoint(seg, point.add(seg._handleOut), 'handle-out')); } if (options.ends && !options.segments && !this._closed) { if (res = checkSegment(this.getFirstSegment(), true)