mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-06 04:42:15 -05:00
Use Matrix#transformBounds() in DocumentView#getBounds().
This commit is contained in:
parent
4908ba5edf
commit
083a9864f0
1 changed files with 8 additions and 30 deletions
|
@ -41,7 +41,15 @@ var DocumentView = this.DocumentView = Base.extend({
|
||||||
this.transform(mx);
|
this.transform(mx);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
transform: function(matrix, flags) {
|
||||||
|
this.matrix.preConcatenate(matrix);
|
||||||
|
this._bounds = null;
|
||||||
|
},
|
||||||
|
|
||||||
getBounds: function() {
|
getBounds: function() {
|
||||||
|
if (!this._bounds) {
|
||||||
|
this._bounds = this.matrix.transformBounds(this.document.bounds);
|
||||||
|
}
|
||||||
return this._bounds;
|
return this._bounds;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -63,35 +71,5 @@ var DocumentView = this.DocumentView = Base.extend({
|
||||||
viewToArtwork: function(point) {
|
viewToArtwork: function(point) {
|
||||||
// TODO: cache the inverse matrix:
|
// TODO: cache the inverse matrix:
|
||||||
return this.matrix.createInverse().transform(point);
|
return this.matrix.createInverse().transform(point);
|
||||||
},
|
|
||||||
|
|
||||||
// TODO: inherit this code somehow?
|
|
||||||
transform: function(matrix, flags) {
|
|
||||||
var width = this.document.bounds.width;
|
|
||||||
var height = this.document.bounds.height;
|
|
||||||
var x = width * -0.5;
|
|
||||||
var y = height * -0.5;
|
|
||||||
var coords = [
|
|
||||||
x, y,
|
|
||||||
x + width, y,
|
|
||||||
x + width, y + height,
|
|
||||||
x, y + height];
|
|
||||||
this.matrix.preConcatenate(matrix);
|
|
||||||
this.matrix.createInverse().transform(coords, 0, coords, 0, 4);
|
|
||||||
var xMin = coords[0], xMax = coords[0];
|
|
||||||
var yMin = coords[1], yMax = coords[1];
|
|
||||||
for (var i = 2; i < 8; i += 2) {
|
|
||||||
var x = coords[i];
|
|
||||||
var y = coords[i + 1];
|
|
||||||
xMin = Math.min(x, xMin);
|
|
||||||
xMax = Math.max(x, xMax);
|
|
||||||
yMin = Math.min(y, yMin);
|
|
||||||
yMax = Math.max(y, yMax);
|
|
||||||
};
|
|
||||||
var bounds = this._bounds;
|
|
||||||
bounds.x = xMin;
|
|
||||||
bounds.y = yMin;
|
|
||||||
bounds.width = xMax - xMin;
|
|
||||||
bounds.height = yMax - yMin;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue