Implement checkSegment() without relying on #_transformCoordinates().

This commit is contained in:
Jürg Lehni 2011-12-25 12:34:51 +01:00
parent 0ccd3bc848
commit 3b0b1184a3

View file

@ -1263,20 +1263,19 @@ var Path = this.Path = PathItem.extend(/** @lends Path# */{
// before stroke or fill. // before stroke or fill.
var coords = [], var coords = [],
that = this; that = this;
function checkSegment(segment, ends) { function checkPoint(seg, pt, name) {
// TODO: Convert to not using _transformCoordinates to get if (point.getDistance(pt) < tolerance)
// untransformed bounds return new HitResult(name, that, { segment: seg, point: pt });
segment._transformCoordinates(null, coords); }
for (var j = ends || options.segments ? 0 : 2, function checkSegment(seg, ends) {
m = !ends && options.handles ? 6 : 2; j < m; j += 2) { var point = seg._point;
if (point.getDistance(coords[j], coords[j + 1]) < tolerance) { // Note, when checking for ends, we don't also check for handles,
return new HitResult(j == 0 ? 'segment' // since this will happen afterwards in a separate loop, see below.
: 'handle-' + (j == 2 ? 'in' : 'out'), that, { return (ends || options.segments)
segment: segment, && checkPoint(seg, point, 'point')
point: Point.create(coords[j], coords[j + 1]) || (!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 (options.ends && !options.segments && !this._closed) {
if (res = checkSegment(this.getFirstSegment(), true) if (res = checkSegment(this.getFirstSegment(), true)