From 50c5c6736c8e1903bf50a074236f963a9c4875a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Wed, 10 Sep 2014 02:20:00 +0200 Subject: [PATCH] Rename PathFlattener to PathIterator and include the class in exports. --- src/paper.js | 2 +- src/path/Path.js | 16 ++++++++-------- src/path/{PathFlattener.js => PathIterator.js} | 12 +++++++----- 3 files changed, 16 insertions(+), 14 deletions(-) rename src/path/{PathFlattener.js => PathIterator.js} (96%) diff --git a/src/paper.js b/src/paper.js index 6e14ddbd..3095b83c 100644 --- a/src/paper.js +++ b/src/paper.js @@ -88,7 +88,7 @@ var paper = new function(undefined) { /*#*/ if (__options.booleanOperations) { /*#*/ include('path/PathItem.Boolean.js'); /*#*/ } -/*#*/ include('path/PathFlattener.js'); +/*#*/ include('path/PathIterator.js'); /*#*/ include('path/PathFitter.js'); /*#*/ include('text/TextItem.js'); diff --git a/src/path/Path.js b/src/path/Path.js index 3485d381..c59813d3 100644 --- a/src/path/Path.js +++ b/src/path/Path.js @@ -952,18 +952,18 @@ var Path = PathItem.extend(/** @lends Path# */{ * copy.flatten(20); */ flatten: function(maxDistance) { - var flattener = new PathFlattener(this), + var iterator = new PathIterator(this), pos = 0, // Adapt step = maxDistance so the points distribute evenly. - step = flattener.length / Math.ceil(flattener.length / maxDistance), + step = iterator.length / Math.ceil(iterator.length / maxDistance), // Add/remove half of step to end, so imprecisions are ok too. // For closed paths, remove it, because we don't want to add last // segment again - end = flattener.length + (this._closed ? -step : step) / 2; + end = iterator.length + (this._closed ? -step : step) / 2; // Iterate over path and evaluate and add points at given offsets var segments = []; while (pos <= end) { - segments.push(new Segment(flattener.evaluate(pos, 0))); + segments.push(new Segment(iterator.evaluate(pos, 0))); pos += step; } this.setSegments(segments); @@ -2113,14 +2113,14 @@ var Path = PathItem.extend(/** @lends Path# */{ if (hasStroke) { if (dashLength) { // We cannot use the path created by drawSegments above - // Use CurveFlatteners to draw dashed paths: + // Use PathIterator to draw dashed paths: // NOTE: We don't cache this path in another currentPath // since browsers that support currentPath also support // native dashes. if (!dontStart) ctx.beginPath(); - var flattener = new PathFlattener(this, strokeMatrix), - length = flattener.length, + var iterator = new PathIterator(this, strokeMatrix), + length = iterator.length, from = -style.getDashOffset(), to, i = 0; from = from % length; @@ -2132,7 +2132,7 @@ var Path = PathItem.extend(/** @lends Path# */{ while (from < length) { to = from + getOffset(i++); if (from > 0 || to > 0) - flattener.drawPart(ctx, + iterator.drawPart(ctx, Math.max(from, 0), Math.max(to, 0)); from = to + getOffset(i++); } diff --git a/src/path/PathFlattener.js b/src/path/PathIterator.js similarity index 96% rename from src/path/PathFlattener.js rename to src/path/PathIterator.js index 9699cbea..da9fd811 100644 --- a/src/path/PathFlattener.js +++ b/src/path/PathIterator.js @@ -11,13 +11,15 @@ */ /** - * @name PathFlattener + * @name PathIterator * @class * @private */ -var PathFlattener = Base.extend({ +var PathIterator = Base.extend({ + _class: 'PathIterator', + /** - * Creates a path flattener for the given path. + * Creates a path iterator for the given path. * * @param {Path} path the path to iterate over. * @param {Matrix} [matrix] the matrix by which to transform the path's @@ -27,7 +29,7 @@ var PathFlattener = Base.extend({ * @param {Number} [tolerance=0.25] the error tolerance at which the * recursion is interrupted before the maximum number of iterations is * reached. - * @return {PathFlattener} the newly created path flattener. + * @return {PathIterator} the newly created path iterator. */ initialize: function(path, matrix, maxRecursion, tolerance) { if (!tolerance) @@ -90,7 +92,7 @@ var PathFlattener = Base.extend({ this.parts = parts; this.length = length; // Keep a current index from the part where we last where in - // getParameterAt(), to optimise for iterator-like usage of flattener. + // getParameterAt(), to optimise for iterator-like usage of iterator. this.index = 0; },