mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-08 05:42:07 -05:00
Merge remote branch 'origin/master'
This commit is contained in:
commit
5770ebc9ff
4 changed files with 45 additions and 25 deletions
|
@ -23,8 +23,21 @@
|
||||||
var length = curve.length;
|
var length = curve.length;
|
||||||
var step = 10;
|
var step = 10;
|
||||||
var iteratively = false;
|
var iteratively = false;
|
||||||
|
var curvesToPoints = true;
|
||||||
var num = Math.floor(length / step);
|
var num = Math.floor(length / step);
|
||||||
var prev = 0;
|
var prev = 0;
|
||||||
|
if (curvesToPoints) {
|
||||||
|
var clone = path.clone();
|
||||||
|
clone.curvesToPoints(step);
|
||||||
|
for (var i = 0; i < clone.segments.length; i++) {
|
||||||
|
var point = clone.segments[i].point;
|
||||||
|
var circle = new Path.Circle(point, step / 2);
|
||||||
|
circle.strokeColor = 'red';
|
||||||
|
if (remove)
|
||||||
|
circle.removeOnMove();
|
||||||
|
}
|
||||||
|
clone.remove();
|
||||||
|
} else {
|
||||||
for (var i = 0, pos = 0; i <= num; i++, pos += step) {
|
for (var i = 0, pos = 0; i <= num; i++, pos += step) {
|
||||||
var t = iteratively
|
var t = iteratively
|
||||||
? curve.getParameter(step, prev)
|
? curve.getParameter(step, prev)
|
||||||
|
@ -37,6 +50,7 @@
|
||||||
prev = t;
|
prev = t;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// modifyCurve(new Point(400, 377), false);
|
// modifyCurve(new Point(400, 377), false);
|
||||||
|
|
||||||
|
|
|
@ -302,19 +302,6 @@ var Curve = this.Curve = Base.extend({
|
||||||
// TODO: getIntersections
|
// TODO: getIntersections
|
||||||
// TODO: adjustThroughPoint
|
// TODO: adjustThroughPoint
|
||||||
|
|
||||||
// DOCS: document Curve#transform(matrix)
|
|
||||||
/**
|
|
||||||
* @param {Matrix} matrix
|
|
||||||
* @return {Curve}
|
|
||||||
*/
|
|
||||||
transform: function(matrix) {
|
|
||||||
return new Curve(
|
|
||||||
matrix._transformPoint(this._segment1._point),
|
|
||||||
matrix._transformPoint(this._segment1._handleOut),
|
|
||||||
matrix._transformPoint(this._segment2._handleIn),
|
|
||||||
matrix._transformPoint(this._segment2._point));
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a reversed version of the curve, without modifying the curve
|
* Returns a reversed version of the curve, without modifying the curve
|
||||||
* itself.
|
* itself.
|
||||||
|
|
|
@ -459,8 +459,21 @@ var Path = this.Path = PathItem.extend({
|
||||||
this.setSelected(selected);
|
this.setSelected(selected);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
curvesToPoints: function(maxDistance) {
|
||||||
|
var flattener = new PathFlattener(this),
|
||||||
|
pos = 0;
|
||||||
|
var step = flattener.length / Math.ceil(flattener.length / maxDistance);
|
||||||
|
this.segments = [];
|
||||||
|
// Iterate over path and evaluate and add points at given offsets
|
||||||
|
do {
|
||||||
|
this._add([ new Segment(flattener.evaluate(pos, 0)) ]);
|
||||||
|
} while ((pos += step) < flattener.length);
|
||||||
|
// Add last one
|
||||||
|
this._add([ new Segment(flattener.evaluate(flattener.length, 0)) ]);
|
||||||
|
this._changed(ChangeFlags.GEOMETRY);
|
||||||
|
},
|
||||||
|
|
||||||
// TODO: pointsToCurves([tolerance[, threshold[, cornerRadius[, scale]]]])
|
// TODO: pointsToCurves([tolerance[, threshold[, cornerRadius[, scale]]]])
|
||||||
// TODO: curvesToPoints([maxPointDistance[, flatness]])
|
|
||||||
// TODO: reduceSegments([flatness])
|
// TODO: reduceSegments([flatness])
|
||||||
// TODO: split(offset) / split(location) / split(index[, parameter])
|
// TODO: split(offset) / split(location) / split(index[, parameter])
|
||||||
|
|
||||||
|
|
|
@ -113,6 +113,12 @@ var PathFlattener = Base.extend({
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
evaluate: function(offset, type) {
|
||||||
|
var param = this.getParameter(offset);
|
||||||
|
return Curve.evaluate.apply(Curve,
|
||||||
|
this.curves[param.index].concat([param.value, type]));
|
||||||
|
},
|
||||||
|
|
||||||
drawPart: function(ctx, from, to) {
|
drawPart: function(ctx, from, to) {
|
||||||
from = this.getParameter(from);
|
from = this.getParameter(from);
|
||||||
to = this.getParameter(to);
|
to = this.getParameter(to);
|
||||||
|
|
Loading…
Reference in a new issue