mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-04 03:45:58 -05:00
Winding: Some improvements to comments and documentation.
This commit is contained in:
parent
8513144ae1
commit
91e67887da
1 changed files with 30 additions and 11 deletions
|
@ -217,7 +217,11 @@ PathItem.inject(new function() {
|
||||||
* Divides the path-items at the given locations.
|
* Divides the path-items at the given locations.
|
||||||
*
|
*
|
||||||
* @param {CurveLocation[]} locations an array of the locations to split the
|
* @param {CurveLocation[]} locations an array of the locations to split the
|
||||||
* path-item at.
|
* path-item at.
|
||||||
|
* @param {Function} [include] a function that determines if dividing should
|
||||||
|
* happen at a given location.
|
||||||
|
* @return {CurveLocation[]} the locations at which the involved path-items
|
||||||
|
* were divided
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
function divideLocations(locations, include) {
|
function divideLocations(locations, include) {
|
||||||
|
@ -295,6 +299,21 @@ PathItem.inject(new function() {
|
||||||
return results || locations;
|
return results || locations;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the winding contribution number of the given point in respect
|
||||||
|
* to the shapes described by the passed curves.
|
||||||
|
*
|
||||||
|
* @param {Point} point the location for which to determine the winding
|
||||||
|
* contribution
|
||||||
|
* @param {Curve[]} curves the curves that describe the shape against which
|
||||||
|
* to check, as returned by {@link Path#getCurves()} or
|
||||||
|
* {@link CompoundPath#getCurves()}
|
||||||
|
* @param {Number} [dir=0] the direction in which to determine the
|
||||||
|
* winding contribution, `0`: in x-direction, `1`: in y-direction
|
||||||
|
* @return {Object} an object containing the calculated winding number, as
|
||||||
|
* well as an indication whether the point was situated on the contour
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
function getWinding(point, curves, dir) {
|
function getWinding(point, curves, dir) {
|
||||||
var epsilon = /*#=*/Numerical.WINDING_EPSILON,
|
var epsilon = /*#=*/Numerical.WINDING_EPSILON,
|
||||||
abs = Math.abs,
|
abs = Math.abs,
|
||||||
|
@ -415,7 +434,7 @@ PathItem.inject(new function() {
|
||||||
( a0 > aAfter && a1 > aAfter &&
|
( a0 > aAfter && a1 > aAfter &&
|
||||||
a2 > aAfter && a3 > aAfter)
|
a2 > aAfter && a3 > aAfter)
|
||||||
? [v] : Curve.getMonoCurves(v, dir);
|
? [v] : Curve.getMonoCurves(v, dir);
|
||||||
for (var i = 0; i < monoCurves.length; i++) {
|
for (var i = 0, l = monoCurves.length; i < l; i++) {
|
||||||
prevV = addWinding(monoCurves[i]);
|
prevV = addWinding(monoCurves[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -437,7 +456,7 @@ PathItem.inject(new function() {
|
||||||
x1 = p1._x, y1 = p1._y,
|
x1 = p1._x, y1 = p1._y,
|
||||||
x2 = p2._x, y2 = p2._y;
|
x2 = p2._x, y2 = p2._y;
|
||||||
closeV = [x1, y1, x1, y1, x2, y2, x2, y2];
|
closeV = [x1, y1, x1, y1, x2, y2, x2, y2];
|
||||||
// The closing curve is a potential candidate for the last
|
// This closing curve is a potential candidate for the last
|
||||||
// non-horizontal curve.
|
// non-horizontal curve.
|
||||||
if (closeV[io] !== closeV[io + 6]) {
|
if (closeV[io] !== closeV[io + 6]) {
|
||||||
prevV = closeV;
|
prevV = closeV;
|
||||||
|
@ -528,9 +547,9 @@ PathItem.inject(new function() {
|
||||||
parent = path._parent,
|
parent = path._parent,
|
||||||
t = curve.getTimeAt(length),
|
t = curve.getTimeAt(length),
|
||||||
pt = curve.getPointAtTime(t),
|
pt = curve.getPointAtTime(t),
|
||||||
// Determine whether to check winding in horizontal or
|
// Determine the direction in which to check the winding
|
||||||
// vertical direction from the point based on the curve's
|
// from the point (horizontal or vertical), based on the
|
||||||
// direction at the given point.
|
// curve's direction at that point.
|
||||||
dir = Math.abs(curve.getTangentAtTime(t).normalize().y)
|
dir = Math.abs(curve.getTangentAtTime(t).normalize().y)
|
||||||
< 0.5 ? 1 : 0;
|
< 0.5 ? 1 : 0;
|
||||||
if (parent instanceof CompoundPath)
|
if (parent instanceof CompoundPath)
|
||||||
|
@ -750,13 +769,13 @@ PathItem.inject(new function() {
|
||||||
|
|
||||||
return /** @lends PathItem# */{
|
return /** @lends PathItem# */{
|
||||||
/**
|
/**
|
||||||
* Returns the winding contribution of the given point with respect to
|
* Returns the winding contribution number of the given point in respect
|
||||||
* this PathItem.
|
* to this PathItem.
|
||||||
*
|
*
|
||||||
* @param {Point} point the location for which to determine the winding
|
* @param {Point} point the location for which to determine the winding
|
||||||
* direction
|
* contribution
|
||||||
* @param {Boolean} horizontal whether we need to consider this point as
|
* @param {Number} [dir=0] the direction in which to determine the
|
||||||
* part of a horizontal curve
|
* winding contribution, `0`: in x-direction, `1`: in y-direction
|
||||||
* @return {Number} the winding number
|
* @return {Number} the winding number
|
||||||
*/
|
*/
|
||||||
_getWinding: function(point, dir) {
|
_getWinding: function(point, dir) {
|
||||||
|
|
Loading…
Reference in a new issue