mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-08 05:42:07 -05:00
Prebuilt module for commit 9e8fcee8cd
This commit is contained in:
parent
c8aa01291d
commit
ffac907296
8 changed files with 203 additions and 209 deletions
116
dist/docs/assets/js/paper.js
vendored
116
dist/docs/assets/js/paper.js
vendored
|
@ -9,7 +9,7 @@
|
||||||
*
|
*
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Date: Wed Feb 10 13:26:40 2016 +0100
|
* Date: Wed Feb 10 14:58:40 2016 +0100
|
||||||
*
|
*
|
||||||
***
|
***
|
||||||
*
|
*
|
||||||
|
@ -6062,7 +6062,7 @@ statics: {
|
||||||
: v;
|
: v;
|
||||||
},
|
},
|
||||||
|
|
||||||
isFlatEnough: function(v, tolerance) {
|
isFlatEnough: function(v, flatness) {
|
||||||
var p1x = v[0], p1y = v[1],
|
var p1x = v[0], p1y = v[1],
|
||||||
c1x = v[2], c1y = v[3],
|
c1x = v[2], c1y = v[3],
|
||||||
c2x = v[4], c2y = v[5],
|
c2x = v[4], c2y = v[5],
|
||||||
|
@ -6072,7 +6072,7 @@ statics: {
|
||||||
vx = 3 * c2x - 2 * p2x - p1x,
|
vx = 3 * c2x - 2 * p2x - p1x,
|
||||||
vy = 3 * c2y - 2 * p2y - p1y;
|
vy = 3 * c2y - 2 * p2y - p1y;
|
||||||
return Math.max(ux * ux, vx * vx) + Math.max(uy * uy, vy * vy)
|
return Math.max(ux * ux, vx * vx) + Math.max(uy * uy, vy * vy)
|
||||||
< 10 * tolerance * tolerance;
|
<= 16 * flatness * flatness;
|
||||||
},
|
},
|
||||||
|
|
||||||
getArea: function(v) {
|
getArea: function(v) {
|
||||||
|
@ -7875,6 +7875,19 @@ var Path = PathItem.extend({
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
reduce: function(options) {
|
||||||
|
var curves = this.getCurves(),
|
||||||
|
simplify = options && options.simplify,
|
||||||
|
tolerance = simplify ? 2e-7 : 0;
|
||||||
|
for (var i = curves.length - 1; i >= 0; i--) {
|
||||||
|
var curve = curves[i];
|
||||||
|
if (!curve.hasHandles() && (curve.getLength() < tolerance
|
||||||
|
|| simplify && curve.isCollinear(curve.getNext())))
|
||||||
|
curve.remove();
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
},
|
||||||
|
|
||||||
reverse: function() {
|
reverse: function() {
|
||||||
this._segments.reverse();
|
this._segments.reverse();
|
||||||
for (var i = 0, l = this._segments.length; i < l; i++) {
|
for (var i = 0, l = this._segments.length; i < l; i++) {
|
||||||
|
@ -7890,32 +7903,16 @@ var Path = PathItem.extend({
|
||||||
this._changed(9);
|
this._changed(9);
|
||||||
},
|
},
|
||||||
|
|
||||||
flatten: function(maxDistance) {
|
flatten: function(flatness) {
|
||||||
var iterator = new PathIterator(this, 64, 0.1),
|
var iterator = new PathIterator(this, flatness || 0.25, 256, true),
|
||||||
pos = 0,
|
parts = iterator.parts,
|
||||||
step = iterator.length / Math.ceil(iterator.length / maxDistance),
|
segments = [];
|
||||||
end = iterator.length + (this._closed ? -step : step) / 2;
|
for (var i = 0, l = parts.length; i < l; i++) {
|
||||||
var segments = [];
|
segments.push(new Segment(parts[i].curve.slice(0, 2)));
|
||||||
while (pos <= end) {
|
|
||||||
segments.push(new Segment(iterator.getPointAt(pos)));
|
|
||||||
pos += step;
|
|
||||||
}
|
}
|
||||||
this.setSegments(segments);
|
this.setSegments(segments);
|
||||||
},
|
},
|
||||||
|
|
||||||
reduce: function(options) {
|
|
||||||
var curves = this.getCurves(),
|
|
||||||
simplify = options && options.simplify,
|
|
||||||
tolerance = simplify ? 2e-7 : 0;
|
|
||||||
for (var i = curves.length - 1; i >= 0; i--) {
|
|
||||||
var curve = curves[i];
|
|
||||||
if (!curve.hasHandles() && (curve.getLength() < tolerance
|
|
||||||
|| simplify && curve.isCollinear(curve.getNext())))
|
|
||||||
curve.remove();
|
|
||||||
}
|
|
||||||
return this;
|
|
||||||
},
|
|
||||||
|
|
||||||
simplify: function(tolerance) {
|
simplify: function(tolerance) {
|
||||||
var segments = new PathFitter(this).fit(tolerance || 2.5);
|
var segments = new PathFitter(this).fit(tolerance || 2.5);
|
||||||
if (segments)
|
if (segments)
|
||||||
|
@ -8425,7 +8422,7 @@ new function() {
|
||||||
if (dashLength) {
|
if (dashLength) {
|
||||||
if (!dontStart)
|
if (!dontStart)
|
||||||
ctx.beginPath();
|
ctx.beginPath();
|
||||||
var iterator = new PathIterator(this, 32, 0.25,
|
var iterator = new PathIterator(this, 0.25, 32, false,
|
||||||
strokeMatrix),
|
strokeMatrix),
|
||||||
length = iterator.length,
|
length = iterator.length,
|
||||||
from = -style.getDashOffset(), to,
|
from = -style.getDashOffset(), to,
|
||||||
|
@ -9880,11 +9877,11 @@ CompoundPath.inject({
|
||||||
var PathIterator = Base.extend({
|
var PathIterator = Base.extend({
|
||||||
_class: 'PathIterator',
|
_class: 'PathIterator',
|
||||||
|
|
||||||
initialize: function(path, maxRecursion, tolerance, matrix) {
|
initialize: function(path, flatness, maxRecursion, ignoreStraight, matrix) {
|
||||||
var curves = [],
|
var curves = [],
|
||||||
parts = [],
|
parts = [],
|
||||||
length = 0,
|
length = 0,
|
||||||
minDifference = 1 / (maxRecursion || 32),
|
minSpan = 1 / (maxRecursion || 32),
|
||||||
segments = path._segments,
|
segments = path._segments,
|
||||||
segment1 = segments[0],
|
segment1 = segments[0],
|
||||||
segment2;
|
segment2;
|
||||||
|
@ -9895,23 +9892,25 @@ var PathIterator = Base.extend({
|
||||||
computeParts(curve, segment1._index, 0, 1);
|
computeParts(curve, segment1._index, 0, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
function computeParts(curve, index, minT, maxT) {
|
function computeParts(curve, index, t1, t2) {
|
||||||
if ((maxT - minT) > minDifference
|
if ((t2 - t1) > minSpan
|
||||||
&& !Curve.isFlatEnough(curve, tolerance || 0.25)) {
|
&& !(ignoreStraight && Curve.isStraight(curve))
|
||||||
var split = Curve.subdivide(curve, 0.5),
|
&& !Curve.isFlatEnough(curve, flatness || 0.25)) {
|
||||||
halfT = (minT + maxT) / 2;
|
var halves = Curve.subdivide(curve, 0.5),
|
||||||
computeParts(split[0], index, minT, halfT);
|
tMid = (t1 + t2) / 2;
|
||||||
computeParts(split[1], index, halfT, maxT);
|
computeParts(halves[0], index, t1, tMid);
|
||||||
|
computeParts(halves[1], index, tMid, t2);
|
||||||
} else {
|
} else {
|
||||||
var x = curve[6] - curve[0],
|
var dx = curve[6] - curve[0],
|
||||||
y = curve[7] - curve[1],
|
dy = curve[7] - curve[1],
|
||||||
dist = Math.sqrt(x * x + y * y);
|
dist = Math.sqrt(dx * dx + dy * dy);
|
||||||
if (dist > 1e-6) {
|
if (dist > 0) {
|
||||||
length += dist;
|
length += dist;
|
||||||
parts.push({
|
parts.push({
|
||||||
offset: length,
|
offset: length,
|
||||||
value: maxT,
|
curve: curve,
|
||||||
index: index
|
index: index,
|
||||||
|
time: t2,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9924,14 +9923,13 @@ var PathIterator = Base.extend({
|
||||||
}
|
}
|
||||||
if (path._closed)
|
if (path._closed)
|
||||||
addCurve(segment2, segments[0]);
|
addCurve(segment2, segments[0]);
|
||||||
|
|
||||||
this.curves = curves;
|
this.curves = curves;
|
||||||
this.parts = parts;
|
this.parts = parts;
|
||||||
this.length = length;
|
this.length = length;
|
||||||
this.index = 0;
|
this.index = 0;
|
||||||
},
|
},
|
||||||
|
|
||||||
getTimeAt: function(offset) {
|
_get: function(offset) {
|
||||||
var i, j = this.index;
|
var i, j = this.index;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
i = j;
|
i = j;
|
||||||
|
@ -9943,39 +9941,39 @@ var PathIterator = Base.extend({
|
||||||
if (part.offset >= offset) {
|
if (part.offset >= offset) {
|
||||||
this.index = i;
|
this.index = i;
|
||||||
var prev = this.parts[i - 1];
|
var prev = this.parts[i - 1];
|
||||||
var prevVal = prev && prev.index == part.index ? prev.value : 0,
|
var prevTime = prev && prev.index === part.index ? prev.time : 0,
|
||||||
prevLen = prev ? prev.offset : 0;
|
prevOffset = prev ? prev.offset : 0;
|
||||||
return {
|
return {
|
||||||
value: prevVal + (part.value - prevVal)
|
index: part.index,
|
||||||
* (offset - prevLen) / (part.offset - prevLen),
|
time: prevTime + (part.time - prevTime)
|
||||||
index: part.index
|
* (offset - prevOffset) / (part.offset - prevOffset)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var part = this.parts[this.parts.length - 1];
|
var part = this.parts[this.parts.length - 1];
|
||||||
return {
|
return {
|
||||||
value: 1,
|
index: part.index,
|
||||||
index: part.index
|
time: 1
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
drawPart: function(ctx, from, to) {
|
drawPart: function(ctx, from, to) {
|
||||||
from = this.getTimeAt(from);
|
var start = this._get(from),
|
||||||
to = this.getTimeAt(to);
|
end = this._get(to);
|
||||||
for (var i = from.index; i <= to.index; i++) {
|
for (var i = start.index, l = end.index; i <= l; i++) {
|
||||||
var curve = Curve.getPart(this.curves[i],
|
var curve = Curve.getPart(this.curves[i],
|
||||||
i == from.index ? from.value : 0,
|
i === start.index ? start.time : 0,
|
||||||
i == to.index ? to.value : 1);
|
i === end.index ? end.time : 1);
|
||||||
if (i == from.index)
|
if (i === start.index)
|
||||||
ctx.moveTo(curve[0], curve[1]);
|
ctx.moveTo(curve[0], curve[1]);
|
||||||
ctx.bezierCurveTo.apply(ctx, curve.slice(2));
|
ctx.bezierCurveTo.apply(ctx, curve.slice(2));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, Base.each(Curve._evaluateMethods,
|
}, Base.each(Curve._evaluateMethods,
|
||||||
function(name) {
|
function(name) {
|
||||||
this[name + 'At'] = function(offset, weighted) {
|
this[name + 'At'] = function(offset) {
|
||||||
var param = this.getTimeAt(offset);
|
var param = this._get(offset);
|
||||||
return Curve[name](this.curves[param.index], param.value, weighted);
|
return Curve[name](this.curves[param.index], param.time);
|
||||||
};
|
};
|
||||||
}, {})
|
}, {})
|
||||||
);
|
);
|
||||||
|
|
14
dist/docs/classes/CompoundPath.html
vendored
14
dist/docs/classes/CompoundPath.html
vendored
|
@ -6730,22 +6730,22 @@ function onMouseMove(event) {
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<div id="flatten-maxDistance" class="member">
|
<div id="flatten-flatness" class="member">
|
||||||
<div class="member-link">
|
<div class="member-link">
|
||||||
<a name="flatten-maxDistance" href="#flatten-maxDistance"><tt><b>flatten</b>(maxDistance)</tt></a>
|
<a name="flatten-flatness" href="#flatten-flatness"><tt><b>flatten</b>(flatness)</tt></a>
|
||||||
</div>
|
</div>
|
||||||
<div class="member-description hidden">
|
<div class="member-description hidden">
|
||||||
<div class="member-text">
|
<div class="member-text">
|
||||||
<p>Converts the curves in a path to straight lines with an even distribution of points. The distance between the produced segments is as close as possible to the value specified by the <code>maxDistance</code> parameter.</p>
|
<p>Flattens the curves in path items to a sequence of straight lines, by subdividing them enough times until the specified maximum error is met.</p>
|
||||||
|
|
||||||
|
|
||||||
<ul class="member-list">
|
<ul class="member-list">
|
||||||
<h4>Parameters:</h4>
|
<h4>Parameters:</h4>
|
||||||
|
|
||||||
<li>
|
<li>
|
||||||
<tt>maxDistance:</tt>
|
<tt>flatness:</tt>
|
||||||
<tt>Number</tt>
|
<tt>Number</tt>
|
||||||
— the maximum distance between the points
|
— the maximum error between the flattened lines and the original curves
|
||||||
|
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
|
@ -6776,8 +6776,8 @@ path.selected = true;
|
||||||
var copy = path.clone();
|
var copy = path.clone();
|
||||||
copy.position.x += 150;
|
copy.position.x += 150;
|
||||||
|
|
||||||
// Convert its curves to points, with a max distance of 20:
|
// Convert its curves to points, with a maximum error of 10:
|
||||||
copy.flatten(20);
|
copy.flatten(10);
|
||||||
</script>
|
</script>
|
||||||
<div class="canvas"><canvas width="516" height="100" id="canvas-57"></canvas></div>
|
<div class="canvas"><canvas width="516" height="100" id="canvas-57"></canvas></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
14
dist/docs/classes/Path.html
vendored
14
dist/docs/classes/Path.html
vendored
|
@ -9551,22 +9551,22 @@ function onMouseMove(event) {
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<div id="flatten-maxDistance" class="member">
|
<div id="flatten-flatness" class="member">
|
||||||
<div class="member-link">
|
<div class="member-link">
|
||||||
<a name="flatten-maxDistance" href="#flatten-maxDistance"><tt><b>flatten</b>(maxDistance)</tt></a>
|
<a name="flatten-flatness" href="#flatten-flatness"><tt><b>flatten</b>(flatness)</tt></a>
|
||||||
</div>
|
</div>
|
||||||
<div class="member-description hidden">
|
<div class="member-description hidden">
|
||||||
<div class="member-text">
|
<div class="member-text">
|
||||||
<p>Converts the curves in a path to straight lines with an even distribution of points. The distance between the produced segments is as close as possible to the value specified by the <code>maxDistance</code> parameter.</p>
|
<p>Flattens the curves in path items to a sequence of straight lines, by subdividing them enough times until the specified maximum error is met.</p>
|
||||||
|
|
||||||
|
|
||||||
<ul class="member-list">
|
<ul class="member-list">
|
||||||
<h4>Parameters:</h4>
|
<h4>Parameters:</h4>
|
||||||
|
|
||||||
<li>
|
<li>
|
||||||
<tt>maxDistance:</tt>
|
<tt>flatness:</tt>
|
||||||
<tt>Number</tt>
|
<tt>Number</tt>
|
||||||
— the maximum distance between the points
|
— the maximum error between the flattened lines and the original curves
|
||||||
|
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
|
@ -9597,8 +9597,8 @@ path.selected = true;
|
||||||
var copy = path.clone();
|
var copy = path.clone();
|
||||||
copy.position.x += 150;
|
copy.position.x += 150;
|
||||||
|
|
||||||
// Convert its curves to points, with a max distance of 20:
|
// Convert its curves to points, with a maximum error of 10:
|
||||||
copy.flatten(20);
|
copy.flatten(10);
|
||||||
</script>
|
</script>
|
||||||
<div class="canvas"><canvas width="516" height="100" id="canvas-104"></canvas></div>
|
<div class="canvas"><canvas width="516" height="100" id="canvas-104"></canvas></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
14
dist/docs/classes/PathItem.html
vendored
14
dist/docs/classes/PathItem.html
vendored
|
@ -512,22 +512,22 @@ function onMouseMove(event) {
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<div id="flatten-maxDistance" class="member">
|
<div id="flatten-flatness" class="member">
|
||||||
<div class="member-link">
|
<div class="member-link">
|
||||||
<a name="flatten-maxDistance" href="#flatten-maxDistance"><tt><b>flatten</b>(maxDistance)</tt></a>
|
<a name="flatten-flatness" href="#flatten-flatness"><tt><b>flatten</b>(flatness)</tt></a>
|
||||||
</div>
|
</div>
|
||||||
<div class="member-description hidden">
|
<div class="member-description hidden">
|
||||||
<div class="member-text">
|
<div class="member-text">
|
||||||
<p>Converts the curves in a path to straight lines with an even distribution of points. The distance between the produced segments is as close as possible to the value specified by the <code>maxDistance</code> parameter.</p>
|
<p>Flattens the curves in path items to a sequence of straight lines, by subdividing them enough times until the specified maximum error is met.</p>
|
||||||
|
|
||||||
|
|
||||||
<ul class="member-list">
|
<ul class="member-list">
|
||||||
<h4>Parameters:</h4>
|
<h4>Parameters:</h4>
|
||||||
|
|
||||||
<li>
|
<li>
|
||||||
<tt>maxDistance:</tt>
|
<tt>flatness:</tt>
|
||||||
<tt>Number</tt>
|
<tt>Number</tt>
|
||||||
— the maximum distance between the points
|
— the maximum error between the flattened lines and the original curves
|
||||||
|
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
|
@ -558,8 +558,8 @@ path.selected = true;
|
||||||
var copy = path.clone();
|
var copy = path.clone();
|
||||||
copy.position.x += 150;
|
copy.position.x += 150;
|
||||||
|
|
||||||
// Convert its curves to points, with a max distance of 20:
|
// Convert its curves to points, with a maximum error of 10:
|
||||||
copy.flatten(20);
|
copy.flatten(10);
|
||||||
</script>
|
</script>
|
||||||
<div class="canvas"><canvas width="516" height="100" id="canvas-2"></canvas></div>
|
<div class="canvas"><canvas width="516" height="100" id="canvas-2"></canvas></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
116
dist/paper-core.js
vendored
116
dist/paper-core.js
vendored
|
@ -9,7 +9,7 @@
|
||||||
*
|
*
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Date: Wed Feb 10 13:26:40 2016 +0100
|
* Date: Wed Feb 10 14:58:40 2016 +0100
|
||||||
*
|
*
|
||||||
***
|
***
|
||||||
*
|
*
|
||||||
|
@ -6062,7 +6062,7 @@ statics: {
|
||||||
: v;
|
: v;
|
||||||
},
|
},
|
||||||
|
|
||||||
isFlatEnough: function(v, tolerance) {
|
isFlatEnough: function(v, flatness) {
|
||||||
var p1x = v[0], p1y = v[1],
|
var p1x = v[0], p1y = v[1],
|
||||||
c1x = v[2], c1y = v[3],
|
c1x = v[2], c1y = v[3],
|
||||||
c2x = v[4], c2y = v[5],
|
c2x = v[4], c2y = v[5],
|
||||||
|
@ -6072,7 +6072,7 @@ statics: {
|
||||||
vx = 3 * c2x - 2 * p2x - p1x,
|
vx = 3 * c2x - 2 * p2x - p1x,
|
||||||
vy = 3 * c2y - 2 * p2y - p1y;
|
vy = 3 * c2y - 2 * p2y - p1y;
|
||||||
return Math.max(ux * ux, vx * vx) + Math.max(uy * uy, vy * vy)
|
return Math.max(ux * ux, vx * vx) + Math.max(uy * uy, vy * vy)
|
||||||
< 10 * tolerance * tolerance;
|
<= 16 * flatness * flatness;
|
||||||
},
|
},
|
||||||
|
|
||||||
getArea: function(v) {
|
getArea: function(v) {
|
||||||
|
@ -7875,6 +7875,19 @@ var Path = PathItem.extend({
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
reduce: function(options) {
|
||||||
|
var curves = this.getCurves(),
|
||||||
|
simplify = options && options.simplify,
|
||||||
|
tolerance = simplify ? 2e-7 : 0;
|
||||||
|
for (var i = curves.length - 1; i >= 0; i--) {
|
||||||
|
var curve = curves[i];
|
||||||
|
if (!curve.hasHandles() && (curve.getLength() < tolerance
|
||||||
|
|| simplify && curve.isCollinear(curve.getNext())))
|
||||||
|
curve.remove();
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
},
|
||||||
|
|
||||||
reverse: function() {
|
reverse: function() {
|
||||||
this._segments.reverse();
|
this._segments.reverse();
|
||||||
for (var i = 0, l = this._segments.length; i < l; i++) {
|
for (var i = 0, l = this._segments.length; i < l; i++) {
|
||||||
|
@ -7890,32 +7903,16 @@ var Path = PathItem.extend({
|
||||||
this._changed(9);
|
this._changed(9);
|
||||||
},
|
},
|
||||||
|
|
||||||
flatten: function(maxDistance) {
|
flatten: function(flatness) {
|
||||||
var iterator = new PathIterator(this, 64, 0.1),
|
var iterator = new PathIterator(this, flatness || 0.25, 256, true),
|
||||||
pos = 0,
|
parts = iterator.parts,
|
||||||
step = iterator.length / Math.ceil(iterator.length / maxDistance),
|
segments = [];
|
||||||
end = iterator.length + (this._closed ? -step : step) / 2;
|
for (var i = 0, l = parts.length; i < l; i++) {
|
||||||
var segments = [];
|
segments.push(new Segment(parts[i].curve.slice(0, 2)));
|
||||||
while (pos <= end) {
|
|
||||||
segments.push(new Segment(iterator.getPointAt(pos)));
|
|
||||||
pos += step;
|
|
||||||
}
|
}
|
||||||
this.setSegments(segments);
|
this.setSegments(segments);
|
||||||
},
|
},
|
||||||
|
|
||||||
reduce: function(options) {
|
|
||||||
var curves = this.getCurves(),
|
|
||||||
simplify = options && options.simplify,
|
|
||||||
tolerance = simplify ? 2e-7 : 0;
|
|
||||||
for (var i = curves.length - 1; i >= 0; i--) {
|
|
||||||
var curve = curves[i];
|
|
||||||
if (!curve.hasHandles() && (curve.getLength() < tolerance
|
|
||||||
|| simplify && curve.isCollinear(curve.getNext())))
|
|
||||||
curve.remove();
|
|
||||||
}
|
|
||||||
return this;
|
|
||||||
},
|
|
||||||
|
|
||||||
simplify: function(tolerance) {
|
simplify: function(tolerance) {
|
||||||
var segments = new PathFitter(this).fit(tolerance || 2.5);
|
var segments = new PathFitter(this).fit(tolerance || 2.5);
|
||||||
if (segments)
|
if (segments)
|
||||||
|
@ -8425,7 +8422,7 @@ new function() {
|
||||||
if (dashLength) {
|
if (dashLength) {
|
||||||
if (!dontStart)
|
if (!dontStart)
|
||||||
ctx.beginPath();
|
ctx.beginPath();
|
||||||
var iterator = new PathIterator(this, 32, 0.25,
|
var iterator = new PathIterator(this, 0.25, 32, false,
|
||||||
strokeMatrix),
|
strokeMatrix),
|
||||||
length = iterator.length,
|
length = iterator.length,
|
||||||
from = -style.getDashOffset(), to,
|
from = -style.getDashOffset(), to,
|
||||||
|
@ -9880,11 +9877,11 @@ CompoundPath.inject({
|
||||||
var PathIterator = Base.extend({
|
var PathIterator = Base.extend({
|
||||||
_class: 'PathIterator',
|
_class: 'PathIterator',
|
||||||
|
|
||||||
initialize: function(path, maxRecursion, tolerance, matrix) {
|
initialize: function(path, flatness, maxRecursion, ignoreStraight, matrix) {
|
||||||
var curves = [],
|
var curves = [],
|
||||||
parts = [],
|
parts = [],
|
||||||
length = 0,
|
length = 0,
|
||||||
minDifference = 1 / (maxRecursion || 32),
|
minSpan = 1 / (maxRecursion || 32),
|
||||||
segments = path._segments,
|
segments = path._segments,
|
||||||
segment1 = segments[0],
|
segment1 = segments[0],
|
||||||
segment2;
|
segment2;
|
||||||
|
@ -9895,23 +9892,25 @@ var PathIterator = Base.extend({
|
||||||
computeParts(curve, segment1._index, 0, 1);
|
computeParts(curve, segment1._index, 0, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
function computeParts(curve, index, minT, maxT) {
|
function computeParts(curve, index, t1, t2) {
|
||||||
if ((maxT - minT) > minDifference
|
if ((t2 - t1) > minSpan
|
||||||
&& !Curve.isFlatEnough(curve, tolerance || 0.25)) {
|
&& !(ignoreStraight && Curve.isStraight(curve))
|
||||||
var split = Curve.subdivide(curve, 0.5),
|
&& !Curve.isFlatEnough(curve, flatness || 0.25)) {
|
||||||
halfT = (minT + maxT) / 2;
|
var halves = Curve.subdivide(curve, 0.5),
|
||||||
computeParts(split[0], index, minT, halfT);
|
tMid = (t1 + t2) / 2;
|
||||||
computeParts(split[1], index, halfT, maxT);
|
computeParts(halves[0], index, t1, tMid);
|
||||||
|
computeParts(halves[1], index, tMid, t2);
|
||||||
} else {
|
} else {
|
||||||
var x = curve[6] - curve[0],
|
var dx = curve[6] - curve[0],
|
||||||
y = curve[7] - curve[1],
|
dy = curve[7] - curve[1],
|
||||||
dist = Math.sqrt(x * x + y * y);
|
dist = Math.sqrt(dx * dx + dy * dy);
|
||||||
if (dist > 1e-6) {
|
if (dist > 0) {
|
||||||
length += dist;
|
length += dist;
|
||||||
parts.push({
|
parts.push({
|
||||||
offset: length,
|
offset: length,
|
||||||
value: maxT,
|
curve: curve,
|
||||||
index: index
|
index: index,
|
||||||
|
time: t2,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9924,14 +9923,13 @@ var PathIterator = Base.extend({
|
||||||
}
|
}
|
||||||
if (path._closed)
|
if (path._closed)
|
||||||
addCurve(segment2, segments[0]);
|
addCurve(segment2, segments[0]);
|
||||||
|
|
||||||
this.curves = curves;
|
this.curves = curves;
|
||||||
this.parts = parts;
|
this.parts = parts;
|
||||||
this.length = length;
|
this.length = length;
|
||||||
this.index = 0;
|
this.index = 0;
|
||||||
},
|
},
|
||||||
|
|
||||||
getTimeAt: function(offset) {
|
_get: function(offset) {
|
||||||
var i, j = this.index;
|
var i, j = this.index;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
i = j;
|
i = j;
|
||||||
|
@ -9943,39 +9941,39 @@ var PathIterator = Base.extend({
|
||||||
if (part.offset >= offset) {
|
if (part.offset >= offset) {
|
||||||
this.index = i;
|
this.index = i;
|
||||||
var prev = this.parts[i - 1];
|
var prev = this.parts[i - 1];
|
||||||
var prevVal = prev && prev.index == part.index ? prev.value : 0,
|
var prevTime = prev && prev.index === part.index ? prev.time : 0,
|
||||||
prevLen = prev ? prev.offset : 0;
|
prevOffset = prev ? prev.offset : 0;
|
||||||
return {
|
return {
|
||||||
value: prevVal + (part.value - prevVal)
|
index: part.index,
|
||||||
* (offset - prevLen) / (part.offset - prevLen),
|
time: prevTime + (part.time - prevTime)
|
||||||
index: part.index
|
* (offset - prevOffset) / (part.offset - prevOffset)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var part = this.parts[this.parts.length - 1];
|
var part = this.parts[this.parts.length - 1];
|
||||||
return {
|
return {
|
||||||
value: 1,
|
index: part.index,
|
||||||
index: part.index
|
time: 1
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
drawPart: function(ctx, from, to) {
|
drawPart: function(ctx, from, to) {
|
||||||
from = this.getTimeAt(from);
|
var start = this._get(from),
|
||||||
to = this.getTimeAt(to);
|
end = this._get(to);
|
||||||
for (var i = from.index; i <= to.index; i++) {
|
for (var i = start.index, l = end.index; i <= l; i++) {
|
||||||
var curve = Curve.getPart(this.curves[i],
|
var curve = Curve.getPart(this.curves[i],
|
||||||
i == from.index ? from.value : 0,
|
i === start.index ? start.time : 0,
|
||||||
i == to.index ? to.value : 1);
|
i === end.index ? end.time : 1);
|
||||||
if (i == from.index)
|
if (i === start.index)
|
||||||
ctx.moveTo(curve[0], curve[1]);
|
ctx.moveTo(curve[0], curve[1]);
|
||||||
ctx.bezierCurveTo.apply(ctx, curve.slice(2));
|
ctx.bezierCurveTo.apply(ctx, curve.slice(2));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, Base.each(Curve._evaluateMethods,
|
}, Base.each(Curve._evaluateMethods,
|
||||||
function(name) {
|
function(name) {
|
||||||
this[name + 'At'] = function(offset, weighted) {
|
this[name + 'At'] = function(offset) {
|
||||||
var param = this.getTimeAt(offset);
|
var param = this._get(offset);
|
||||||
return Curve[name](this.curves[param.index], param.value, weighted);
|
return Curve[name](this.curves[param.index], param.time);
|
||||||
};
|
};
|
||||||
}, {})
|
}, {})
|
||||||
);
|
);
|
||||||
|
|
10
dist/paper-core.min.js
vendored
10
dist/paper-core.min.js
vendored
File diff suppressed because one or more lines are too long
116
dist/paper-full.js
vendored
116
dist/paper-full.js
vendored
|
@ -9,7 +9,7 @@
|
||||||
*
|
*
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Date: Wed Feb 10 13:26:40 2016 +0100
|
* Date: Wed Feb 10 14:58:40 2016 +0100
|
||||||
*
|
*
|
||||||
***
|
***
|
||||||
*
|
*
|
||||||
|
@ -6062,7 +6062,7 @@ statics: {
|
||||||
: v;
|
: v;
|
||||||
},
|
},
|
||||||
|
|
||||||
isFlatEnough: function(v, tolerance) {
|
isFlatEnough: function(v, flatness) {
|
||||||
var p1x = v[0], p1y = v[1],
|
var p1x = v[0], p1y = v[1],
|
||||||
c1x = v[2], c1y = v[3],
|
c1x = v[2], c1y = v[3],
|
||||||
c2x = v[4], c2y = v[5],
|
c2x = v[4], c2y = v[5],
|
||||||
|
@ -6072,7 +6072,7 @@ statics: {
|
||||||
vx = 3 * c2x - 2 * p2x - p1x,
|
vx = 3 * c2x - 2 * p2x - p1x,
|
||||||
vy = 3 * c2y - 2 * p2y - p1y;
|
vy = 3 * c2y - 2 * p2y - p1y;
|
||||||
return Math.max(ux * ux, vx * vx) + Math.max(uy * uy, vy * vy)
|
return Math.max(ux * ux, vx * vx) + Math.max(uy * uy, vy * vy)
|
||||||
< 10 * tolerance * tolerance;
|
<= 16 * flatness * flatness;
|
||||||
},
|
},
|
||||||
|
|
||||||
getArea: function(v) {
|
getArea: function(v) {
|
||||||
|
@ -7875,6 +7875,19 @@ var Path = PathItem.extend({
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
reduce: function(options) {
|
||||||
|
var curves = this.getCurves(),
|
||||||
|
simplify = options && options.simplify,
|
||||||
|
tolerance = simplify ? 2e-7 : 0;
|
||||||
|
for (var i = curves.length - 1; i >= 0; i--) {
|
||||||
|
var curve = curves[i];
|
||||||
|
if (!curve.hasHandles() && (curve.getLength() < tolerance
|
||||||
|
|| simplify && curve.isCollinear(curve.getNext())))
|
||||||
|
curve.remove();
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
},
|
||||||
|
|
||||||
reverse: function() {
|
reverse: function() {
|
||||||
this._segments.reverse();
|
this._segments.reverse();
|
||||||
for (var i = 0, l = this._segments.length; i < l; i++) {
|
for (var i = 0, l = this._segments.length; i < l; i++) {
|
||||||
|
@ -7890,32 +7903,16 @@ var Path = PathItem.extend({
|
||||||
this._changed(9);
|
this._changed(9);
|
||||||
},
|
},
|
||||||
|
|
||||||
flatten: function(maxDistance) {
|
flatten: function(flatness) {
|
||||||
var iterator = new PathIterator(this, 64, 0.1),
|
var iterator = new PathIterator(this, flatness || 0.25, 256, true),
|
||||||
pos = 0,
|
parts = iterator.parts,
|
||||||
step = iterator.length / Math.ceil(iterator.length / maxDistance),
|
segments = [];
|
||||||
end = iterator.length + (this._closed ? -step : step) / 2;
|
for (var i = 0, l = parts.length; i < l; i++) {
|
||||||
var segments = [];
|
segments.push(new Segment(parts[i].curve.slice(0, 2)));
|
||||||
while (pos <= end) {
|
|
||||||
segments.push(new Segment(iterator.getPointAt(pos)));
|
|
||||||
pos += step;
|
|
||||||
}
|
}
|
||||||
this.setSegments(segments);
|
this.setSegments(segments);
|
||||||
},
|
},
|
||||||
|
|
||||||
reduce: function(options) {
|
|
||||||
var curves = this.getCurves(),
|
|
||||||
simplify = options && options.simplify,
|
|
||||||
tolerance = simplify ? 2e-7 : 0;
|
|
||||||
for (var i = curves.length - 1; i >= 0; i--) {
|
|
||||||
var curve = curves[i];
|
|
||||||
if (!curve.hasHandles() && (curve.getLength() < tolerance
|
|
||||||
|| simplify && curve.isCollinear(curve.getNext())))
|
|
||||||
curve.remove();
|
|
||||||
}
|
|
||||||
return this;
|
|
||||||
},
|
|
||||||
|
|
||||||
simplify: function(tolerance) {
|
simplify: function(tolerance) {
|
||||||
var segments = new PathFitter(this).fit(tolerance || 2.5);
|
var segments = new PathFitter(this).fit(tolerance || 2.5);
|
||||||
if (segments)
|
if (segments)
|
||||||
|
@ -8425,7 +8422,7 @@ new function() {
|
||||||
if (dashLength) {
|
if (dashLength) {
|
||||||
if (!dontStart)
|
if (!dontStart)
|
||||||
ctx.beginPath();
|
ctx.beginPath();
|
||||||
var iterator = new PathIterator(this, 32, 0.25,
|
var iterator = new PathIterator(this, 0.25, 32, false,
|
||||||
strokeMatrix),
|
strokeMatrix),
|
||||||
length = iterator.length,
|
length = iterator.length,
|
||||||
from = -style.getDashOffset(), to,
|
from = -style.getDashOffset(), to,
|
||||||
|
@ -9880,11 +9877,11 @@ CompoundPath.inject({
|
||||||
var PathIterator = Base.extend({
|
var PathIterator = Base.extend({
|
||||||
_class: 'PathIterator',
|
_class: 'PathIterator',
|
||||||
|
|
||||||
initialize: function(path, maxRecursion, tolerance, matrix) {
|
initialize: function(path, flatness, maxRecursion, ignoreStraight, matrix) {
|
||||||
var curves = [],
|
var curves = [],
|
||||||
parts = [],
|
parts = [],
|
||||||
length = 0,
|
length = 0,
|
||||||
minDifference = 1 / (maxRecursion || 32),
|
minSpan = 1 / (maxRecursion || 32),
|
||||||
segments = path._segments,
|
segments = path._segments,
|
||||||
segment1 = segments[0],
|
segment1 = segments[0],
|
||||||
segment2;
|
segment2;
|
||||||
|
@ -9895,23 +9892,25 @@ var PathIterator = Base.extend({
|
||||||
computeParts(curve, segment1._index, 0, 1);
|
computeParts(curve, segment1._index, 0, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
function computeParts(curve, index, minT, maxT) {
|
function computeParts(curve, index, t1, t2) {
|
||||||
if ((maxT - minT) > minDifference
|
if ((t2 - t1) > minSpan
|
||||||
&& !Curve.isFlatEnough(curve, tolerance || 0.25)) {
|
&& !(ignoreStraight && Curve.isStraight(curve))
|
||||||
var split = Curve.subdivide(curve, 0.5),
|
&& !Curve.isFlatEnough(curve, flatness || 0.25)) {
|
||||||
halfT = (minT + maxT) / 2;
|
var halves = Curve.subdivide(curve, 0.5),
|
||||||
computeParts(split[0], index, minT, halfT);
|
tMid = (t1 + t2) / 2;
|
||||||
computeParts(split[1], index, halfT, maxT);
|
computeParts(halves[0], index, t1, tMid);
|
||||||
|
computeParts(halves[1], index, tMid, t2);
|
||||||
} else {
|
} else {
|
||||||
var x = curve[6] - curve[0],
|
var dx = curve[6] - curve[0],
|
||||||
y = curve[7] - curve[1],
|
dy = curve[7] - curve[1],
|
||||||
dist = Math.sqrt(x * x + y * y);
|
dist = Math.sqrt(dx * dx + dy * dy);
|
||||||
if (dist > 1e-6) {
|
if (dist > 0) {
|
||||||
length += dist;
|
length += dist;
|
||||||
parts.push({
|
parts.push({
|
||||||
offset: length,
|
offset: length,
|
||||||
value: maxT,
|
curve: curve,
|
||||||
index: index
|
index: index,
|
||||||
|
time: t2,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9924,14 +9923,13 @@ var PathIterator = Base.extend({
|
||||||
}
|
}
|
||||||
if (path._closed)
|
if (path._closed)
|
||||||
addCurve(segment2, segments[0]);
|
addCurve(segment2, segments[0]);
|
||||||
|
|
||||||
this.curves = curves;
|
this.curves = curves;
|
||||||
this.parts = parts;
|
this.parts = parts;
|
||||||
this.length = length;
|
this.length = length;
|
||||||
this.index = 0;
|
this.index = 0;
|
||||||
},
|
},
|
||||||
|
|
||||||
getTimeAt: function(offset) {
|
_get: function(offset) {
|
||||||
var i, j = this.index;
|
var i, j = this.index;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
i = j;
|
i = j;
|
||||||
|
@ -9943,39 +9941,39 @@ var PathIterator = Base.extend({
|
||||||
if (part.offset >= offset) {
|
if (part.offset >= offset) {
|
||||||
this.index = i;
|
this.index = i;
|
||||||
var prev = this.parts[i - 1];
|
var prev = this.parts[i - 1];
|
||||||
var prevVal = prev && prev.index == part.index ? prev.value : 0,
|
var prevTime = prev && prev.index === part.index ? prev.time : 0,
|
||||||
prevLen = prev ? prev.offset : 0;
|
prevOffset = prev ? prev.offset : 0;
|
||||||
return {
|
return {
|
||||||
value: prevVal + (part.value - prevVal)
|
index: part.index,
|
||||||
* (offset - prevLen) / (part.offset - prevLen),
|
time: prevTime + (part.time - prevTime)
|
||||||
index: part.index
|
* (offset - prevOffset) / (part.offset - prevOffset)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var part = this.parts[this.parts.length - 1];
|
var part = this.parts[this.parts.length - 1];
|
||||||
return {
|
return {
|
||||||
value: 1,
|
index: part.index,
|
||||||
index: part.index
|
time: 1
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
drawPart: function(ctx, from, to) {
|
drawPart: function(ctx, from, to) {
|
||||||
from = this.getTimeAt(from);
|
var start = this._get(from),
|
||||||
to = this.getTimeAt(to);
|
end = this._get(to);
|
||||||
for (var i = from.index; i <= to.index; i++) {
|
for (var i = start.index, l = end.index; i <= l; i++) {
|
||||||
var curve = Curve.getPart(this.curves[i],
|
var curve = Curve.getPart(this.curves[i],
|
||||||
i == from.index ? from.value : 0,
|
i === start.index ? start.time : 0,
|
||||||
i == to.index ? to.value : 1);
|
i === end.index ? end.time : 1);
|
||||||
if (i == from.index)
|
if (i === start.index)
|
||||||
ctx.moveTo(curve[0], curve[1]);
|
ctx.moveTo(curve[0], curve[1]);
|
||||||
ctx.bezierCurveTo.apply(ctx, curve.slice(2));
|
ctx.bezierCurveTo.apply(ctx, curve.slice(2));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, Base.each(Curve._evaluateMethods,
|
}, Base.each(Curve._evaluateMethods,
|
||||||
function(name) {
|
function(name) {
|
||||||
this[name + 'At'] = function(offset, weighted) {
|
this[name + 'At'] = function(offset) {
|
||||||
var param = this.getTimeAt(offset);
|
var param = this._get(offset);
|
||||||
return Curve[name](this.curves[param.index], param.value, weighted);
|
return Curve[name](this.curves[param.index], param.time);
|
||||||
};
|
};
|
||||||
}, {})
|
}, {})
|
||||||
);
|
);
|
||||||
|
|
12
dist/paper-full.min.js
vendored
12
dist/paper-full.min.js
vendored
File diff suppressed because one or more lines are too long
Loading…
Reference in a new issue