mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-20 22:39:50 -05:00
Rename from, to parameters to start, end in methods where the end is exclusive.
Relates to #338
This commit is contained in:
parent
7ad6dc2d5f
commit
86b9d04c43
2 changed files with 30 additions and 30 deletions
|
@ -2442,24 +2442,24 @@ var Item = Base.extend(Emitter, /** @lends Item# */{
|
||||||
* @return {Item[]} an array containing the removed items
|
* @return {Item[]} an array containing the removed items
|
||||||
*/
|
*/
|
||||||
/**
|
/**
|
||||||
* Removes the children from the specified `from` index to the `to` index
|
* Removes the children from the specified `start` index to and excluding
|
||||||
* from the parent's {@link #children} array.
|
* the `end` index from the parent's {@link #children} array.
|
||||||
*
|
*
|
||||||
* @name Item#removeChildren
|
* @name Item#removeChildren
|
||||||
* @function
|
* @function
|
||||||
* @param {Number} from the beginning index, inclusive
|
* @param {Number} start the beginning index, inclusive
|
||||||
* @param {Number} [to=children.length] the ending index, exclusive
|
* @param {Number} [end=children.length] the ending index, exclusive
|
||||||
* @return {Item[]} an array containing the removed items
|
* @return {Item[]} an array containing the removed items
|
||||||
*/
|
*/
|
||||||
removeChildren: function(from, to) {
|
removeChildren: function(start, end) {
|
||||||
if (!this._children)
|
if (!this._children)
|
||||||
return null;
|
return null;
|
||||||
from = from || 0;
|
start = start || 0;
|
||||||
to = Base.pick(to, this._children.length);
|
end = Base.pick(end, this._children.length);
|
||||||
// Use Base.splice(), which adjusts #_index for the items above, and
|
// Use Base.splice(), which adjusts #_index for the items above, and
|
||||||
// deletes it for the removed items. Calling #_remove() afterwards is
|
// deletes it for the removed items. Calling #_remove() afterwards is
|
||||||
// fine, since it only calls Base.splice() if #_index is set.
|
// fine, since it only calls Base.splice() if #_index is set.
|
||||||
var removed = Base.splice(this._children, null, from, to - from);
|
var removed = Base.splice(this._children, null, start, end - start);
|
||||||
for (var i = removed.length - 1; i >= 0; i--) {
|
for (var i = removed.length - 1; i >= 0; i--) {
|
||||||
// Don't notify parent each time, notify it separately after.
|
// Don't notify parent each time, notify it separately after.
|
||||||
removed[i]._remove(true, false);
|
removed[i]._remove(true, false);
|
||||||
|
|
|
@ -417,21 +417,21 @@ var Path = PathItem.extend(/** @lends Path# */{
|
||||||
var total = this._countCurves(),
|
var total = this._countCurves(),
|
||||||
// If we're adding a new segment to the end of an open path,
|
// If we're adding a new segment to the end of an open path,
|
||||||
// we need to step one index down to get its curve.
|
// we need to step one index down to get its curve.
|
||||||
from = index > 0 && index + amount - 1 === total ? index - 1
|
start = index > 0 && index + amount - 1 === total ? index - 1
|
||||||
: index,
|
: index,
|
||||||
start = from,
|
insert = start,
|
||||||
to = Math.min(from + amount, total);
|
end = Math.min(start + amount, total);
|
||||||
if (segs._curves) {
|
if (segs._curves) {
|
||||||
// Reuse removed curves.
|
// Reuse removed curves.
|
||||||
curves.splice.apply(curves, [from, 0].concat(segs._curves));
|
curves.splice.apply(curves, [start, 0].concat(segs._curves));
|
||||||
start += segs._curves.length;
|
insert += segs._curves.length;
|
||||||
}
|
}
|
||||||
// Insert new curves, but do not initialize their segments yet,
|
// Insert new curves, but do not initialize their segments yet,
|
||||||
// since #_adjustCurves() handles all that for us.
|
// since #_adjustCurves() handles all that for us.
|
||||||
for (var i = start; i < to; i++)
|
for (var i = insert; i < end; i++)
|
||||||
curves.splice(i, 0, new Curve(this, null, null));
|
curves.splice(i, 0, new Curve(this, null, null));
|
||||||
// Adjust segments for the curves before and after the removed ones
|
// Adjust segments for the curves before and after the removed ones
|
||||||
this._adjustCurves(from, to);
|
this._adjustCurves(start, end);
|
||||||
}
|
}
|
||||||
// Use SEGMENTS notification instead of GEOMETRY since curves are kept
|
// Use SEGMENTS notification instead of GEOMETRY since curves are kept
|
||||||
// up-to-date by _adjustCurves() and don't need notification.
|
// up-to-date by _adjustCurves() and don't need notification.
|
||||||
|
@ -442,11 +442,11 @@ var Path = PathItem.extend(/** @lends Path# */{
|
||||||
/**
|
/**
|
||||||
* Adjusts segments of curves before and after inserted / removed segments.
|
* Adjusts segments of curves before and after inserted / removed segments.
|
||||||
*/
|
*/
|
||||||
_adjustCurves: function(from, to) {
|
_adjustCurves: function(start, end) {
|
||||||
var segments = this._segments,
|
var segments = this._segments,
|
||||||
curves = this._curves,
|
curves = this._curves,
|
||||||
curve;
|
curve;
|
||||||
for (var i = from; i < to; i++) {
|
for (var i = start; i < end; i++) {
|
||||||
curve = curves[i];
|
curve = curves[i];
|
||||||
curve._path = this;
|
curve._path = this;
|
||||||
curve._segment1 = segments[i];
|
curve._segment1 = segments[i];
|
||||||
|
@ -455,14 +455,14 @@ var Path = PathItem.extend(/** @lends Path# */{
|
||||||
}
|
}
|
||||||
// If it's the first segment, correct the last segment of closed
|
// If it's the first segment, correct the last segment of closed
|
||||||
// paths too:
|
// paths too:
|
||||||
if (curve = curves[this._closed && from === 0 ? segments.length - 1
|
if (curve = curves[this._closed && start === 0 ? segments.length - 1
|
||||||
: from - 1]) {
|
: start - 1]) {
|
||||||
curve._segment2 = segments[from] || segments[0];
|
curve._segment2 = segments[start] || segments[0];
|
||||||
curve._changed();
|
curve._changed();
|
||||||
}
|
}
|
||||||
// Fix the segment after the modified range, if it exists
|
// Fix the segment after the modified range, if it exists
|
||||||
if (curve = curves[to]) {
|
if (curve = curves[end]) {
|
||||||
curve._segment1 = segments[to];
|
curve._segment1 = segments[end];
|
||||||
curve._changed();
|
curve._changed();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -725,13 +725,13 @@ var Path = PathItem.extend(/** @lends Path# */{
|
||||||
* // Select the path, so we can see its segments:
|
* // Select the path, so we can see its segments:
|
||||||
* path.selected = true;
|
* path.selected = true;
|
||||||
*/
|
*/
|
||||||
removeSegments: function(from, to, _includeCurves) {
|
removeSegments: function(start, end, _includeCurves) {
|
||||||
from = from || 0;
|
start = start || 0;
|
||||||
to = Base.pick(to, this._segments.length);
|
end = Base.pick(end, this._segments.length);
|
||||||
var segments = this._segments,
|
var segments = this._segments,
|
||||||
curves = this._curves,
|
curves = this._curves,
|
||||||
count = segments.length, // segment count before removal
|
count = segments.length, // segment count before removal
|
||||||
removed = segments.splice(from, to - from),
|
removed = segments.splice(start, end - start),
|
||||||
amount = removed.length;
|
amount = removed.length;
|
||||||
if (!amount)
|
if (!amount)
|
||||||
return removed;
|
return removed;
|
||||||
|
@ -744,7 +744,7 @@ var Path = PathItem.extend(/** @lends Path# */{
|
||||||
segment._index = segment._path = null;
|
segment._index = segment._path = null;
|
||||||
}
|
}
|
||||||
// Adjust the indices of the segments above.
|
// Adjust the indices of the segments above.
|
||||||
for (var i = from, l = segments.length; i < l; i++)
|
for (var i = start, l = segments.length; i < l; i++)
|
||||||
segments[i]._index = i;
|
segments[i]._index = i;
|
||||||
// Keep curves in sync
|
// Keep curves in sync
|
||||||
if (curves) {
|
if (curves) {
|
||||||
|
@ -752,9 +752,9 @@ var Path = PathItem.extend(/** @lends Path# */{
|
||||||
// one to the left of the segment, not to the right, as normally).
|
// one to the left of the segment, not to the right, as normally).
|
||||||
// Also take into account closed paths, which have one curve more
|
// Also take into account closed paths, which have one curve more
|
||||||
// than segments.
|
// than segments.
|
||||||
var index = from > 0 && to === count + (this._closed ? 1 : 0)
|
var index = start > 0 && end === count + (this._closed ? 1 : 0)
|
||||||
? from - 1
|
? start - 1
|
||||||
: from,
|
: start,
|
||||||
curves = curves.splice(index, amount);
|
curves = curves.splice(index, amount);
|
||||||
// Unlink the removed curves from the path.
|
// Unlink the removed curves from the path.
|
||||||
for (var i = curves.length - 1; i >= 0; i--)
|
for (var i = curves.length - 1; i >= 0; i--)
|
||||||
|
|
Loading…
Reference in a new issue