mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-08 05:42:07 -05:00
Add getter/setter for Path#closed.
This commit is contained in:
parent
bf3bd13540
commit
781b315808
5 changed files with 31 additions and 24 deletions
|
@ -89,7 +89,7 @@ var CompoundPath = this.CompoundPath = PathItem.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
closePath: function() {
|
closePath: function() {
|
||||||
getCurrentPath(this).closed = true;
|
getCurrentPath(this).setClosed(true);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -132,13 +132,13 @@ var Curve = this.Curve = Base.extend({
|
||||||
// TODO: No need to call getCurves() here?
|
// TODO: No need to call getCurves() here?
|
||||||
var curves = this._path && this._path._curves;
|
var curves = this._path && this._path._curves;
|
||||||
return curves && (curves[this._index1 + 1]
|
return curves && (curves[this._index1 + 1]
|
||||||
|| this._path.closed && curves[0]) || null;
|
|| this._path._closed && curves[0]) || null;
|
||||||
},
|
},
|
||||||
|
|
||||||
getPrevious: function() {
|
getPrevious: function() {
|
||||||
var curves = this._path && this._path._curves;
|
var curves = this._path && this._path._curves;
|
||||||
return curves && (curves[this._index1 - 1]
|
return curves && (curves[this._index1 - 1]
|
||||||
|| this._path.closed && curves[curves.length - 1]) || null;
|
|| this._path._closed && curves[curves.length - 1]) || null;
|
||||||
},
|
},
|
||||||
|
|
||||||
setSelected: function(selected) {
|
setSelected: function(selected) {
|
||||||
|
|
|
@ -41,7 +41,7 @@ Path.inject({ statics: new function() {
|
||||||
for (var i = 0; i < 4; i++) {
|
for (var i = 0; i < 4; i++) {
|
||||||
path.add(rect[corners[i]]());
|
path.add(rect[corners[i]]());
|
||||||
}
|
}
|
||||||
path.closed = true;
|
path.setClosed(true);
|
||||||
return path;
|
return path;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -74,7 +74,7 @@ Path.inject({ statics: new function() {
|
||||||
path.add(br.subtract(0, size.height), null, [0, uSize.height]);
|
path.add(br.subtract(0, size.height), null, [0, uSize.height]);
|
||||||
path.add(br.subtract(size.width, 0), [uSize.width, 0], null);
|
path.add(br.subtract(size.width, 0), [uSize.width, 0], null);
|
||||||
|
|
||||||
path.closed = true;
|
path.setClosed(true);
|
||||||
return path;
|
return path;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -91,7 +91,7 @@ Path.inject({ statics: new function() {
|
||||||
segment._handleOut.multiply(size)
|
segment._handleOut.multiply(size)
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
path.closed = true;
|
path.setClosed(true);
|
||||||
return path;
|
return path;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -123,7 +123,7 @@ Path.inject({ statics: new function() {
|
||||||
var angle = (360 / numSides) * (i + offset);
|
var angle = (360 / numSides) * (i + offset);
|
||||||
path.add(center.add(vector.rotate(angle)));
|
path.add(center.add(vector.rotate(angle)));
|
||||||
}
|
}
|
||||||
path.closed = true;
|
path.setClosed(true);
|
||||||
return path;
|
return path;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -138,7 +138,7 @@ Path.inject({ statics: new function() {
|
||||||
length: i % 2 ? radius2 : radius1
|
length: i % 2 ? radius2 : radius1
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
path.closed = true;
|
path.setClosed(true);
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -19,7 +19,7 @@ var Path = this.Path = PathItem.extend({
|
||||||
|
|
||||||
initialize: function(segments) {
|
initialize: function(segments) {
|
||||||
this.base();
|
this.base();
|
||||||
this.closed = false;
|
this._closed = false;
|
||||||
this._selectedSegmentCount = 0;
|
this._selectedSegmentCount = 0;
|
||||||
// Support both passing of segments as array or arguments
|
// Support both passing of segments as array or arguments
|
||||||
// If it is an array, it can also be a description of a point, so
|
// If it is an array, it can also be a description of a point, so
|
||||||
|
@ -34,7 +34,7 @@ var Path = this.Path = PathItem.extend({
|
||||||
getCurves: function() {
|
getCurves: function() {
|
||||||
var length = this._segments.length;
|
var length = this._segments.length;
|
||||||
// Reduce length by one if it's an open path:
|
// Reduce length by one if it's an open path:
|
||||||
if (!this.closed && length > 0)
|
if (!this._closed && length > 0)
|
||||||
length--;
|
length--;
|
||||||
var curves = this._curves = this._curves || new Array(length);
|
var curves = this._curves = this._curves || new Array(length);
|
||||||
curves.length = length;
|
curves.length = length;
|
||||||
|
@ -50,6 +50,14 @@ var Path = this.Path = PathItem.extend({
|
||||||
return curves;
|
return curves;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
getClosed: function() {
|
||||||
|
return this._closed;
|
||||||
|
},
|
||||||
|
|
||||||
|
setClosed: function(closed) {
|
||||||
|
this._closed = closed;
|
||||||
|
},
|
||||||
|
|
||||||
getFirstSegment: function() {
|
getFirstSegment: function() {
|
||||||
return this._segments[0];
|
return this._segments[0];
|
||||||
},
|
},
|
||||||
|
@ -198,7 +206,7 @@ var Path = this.Path = PathItem.extend({
|
||||||
if (last1._point.equals(first1._point)) {
|
if (last1._point.equals(first1._point)) {
|
||||||
first1.setHandleIn(last1._handleIn);
|
first1.setHandleIn(last1._handleIn);
|
||||||
last1.remove();
|
last1.remove();
|
||||||
this.closed = true;
|
this.setClosed(true);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -359,7 +367,7 @@ var Path = this.Path = PathItem.extend({
|
||||||
outX = handleOut._x + x;
|
outX = handleOut._x + x;
|
||||||
outY = handleOut._y + y;
|
outY = handleOut._y + y;
|
||||||
}
|
}
|
||||||
if (this.closed && length > 1) {
|
if (this._closed && length > 1) {
|
||||||
var segment = segments[0],
|
var segment = segments[0],
|
||||||
point = segment._point,
|
point = segment._point,
|
||||||
x = point._x,
|
x = point._x,
|
||||||
|
@ -495,7 +503,7 @@ var Path = this.Path = PathItem.extend({
|
||||||
if (size <= 2)
|
if (size <= 2)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (this.closed) {
|
if (this._closed) {
|
||||||
// Overlap up to 4 points since averaging beziers affect the 4
|
// Overlap up to 4 points since averaging beziers affect the 4
|
||||||
// neighboring points
|
// neighboring points
|
||||||
overlap = Math.min(size, 4);
|
overlap = Math.min(size, 4);
|
||||||
|
@ -506,7 +514,7 @@ var Path = this.Path = PathItem.extend({
|
||||||
var knots = [];
|
var knots = [];
|
||||||
for (var i = 0; i < size; i++)
|
for (var i = 0; i < size; i++)
|
||||||
knots[i + overlap] = segments[i]._point;
|
knots[i + overlap] = segments[i]._point;
|
||||||
if (this.closed) {
|
if (this._closed) {
|
||||||
// If we're averaging, add the 4 last points again at the
|
// If we're averaging, add the 4 last points again at the
|
||||||
// beginning, and the 4 first ones at the end.
|
// beginning, and the 4 first ones at the end.
|
||||||
for (var i = 0; i < overlap; i++) {
|
for (var i = 0; i < overlap; i++) {
|
||||||
|
@ -536,7 +544,7 @@ var Path = this.Path = PathItem.extend({
|
||||||
// Get first control points Y-values
|
// Get first control points Y-values
|
||||||
var y = getFirstControlPoints(rhs);
|
var y = getFirstControlPoints(rhs);
|
||||||
|
|
||||||
if (this.closed) {
|
if (this._closed) {
|
||||||
// Do the actual averaging simply by linearly fading between the
|
// Do the actual averaging simply by linearly fading between the
|
||||||
// overlapping values.
|
// overlapping values.
|
||||||
for (var i = 0, j = size; i < overlap; i++, j++) {
|
for (var i = 0, j = size; i < overlap; i++, j++) {
|
||||||
|
@ -571,7 +579,7 @@ var Path = this.Path = PathItem.extend({
|
||||||
(knots[n]._y + y[n - 1]) / 2);
|
(knots[n]._y + y[n - 1]) / 2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (this.closed && handleIn) {
|
if (this._closed && handleIn) {
|
||||||
var segment = this._segments[0];
|
var segment = this._segments[0];
|
||||||
segment.setHandleIn(handleIn.subtract(segment._point));
|
segment.setHandleIn(handleIn.subtract(segment._point));
|
||||||
}
|
}
|
||||||
|
@ -781,7 +789,7 @@ var Path = this.Path = PathItem.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
closePath: function() {
|
closePath: function() {
|
||||||
this.closed = true;
|
this.setClosed(true);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}, new function() { // A dedicated scope for the tricky bounds calculations
|
}, new function() { // A dedicated scope for the tricky bounds calculations
|
||||||
|
@ -878,7 +886,7 @@ var Path = this.Path = PathItem.extend({
|
||||||
}
|
}
|
||||||
for (var i = 1, l = segments.length; i < l; i++)
|
for (var i = 1, l = segments.length; i < l; i++)
|
||||||
processSegment(segments[i]);
|
processSegment(segments[i]);
|
||||||
if (that.closed)
|
if (that._closed)
|
||||||
processSegment(first);
|
processSegment(first);
|
||||||
return Rectangle.create(min[0], min[1],
|
return Rectangle.create(min[0], min[1],
|
||||||
max[0] - min[0], max[1] - min[1]);
|
max[0] - min[0], max[1] - min[1]);
|
||||||
|
@ -954,7 +962,6 @@ var Path = this.Path = PathItem.extend({
|
||||||
miter = this.getMiterLimit() * width / 2,
|
miter = this.getMiterLimit() * width / 2,
|
||||||
segments = this._segments,
|
segments = this._segments,
|
||||||
length = segments.length,
|
length = segments.length,
|
||||||
closed= this.closed,
|
|
||||||
// It seems to be compatible with Ai we need to pass pen padding
|
// It seems to be compatible with Ai we need to pass pen padding
|
||||||
// untransformed to getBounds()
|
// untransformed to getBounds()
|
||||||
bounds = getBounds(this, matrix, getPenPadding(radius));
|
bounds = getBounds(this, matrix, getPenPadding(radius));
|
||||||
|
@ -1034,10 +1041,10 @@ var Path = this.Path = PathItem.extend({
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var i = 1, l = length - (closed ? 0 : 1); i < l; i++) {
|
for (var i = 1, l = length - (this._closed ? 0 : 1); i < l; i++) {
|
||||||
addJoin(segments[i], join);
|
addJoin(segments[i], join);
|
||||||
}
|
}
|
||||||
if (closed) {
|
if (this._closed) {
|
||||||
addJoin(segments[0], join);
|
addJoin(segments[0], join);
|
||||||
} else {
|
} else {
|
||||||
addCap(segments[0], cap, 0);
|
addCap(segments[0], cap, 0);
|
||||||
|
|
|
@ -110,7 +110,7 @@ var Segment = this.Segment = Base.extend({
|
||||||
if (this._path != null) {
|
if (this._path != null) {
|
||||||
var index = this.getIndex();
|
var index = this.getIndex();
|
||||||
// The last segment of an open path belongs to the last curve
|
// The last segment of an open path belongs to the last curve
|
||||||
if (!this._path.closed && index == this._path._segments.length - 1)
|
if (!this._path._closed && index == this._path._segments.length - 1)
|
||||||
index--;
|
index--;
|
||||||
return this._path.getCurves()[index] || null;
|
return this._path.getCurves()[index] || null;
|
||||||
}
|
}
|
||||||
|
@ -120,13 +120,13 @@ var Segment = this.Segment = Base.extend({
|
||||||
getNext: function() {
|
getNext: function() {
|
||||||
var segments = this._path && this._path._segments;
|
var segments = this._path && this._path._segments;
|
||||||
return segments && (segments[this.getIndex() + 1]
|
return segments && (segments[this.getIndex() + 1]
|
||||||
|| this._path.closed && segments[0]) || null;
|
|| this._path._closed && segments[0]) || null;
|
||||||
},
|
},
|
||||||
|
|
||||||
getPrevious: function() {
|
getPrevious: function() {
|
||||||
var segments = this._path && this._path._segments;
|
var segments = this._path && this._path._segments;
|
||||||
return segments && (segments[this.getIndex() - 1]
|
return segments && (segments[this.getIndex() - 1]
|
||||||
|| this._path.closed && segments[segments.length - 1]) || null;
|
|| this._path._closed && segments[segments.length - 1]) || null;
|
||||||
},
|
},
|
||||||
|
|
||||||
_isSelected: function(point) {
|
_isSelected: function(point) {
|
||||||
|
|
Loading…
Reference in a new issue