mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-03 19:45:44 -05:00
Expose and reuse Curve evaluation method names.
This commit is contained in:
parent
9fe93d1434
commit
84b202fd79
4 changed files with 36 additions and 29 deletions
|
@ -719,7 +719,8 @@ statics: {
|
|||
padding);
|
||||
}
|
||||
}
|
||||
}}, Base.each(['getBounds', 'getStrokeBounds', 'getHandleBounds', 'getRoughBounds'],
|
||||
}}, Base.each(
|
||||
['getBounds', 'getStrokeBounds', 'getHandleBounds', 'getRoughBounds'],
|
||||
// Note: Although Curve.getBounds() exists, we are using Path.getBounds() to
|
||||
// determine the bounds of Curve objects with defined segment1 and segment2
|
||||
// values Curve.getBounds() can be used directly on curve arrays, without
|
||||
|
@ -769,21 +770,7 @@ statics: {
|
|||
* @type Rectangle
|
||||
* @ignore
|
||||
*/
|
||||
}), Base.each(['getPoint', 'getTangent', 'getNormal', 'getWeightedTangent',
|
||||
'getWeightedNormal', 'getCurvature'],
|
||||
// Note: Although Curve.getBounds() exists, we are using Path.getBounds() to
|
||||
// determine the bounds of Curve objects with defined segment1 and segment2
|
||||
// values Curve.getBounds() can be used directly on curve arrays, without
|
||||
// the need to create a Curve object first, as required by the code that
|
||||
// finds path interesections.
|
||||
function(name) {
|
||||
this[name + 'At'] = function(offset, isParameter) {
|
||||
var values = this.getValues();
|
||||
return Curve[name](values, isParameter ? offset
|
||||
: Curve.getParameterAt(values, offset, 0));
|
||||
};
|
||||
},
|
||||
/** @lends Curve# */{
|
||||
}), /** @lends Curve# */{
|
||||
// Explicitly deactivate the creation of beans, as we have functions here
|
||||
// that look like bean getters but actually read arguments.
|
||||
// See #getParameterOf(), #getLocationOf(), #getNearestLocation(), ...
|
||||
|
@ -970,7 +957,28 @@ statics: {
|
|||
* is a curve time parameter
|
||||
* @return {Number} the curvature of the curve at the given offset
|
||||
*/
|
||||
}),
|
||||
},
|
||||
new function() { // // Scope to inject various evaluate methods
|
||||
var methods = ['getPoint', 'getTangent', 'getNormal', 'getWeightedTangent',
|
||||
'getWeightedNormal', 'getCurvature'];
|
||||
return Base.each(methods,
|
||||
// Note: Although Curve.getBounds() exists, we are using Path.getBounds() to
|
||||
// determine the bounds of Curve objects with defined segment1 and segment2
|
||||
// values Curve.getBounds() can be used directly on curve arrays, without
|
||||
// the need to create a Curve object first, as required by the code that
|
||||
// finds path interesections.
|
||||
function(name) {
|
||||
this[name + 'At'] = function(offset, isParameter) {
|
||||
var values = this.getValues();
|
||||
return Curve[name](values, isParameter ? offset
|
||||
: Curve.getParameterAt(values, offset, 0));
|
||||
};
|
||||
}, {
|
||||
statics: {
|
||||
evaluateMethods: methods
|
||||
}
|
||||
})
|
||||
},
|
||||
new function() { // Scope for methods that require private functions
|
||||
|
||||
function getLengthIntegrand(v) {
|
||||
|
|
|
@ -307,13 +307,14 @@ var CurveLocation = Base.extend(/** @lends CurveLocation# */{
|
|||
parts.push('distance: ' + f.number(this._distance));
|
||||
return '{ ' + parts.join(', ') + ' }';
|
||||
}
|
||||
}, Base.each(['getTangent', 'getNormal', 'getWeightedTangent',
|
||||
'getWeightedNormal', 'getCurvature'], function(name) {
|
||||
}, Base.each(Curve.evaluateMethods, function(name) {
|
||||
// Produce getters for #getTangent() / #getNormal() / #getCurvature()
|
||||
var get = name + 'At';
|
||||
this[name] = function() {
|
||||
var parameter = this.getParameter(),
|
||||
curve = this.getCurve();
|
||||
return parameter != null && curve && curve[get](parameter, true);
|
||||
};
|
||||
if (name !== 'getPoint') {
|
||||
var get = name + 'At';
|
||||
this[name] = function() {
|
||||
var parameter = this.getParameter(),
|
||||
curve = this.getCurve();
|
||||
return parameter != null && curve && curve[get](parameter, true);
|
||||
};
|
||||
}
|
||||
}, {}));
|
||||
|
|
|
@ -1638,8 +1638,7 @@ var Path = PathItem.extend(/** @lends Path# */{
|
|||
|
||||
// TODO: intersects(item)
|
||||
// TODO: contains(item)
|
||||
}, Base.each(['getPoint', 'getTangent', 'getNormal', 'getWeightedTangent',
|
||||
'getWeightedNormal', 'getCurvature'],
|
||||
}, Base.each(Curve.evaluateMethods,
|
||||
function(name) {
|
||||
this[name + 'At'] = function(offset, isParameter) {
|
||||
var loc = this.getLocationAt(offset, isParameter);
|
||||
|
|
|
@ -146,8 +146,7 @@ var PathIterator = Base.extend({
|
|||
ctx.bezierCurveTo.apply(ctx, curve.slice(2));
|
||||
}
|
||||
}
|
||||
}, Base.each(['getPoint', 'getTangent', 'getNormal', 'getWeightedTangent',
|
||||
'getWeightedNormal', 'getCurvature'],
|
||||
}, Base.each(Curve.evaluateMethods,
|
||||
function(name) {
|
||||
this[name + 'At'] = function(offset, weighted) {
|
||||
var param = this.getParameterAt(offset);
|
||||
|
|
Loading…
Reference in a new issue