Rename PathFlattener to PathIterator and include the class in exports.

This commit is contained in:
Jürg Lehni 2014-09-10 02:20:00 +02:00
parent 1db4fb4064
commit 50c5c6736c
3 changed files with 16 additions and 14 deletions

View file

@ -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');

View file

@ -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++);
}

View file

@ -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;
},