mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-05 20:32:00 -05:00
Merge remote branch 'origin/master'
This commit is contained in:
commit
5770ebc9ff
4 changed files with 45 additions and 25 deletions
|
@ -23,18 +23,32 @@
|
|||
var length = curve.length;
|
||||
var step = 10;
|
||||
var iteratively = false;
|
||||
var curvesToPoints = true;
|
||||
var num = Math.floor(length / step);
|
||||
var prev = 0;
|
||||
for (var i = 0, pos = 0; i <= num; i++, pos += step) {
|
||||
var t = iteratively
|
||||
? curve.getParameter(step, prev)
|
||||
: curve.getParameter(pos);
|
||||
var point = curve.getPoint(t);
|
||||
var circle = new Path.Circle(point, step / 2);
|
||||
circle.strokeColor = 'red';
|
||||
if (remove)
|
||||
circle.removeOnMove();
|
||||
prev = t;
|
||||
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) {
|
||||
var t = iteratively
|
||||
? curve.getParameter(step, prev)
|
||||
: curve.getParameter(pos);
|
||||
var point = curve.getPoint(t);
|
||||
var circle = new Path.Circle(point, step / 2);
|
||||
circle.strokeColor = 'red';
|
||||
if (remove)
|
||||
circle.removeOnMove();
|
||||
prev = t;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -302,19 +302,6 @@ var Curve = this.Curve = Base.extend({
|
|||
// TODO: getIntersections
|
||||
// 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
|
||||
* itself.
|
||||
|
|
|
@ -458,9 +458,22 @@ var Path = this.Path = PathItem.extend({
|
|||
setFullySelected: function(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: curvesToPoints([maxPointDistance[, flatness]])
|
||||
// TODO: reduceSegments([flatness])
|
||||
// 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) {
|
||||
from = this.getParameter(from);
|
||||
to = this.getParameter(to);
|
||||
|
|
Loading…
Reference in a new issue