mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-06 04:42:15 -05:00
Rename PathFlattener to PathIterator and include the class in exports.
This commit is contained in:
parent
1db4fb4064
commit
50c5c6736c
3 changed files with 16 additions and 14 deletions
|
@ -88,7 +88,7 @@ var paper = new function(undefined) {
|
||||||
/*#*/ if (__options.booleanOperations) {
|
/*#*/ if (__options.booleanOperations) {
|
||||||
/*#*/ include('path/PathItem.Boolean.js');
|
/*#*/ include('path/PathItem.Boolean.js');
|
||||||
/*#*/ }
|
/*#*/ }
|
||||||
/*#*/ include('path/PathFlattener.js');
|
/*#*/ include('path/PathIterator.js');
|
||||||
/*#*/ include('path/PathFitter.js');
|
/*#*/ include('path/PathFitter.js');
|
||||||
|
|
||||||
/*#*/ include('text/TextItem.js');
|
/*#*/ include('text/TextItem.js');
|
||||||
|
|
|
@ -952,18 +952,18 @@ var Path = PathItem.extend(/** @lends Path# */{
|
||||||
* copy.flatten(20);
|
* copy.flatten(20);
|
||||||
*/
|
*/
|
||||||
flatten: function(maxDistance) {
|
flatten: function(maxDistance) {
|
||||||
var flattener = new PathFlattener(this),
|
var iterator = new PathIterator(this),
|
||||||
pos = 0,
|
pos = 0,
|
||||||
// Adapt step = maxDistance so the points distribute evenly.
|
// 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.
|
// 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
|
// For closed paths, remove it, because we don't want to add last
|
||||||
// segment again
|
// 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
|
// Iterate over path and evaluate and add points at given offsets
|
||||||
var segments = [];
|
var segments = [];
|
||||||
while (pos <= end) {
|
while (pos <= end) {
|
||||||
segments.push(new Segment(flattener.evaluate(pos, 0)));
|
segments.push(new Segment(iterator.evaluate(pos, 0)));
|
||||||
pos += step;
|
pos += step;
|
||||||
}
|
}
|
||||||
this.setSegments(segments);
|
this.setSegments(segments);
|
||||||
|
@ -2113,14 +2113,14 @@ var Path = PathItem.extend(/** @lends Path# */{
|
||||||
if (hasStroke) {
|
if (hasStroke) {
|
||||||
if (dashLength) {
|
if (dashLength) {
|
||||||
// We cannot use the path created by drawSegments above
|
// 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
|
// NOTE: We don't cache this path in another currentPath
|
||||||
// since browsers that support currentPath also support
|
// since browsers that support currentPath also support
|
||||||
// native dashes.
|
// native dashes.
|
||||||
if (!dontStart)
|
if (!dontStart)
|
||||||
ctx.beginPath();
|
ctx.beginPath();
|
||||||
var flattener = new PathFlattener(this, strokeMatrix),
|
var iterator = new PathIterator(this, strokeMatrix),
|
||||||
length = flattener.length,
|
length = iterator.length,
|
||||||
from = -style.getDashOffset(), to,
|
from = -style.getDashOffset(), to,
|
||||||
i = 0;
|
i = 0;
|
||||||
from = from % length;
|
from = from % length;
|
||||||
|
@ -2132,7 +2132,7 @@ var Path = PathItem.extend(/** @lends Path# */{
|
||||||
while (from < length) {
|
while (from < length) {
|
||||||
to = from + getOffset(i++);
|
to = from + getOffset(i++);
|
||||||
if (from > 0 || to > 0)
|
if (from > 0 || to > 0)
|
||||||
flattener.drawPart(ctx,
|
iterator.drawPart(ctx,
|
||||||
Math.max(from, 0), Math.max(to, 0));
|
Math.max(from, 0), Math.max(to, 0));
|
||||||
from = to + getOffset(i++);
|
from = to + getOffset(i++);
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,13 +11,15 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @name PathFlattener
|
* @name PathIterator
|
||||||
* @class
|
* @class
|
||||||
* @private
|
* @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 {Path} path the path to iterate over.
|
||||||
* @param {Matrix} [matrix] the matrix by which to transform the path's
|
* @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
|
* @param {Number} [tolerance=0.25] the error tolerance at which the
|
||||||
* recursion is interrupted before the maximum number of iterations is
|
* recursion is interrupted before the maximum number of iterations is
|
||||||
* reached.
|
* reached.
|
||||||
* @return {PathFlattener} the newly created path flattener.
|
* @return {PathIterator} the newly created path iterator.
|
||||||
*/
|
*/
|
||||||
initialize: function(path, matrix, maxRecursion, tolerance) {
|
initialize: function(path, matrix, maxRecursion, tolerance) {
|
||||||
if (!tolerance)
|
if (!tolerance)
|
||||||
|
@ -90,7 +92,7 @@ var PathFlattener = Base.extend({
|
||||||
this.parts = parts;
|
this.parts = parts;
|
||||||
this.length = length;
|
this.length = length;
|
||||||
// Keep a current index from the part where we last where in
|
// 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;
|
this.index = 0;
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue