mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2024-12-29 01:12:39 -05:00
Fix calculation of internal bounds with children and applyMatrix = false
Closes #1250
This commit is contained in:
parent
65da4fe3ed
commit
db4deb244f
2 changed files with 27 additions and 7 deletions
|
@ -893,14 +893,14 @@ new function() { // Injection scope for various item event handlers
|
|||
* Private method that deals with the calling of _getBounds, recursive
|
||||
* matrix concatenation and handles all the complicated caching mechanisms.
|
||||
*/
|
||||
_getCachedBounds: function(matrix, options) {
|
||||
_getCachedBounds: function(matrix, options, noInternal) {
|
||||
// See if we can cache these bounds. We only cache the bounds
|
||||
// transformed with the internally stored _matrix, (the default if no
|
||||
// matrix is passed).
|
||||
matrix = matrix && matrix._orNullIfIdentity();
|
||||
// Do not transform by the internal matrix for internal, untransformed
|
||||
// bounds.
|
||||
var internal = options.internal,
|
||||
var internal = options.internal && !noInternal,
|
||||
cacheItem = options.cacheItem,
|
||||
_matrix = internal ? null : this._matrix._orNullIfIdentity(),
|
||||
// Create a key for caching, reflecting all bounds options.
|
||||
|
@ -923,7 +923,7 @@ new function() { // Injection scope for various item event handlers
|
|||
var cached = this._bounds[cacheKey] = {
|
||||
rect: bounds.clone(),
|
||||
// Mark as internal, so Item#transform() won't transform it
|
||||
internal: options.internal
|
||||
internal: internal
|
||||
};
|
||||
}
|
||||
return bounds;
|
||||
|
@ -1010,8 +1010,11 @@ new function() { // Injection scope for various item event handlers
|
|||
for (var i = 0, l = items.length; i < l; i++) {
|
||||
var item = items[i];
|
||||
if (item._visible && !item.isEmpty()) {
|
||||
// Pass true for noInternal, since even when getting
|
||||
// internal bounds for this item, we need to apply the
|
||||
// matrices to its children.
|
||||
var rect = item._getCachedBounds(
|
||||
matrix && matrix.appended(item._matrix), options);
|
||||
matrix && matrix.appended(item._matrix), options, true);
|
||||
x1 = Math.min(rect.x, x1);
|
||||
y1 = Math.min(rect.y, y1);
|
||||
x2 = Math.max(rect.x + rect.width, x2);
|
||||
|
|
|
@ -741,8 +741,7 @@ test('item.visible and item.parents.bounds (#1248)', function() {
|
|||
var item = new Path.Rectangle({
|
||||
point: [0, 0],
|
||||
size: [50, 100],
|
||||
fillColor: 'red',
|
||||
visible: false,
|
||||
visible: false
|
||||
});
|
||||
equals(item.bounds, new Rectangle(0, 0, 50, 100), 'item.bounds');
|
||||
equals(item.parent.bounds, new Rectangle(0, 0, 0, 0),
|
||||
|
@ -750,4 +749,22 @@ test('item.visible and item.parents.bounds (#1248)', function() {
|
|||
item.visible = true;
|
||||
equals(item.parent.bounds, item.bounds,
|
||||
'item.parent.bounds with item.visible = true');
|
||||
})
|
||||
});
|
||||
|
||||
test('group.internalBounds with child and child.applyMatrix = false (#1250)', function() {
|
||||
var item1 = Shape.Rectangle({
|
||||
point: [100, 100],
|
||||
size: [200, 200]
|
||||
});
|
||||
var item2 = new Path.Rectangle({
|
||||
point: [0, 0],
|
||||
size: [100, 100]
|
||||
});
|
||||
var group = new Group([item1, item2]);
|
||||
equals(item1.bounds, new Rectangle(100, 100, 200, 200), 'item.bounds');
|
||||
equals(group.internalBounds, new Rectangle(0, 0, 300, 300),
|
||||
'group.internalBounds before scaling item1');
|
||||
item1.scale(0.5);
|
||||
equals(group.internalBounds, new Rectangle(0, 0, 250, 250),
|
||||
'group.internalBounds after scaling item1');
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue