mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2024-12-29 09:22:22 -05:00
Clean up code from #856 a bit.
This commit is contained in:
parent
d67796f655
commit
f34afbc19a
3 changed files with 13 additions and 9 deletions
|
@ -3940,6 +3940,7 @@ var Item = Base.extend(Emitter, /** @lends Item# */{
|
|||
// Get the transformation matrix for non-scaling strokes.
|
||||
var strokeMatrix = parentStrokeMatrix
|
||||
? parentStrokeMatrix.chain(matrix)
|
||||
// pass `true` for dontMerge
|
||||
: !this.getStrokeScaling(true) && getViewMatrix(globalMatrix),
|
||||
// If we're drawing into a separate canvas and a clipItem is defined
|
||||
// for the current rendering loop, we need to draw the clip item
|
||||
|
|
|
@ -272,14 +272,17 @@ var Shape = Item.extend(/** @lends Shape# */{
|
|||
|
||||
_getBounds: function(getter, matrix) {
|
||||
var rect = new Rectangle(this._size).setCenter(0, 0),
|
||||
expandStrokeWidth = getter !== 'getBounds' && this.hasStroke()
|
||||
&& this.getStrokeWidth();
|
||||
if (expandStrokeWidth && this.getStrokeScaling(true))
|
||||
rect = rect.expand(expandStrokeWidth);
|
||||
strokeWidth = getter === 'getStrokeBounds' && this.hasStroke()
|
||||
&& this.getStrokeWidth(),
|
||||
scaling = strokeWidth && this.getStrokeScaling();
|
||||
// If we're getting the strokeBounds, include the stroke width before
|
||||
// or after transforming the rect, based on strokeScaling.
|
||||
if (strokeWidth && scaling)
|
||||
rect = rect.expand(strokeWidth);
|
||||
if (matrix)
|
||||
rect = matrix._transformBounds(rect);
|
||||
if (expandStrokeWidth && !this.getStrokeScaling(true))
|
||||
rect = rect.expand(expandStrokeWidth);
|
||||
if (strokeWidth && !scaling)
|
||||
rect = rect.expand(strokeWidth);
|
||||
return rect;
|
||||
}
|
||||
},
|
||||
|
|
|
@ -77,7 +77,7 @@ test('path.bounds when contained in a transformed group', function() {
|
|||
equals(path.bounds, new Rectangle(110, 110, 50, 50), 'path.bounds after group translation');
|
||||
});
|
||||
|
||||
test('shape.strokeBounds when scale with strokeScaling is false', function(){
|
||||
test('shape.strokeBounds when scaled with strokeScaling set to false', function(){
|
||||
var shape = new Shape.Rectangle({
|
||||
point: [5, 5],
|
||||
size: [20, 20],
|
||||
|
@ -85,9 +85,9 @@ test('shape.strokeBounds when scale with strokeScaling is false', function(){
|
|||
strokeColor: 'black',
|
||||
strokeWidth: 10
|
||||
});
|
||||
equals(shape.getStrokeBounds(), new Rectangle(0, 0, 30, 30), 'shape.strokeBounds before scaling');
|
||||
equals(shape.strokeBounds, new Rectangle(0, 0, 30, 30), 'shape.strokeBounds before scaling');
|
||||
shape.scale(2, 2, [5, 5]);
|
||||
equals(shape.getStrokeBounds(), new Rectangle(0, 0, 50, 50), 'shape.strokeBounds after scaling');
|
||||
equals(shape.strokeBounds, new Rectangle(0, 0, 50, 50), 'shape.strokeBounds after scaling');
|
||||
});
|
||||
|
||||
test('text.bounds', function() {
|
||||
|
|
Loading…
Reference in a new issue