mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-07 13:22:07 -05:00
Clean up getBounds code a bit, by using less local variables and more explicit variable names.
This commit is contained in:
parent
2061cb0517
commit
9a7f72e163
1 changed files with 15 additions and 18 deletions
|
@ -2014,17 +2014,15 @@ var Path = this.Path = PathItem.extend(/** @lends Path# */{
|
||||||
// TODO: Find a way to reuse 'bounds' cache instead?
|
// TODO: Find a way to reuse 'bounds' cache instead?
|
||||||
if (!style._strokeColor || !style._strokeWidth)
|
if (!style._strokeColor || !style._strokeWidth)
|
||||||
return getBounds.call(this, matrix);
|
return getBounds.call(this, matrix);
|
||||||
var width = style._strokeWidth,
|
var radius = style._strokeWidth / 2,
|
||||||
radius = width / 2,
|
|
||||||
padding = getPenPadding(radius, matrix),
|
padding = getPenPadding(radius, matrix),
|
||||||
|
bounds = getBounds.call(this, matrix, padding),
|
||||||
join = style._strokeJoin,
|
join = style._strokeJoin,
|
||||||
cap = style._strokeCap,
|
cap = style._strokeCap,
|
||||||
// miter is relative to width. Divide it by 2 since we're
|
// miter is relative to stroke width. Divide it by 2 since we're
|
||||||
// measuring half the distance below
|
// measuring half the distance below
|
||||||
miter = style._miterLimit * width / 2,
|
miter = style._miterLimit * style._strokeWidth / 2,
|
||||||
segments = this._segments,
|
segments = this._segments;
|
||||||
length = segments.length,
|
|
||||||
bounds = getBounds.call(this, matrix, padding);
|
|
||||||
// Create a rectangle of padding size, used for union with bounds
|
// Create a rectangle of padding size, used for union with bounds
|
||||||
// further down
|
// further down
|
||||||
var joinBounds = new Rectangle(new Size(padding).multiply(2));
|
var joinBounds = new Rectangle(new Size(padding).multiply(2));
|
||||||
|
@ -2094,14 +2092,13 @@ var Path = this.Path = PathItem.extend(/** @lends Path# */{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var i = 1, l = length - (this._closed ? 0 : 1); i < l; i++) {
|
for (var i = 1, l = segments.length - (this._closed ? 0 : 1); i < l; i++)
|
||||||
addJoin(segments[i], join);
|
addJoin(segments[i], join);
|
||||||
}
|
|
||||||
if (this._closed) {
|
if (this._closed) {
|
||||||
addJoin(segments[0], join);
|
addJoin(segments[0], join);
|
||||||
} else {
|
} else {
|
||||||
addCap(segments[0], cap, 0);
|
addCap(segments[0], cap, 0);
|
||||||
addCap(segments[length - 1], cap, 1);
|
addCap(segments[segments.length - 1], cap, 1);
|
||||||
}
|
}
|
||||||
return bounds;
|
return bounds;
|
||||||
}
|
}
|
||||||
|
@ -2109,20 +2106,20 @@ var Path = this.Path = PathItem.extend(/** @lends Path# */{
|
||||||
/**
|
/**
|
||||||
* Returns the bounding rectangle of the item including handles.
|
* Returns the bounding rectangle of the item including handles.
|
||||||
*/
|
*/
|
||||||
function getHandleBounds(matrix, stroke, join) {
|
function getHandleBounds(matrix, strokePadding, joinPadding) {
|
||||||
var coords = new Array(6),
|
var coords = new Array(6),
|
||||||
x1 = Infinity,
|
x1 = Infinity,
|
||||||
x2 = -x1,
|
x2 = -x1,
|
||||||
y1 = x1,
|
y1 = x1,
|
||||||
y2 = x2;
|
y2 = x2;
|
||||||
stroke = stroke / 2 || 0; // Stroke padding
|
strokePadding = strokePadding / 2 || 0;
|
||||||
join = join / 2 || 0; // Join padding, for miterLimit
|
joinPadding = joinPadding / 2 || 0;
|
||||||
for (var i = 0, l = this._segments.length; i < l; i++) {
|
for (var i = 0, l = this._segments.length; i < l; i++) {
|
||||||
var segment = this._segments[i];
|
var segment = this._segments[i];
|
||||||
segment._transformCoordinates(matrix, coords, false);
|
segment._transformCoordinates(matrix, coords, false);
|
||||||
for (var j = 0; j < 6; j += 2) {
|
for (var j = 0; j < 6; j += 2) {
|
||||||
// Use different padding for points or handles
|
// Use different padding for points or handles
|
||||||
var padding = j == 0 ? join : stroke,
|
var padding = j == 0 ? joinPadding : strokePadding,
|
||||||
x = coords[j],
|
x = coords[j],
|
||||||
y = coords[j + 1],
|
y = coords[j + 1],
|
||||||
xn = x - padding,
|
xn = x - padding,
|
||||||
|
@ -2147,11 +2144,11 @@ var Path = this.Path = PathItem.extend(/** @lends Path# */{
|
||||||
// joins. Hanlde miter joins specially, by passing the largets radius
|
// joins. Hanlde miter joins specially, by passing the largets radius
|
||||||
// possible.
|
// possible.
|
||||||
var style = this._style,
|
var style = this._style,
|
||||||
width = style._strokeColor ? style._strokeWidth : 0;
|
strokeWidth = style._strokeColor ? style._strokeWidth : 0;
|
||||||
return getHandleBounds.call(this, matrix, width,
|
return getHandleBounds.call(this, matrix, strokeWidth,
|
||||||
style._strokeJoin == 'miter'
|
style._strokeJoin == 'miter'
|
||||||
? width * style._miterLimit
|
? strokeWidth * style._miterLimit
|
||||||
: width);
|
: strokeWidth);
|
||||||
}
|
}
|
||||||
|
|
||||||
var get = {
|
var get = {
|
||||||
|
|
Loading…
Reference in a new issue