mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-03-15 17:29:52 -04:00
Use loop to produce CurveLocation getters, and add CurveLocation#curvature.
This commit is contained in:
parent
d3d9e4bada
commit
652dbe1e86
1 changed files with 21 additions and 11 deletions
|
@ -209,26 +209,26 @@ var CurveLocation = Base.extend(/** @lends CurveLocation# */{
|
||||||
/**
|
/**
|
||||||
* The tangential vector to the {@link #curve} at the given location.
|
* The tangential vector to the {@link #curve} at the given location.
|
||||||
*
|
*
|
||||||
|
* @name Item#getTangent
|
||||||
* @type Point
|
* @type Point
|
||||||
* @bean
|
* @bean
|
||||||
*/
|
*/
|
||||||
getTangent: function() {
|
|
||||||
var parameter = this.getParameter(),
|
|
||||||
curve = this.getCurve();
|
|
||||||
return parameter != null && curve && curve.getTangentAt(parameter, true);
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The normal vector to the {@link #curve} at the given location.
|
* The normal vector to the {@link #curve} at the given location.
|
||||||
*
|
*
|
||||||
|
* @name Item#getNormal
|
||||||
* @type Point
|
* @type Point
|
||||||
* @bean
|
* @bean
|
||||||
*/
|
*/
|
||||||
getNormal: function() {
|
|
||||||
var parameter = this.getParameter(),
|
/**
|
||||||
curve = this.getCurve();
|
* The curvature of the {@link #curve} at the given location.
|
||||||
return parameter != null && curve && curve.getNormalAt(parameter, true);
|
*
|
||||||
},
|
* @name Item#getCurvature
|
||||||
|
* @type Number
|
||||||
|
* @bean
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The distance from the queried point to the returned location.
|
* The distance from the queried point to the returned location.
|
||||||
|
@ -288,4 +288,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(['Tangent', 'Normal', 'Curvature'],
|
||||||
|
// Produce getters for #getTangent() / #getNormal() / #getCurvature()
|
||||||
|
function(name) {
|
||||||
|
var get = 'get' + name + 'At';
|
||||||
|
this['get' + name] = function() {
|
||||||
|
var parameter = this.getParameter(),
|
||||||
|
curve = this.getCurve();
|
||||||
|
return parameter != null && curve && curve[get](parameter, true);
|
||||||
|
};
|
||||||
|
}, {}
|
||||||
|
));
|
||||||
|
|
Loading…
Reference in a new issue