mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-01 02:38:43 -05:00
Make PathItem#getBounds() work for closed paths too.
This commit is contained in:
parent
d59d514a55
commit
71d1ff3cb3
1 changed files with 8 additions and 5 deletions
|
@ -68,10 +68,10 @@ PathItem = Item.extend(new function() {
|
||||||
|
|
||||||
getBounds: function() {
|
getBounds: function() {
|
||||||
var segments = this._segments;
|
var segments = this._segments;
|
||||||
var prev = segments[0];
|
var first = segments[0];
|
||||||
if (!prev)
|
if (!first)
|
||||||
return null;
|
return null;
|
||||||
var p0 = prev.point;
|
var p0 = first.point, prev = first;
|
||||||
var min = {
|
var min = {
|
||||||
x: p0.x,
|
x: p0.x,
|
||||||
y: p0.y
|
y: p0.y
|
||||||
|
@ -81,8 +81,7 @@ PathItem = Item.extend(new function() {
|
||||||
y: p0.y
|
y: p0.y
|
||||||
}
|
}
|
||||||
var coords = ['x', 'y'];
|
var coords = ['x', 'y'];
|
||||||
for (var i = 1, l = segments.length; i < l; i++) {
|
function processSegment(segment) {
|
||||||
var segment = segments[i];
|
|
||||||
var p1 = p0.add(prev.handleOut);
|
var p1 = p0.add(prev.handleOut);
|
||||||
var p3 = segment.point;
|
var p3 = segment.point;
|
||||||
var p2 = p3.add(segment.handleIn);
|
var p2 = p3.add(segment.handleIn);
|
||||||
|
@ -132,6 +131,10 @@ PathItem = Item.extend(new function() {
|
||||||
p0 = p3;
|
p0 = p3;
|
||||||
prev = segment;
|
prev = segment;
|
||||||
}
|
}
|
||||||
|
for (var i = 1, l = segments.length; i < l; i++)
|
||||||
|
processSegment(segments[i]);
|
||||||
|
if (this.closed)
|
||||||
|
processSegment(first);
|
||||||
return new Rectangle(min.x, min.y, max.x - min.x , max.y - min.y);
|
return new Rectangle(min.x, min.y, max.x - min.x , max.y - min.y);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue