mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-06 04:42:15 -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);
|
padding);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}}, Base.each(['getBounds', 'getStrokeBounds', 'getHandleBounds', 'getRoughBounds'],
|
}}, Base.each(
|
||||||
|
['getBounds', 'getStrokeBounds', 'getHandleBounds', 'getRoughBounds'],
|
||||||
// Note: Although Curve.getBounds() exists, we are using Path.getBounds() to
|
// Note: Although Curve.getBounds() exists, we are using Path.getBounds() to
|
||||||
// determine the bounds of Curve objects with defined segment1 and segment2
|
// determine the bounds of Curve objects with defined segment1 and segment2
|
||||||
// values Curve.getBounds() can be used directly on curve arrays, without
|
// values Curve.getBounds() can be used directly on curve arrays, without
|
||||||
|
@ -769,21 +770,7 @@ statics: {
|
||||||
* @type Rectangle
|
* @type Rectangle
|
||||||
* @ignore
|
* @ignore
|
||||||
*/
|
*/
|
||||||
}), Base.each(['getPoint', 'getTangent', 'getNormal', 'getWeightedTangent',
|
}), /** @lends Curve# */{
|
||||||
'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# */{
|
|
||||||
// Explicitly deactivate the creation of beans, as we have functions here
|
// Explicitly deactivate the creation of beans, as we have functions here
|
||||||
// that look like bean getters but actually read arguments.
|
// that look like bean getters but actually read arguments.
|
||||||
// See #getParameterOf(), #getLocationOf(), #getNearestLocation(), ...
|
// See #getParameterOf(), #getLocationOf(), #getNearestLocation(), ...
|
||||||
|
@ -970,7 +957,28 @@ statics: {
|
||||||
* is a curve time parameter
|
* is a curve time parameter
|
||||||
* @return {Number} the curvature of the curve at the given offset
|
* @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
|
new function() { // Scope for methods that require private functions
|
||||||
|
|
||||||
function getLengthIntegrand(v) {
|
function getLengthIntegrand(v) {
|
||||||
|
|
|
@ -307,13 +307,14 @@ var CurveLocation = Base.extend(/** @lends CurveLocation# */{
|
||||||
parts.push('distance: ' + f.number(this._distance));
|
parts.push('distance: ' + f.number(this._distance));
|
||||||
return '{ ' + parts.join(', ') + ' }';
|
return '{ ' + parts.join(', ') + ' }';
|
||||||
}
|
}
|
||||||
}, Base.each(['getTangent', 'getNormal', 'getWeightedTangent',
|
}, Base.each(Curve.evaluateMethods, function(name) {
|
||||||
'getWeightedNormal', 'getCurvature'], function(name) {
|
|
||||||
// Produce getters for #getTangent() / #getNormal() / #getCurvature()
|
// Produce getters for #getTangent() / #getNormal() / #getCurvature()
|
||||||
var get = name + 'At';
|
if (name !== 'getPoint') {
|
||||||
this[name] = function() {
|
var get = name + 'At';
|
||||||
var parameter = this.getParameter(),
|
this[name] = function() {
|
||||||
curve = this.getCurve();
|
var parameter = this.getParameter(),
|
||||||
return parameter != null && curve && curve[get](parameter, true);
|
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: intersects(item)
|
||||||
// TODO: contains(item)
|
// TODO: contains(item)
|
||||||
}, Base.each(['getPoint', 'getTangent', 'getNormal', 'getWeightedTangent',
|
}, Base.each(Curve.evaluateMethods,
|
||||||
'getWeightedNormal', 'getCurvature'],
|
|
||||||
function(name) {
|
function(name) {
|
||||||
this[name + 'At'] = function(offset, isParameter) {
|
this[name + 'At'] = function(offset, isParameter) {
|
||||||
var loc = this.getLocationAt(offset, isParameter);
|
var loc = this.getLocationAt(offset, isParameter);
|
||||||
|
|
|
@ -146,8 +146,7 @@ var PathIterator = Base.extend({
|
||||||
ctx.bezierCurveTo.apply(ctx, curve.slice(2));
|
ctx.bezierCurveTo.apply(ctx, curve.slice(2));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, Base.each(['getPoint', 'getTangent', 'getNormal', 'getWeightedTangent',
|
}, Base.each(Curve.evaluateMethods,
|
||||||
'getWeightedNormal', 'getCurvature'],
|
|
||||||
function(name) {
|
function(name) {
|
||||||
this[name + 'At'] = function(offset, weighted) {
|
this[name + 'At'] = function(offset, weighted) {
|
||||||
var param = this.getParameterAt(offset);
|
var param = this.getParameterAt(offset);
|
||||||
|
|
Loading…
Reference in a new issue