mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-20 22:39:50 -05:00
Remove redundant Rectangle#transformBounds() and merge its code with less optimised Matrix#transformBounds().
This commit is contained in:
parent
aaceeb4f54
commit
fc547793fa
3 changed files with 19 additions and 41 deletions
|
@ -293,6 +293,7 @@ var Matrix = this.Matrix = Base.extend({
|
|||
*/
|
||||
transform: function(/* point | */ src, srcOff, dst, dstOff, numPts) {
|
||||
return arguments.length < 5
|
||||
// TODO: Check for rectangle and use _tranformBounds?
|
||||
? this._transformPoint(Point.read(arguments))
|
||||
: this._transformCoordinates(src, srcOff, dst, dstOff, numPts);
|
||||
},
|
||||
|
@ -325,27 +326,25 @@ var Matrix = this.Matrix = Base.extend({
|
|||
return dst;
|
||||
},
|
||||
|
||||
transformBounds: function(bounds) {
|
||||
// Rotate the corner points of the image rectangle do find the
|
||||
// extremas that define our raster's bounds, and update them straight
|
||||
// away
|
||||
var tl = bounds.getTopLeft(),
|
||||
tr = bounds.getTopRight(),
|
||||
br = bounds.getBottomRight(),
|
||||
bl = bounds.getBottomLeft(),
|
||||
coords = [ tl.x, tl.y, tr.x, tr.y, br.x, br.y, bl.x, bl.y ];
|
||||
this._transformCoordinates(coords, 0, coords, 0, 4);
|
||||
// Loop through all x and y coordinates and update min and max values.
|
||||
// Start with the first coordinate pair for both (coords.slice(0, 2)).
|
||||
var min = coords.slice(0, 2), max = min.slice(0);
|
||||
/**
|
||||
* Returns the 'transformed' bounds rectangle by transforming each corner
|
||||
* point and finding the new bounding box to these points. This is not
|
||||
* really the transformed reactangle!
|
||||
*/
|
||||
_transformBounds: function(bounds) {
|
||||
var coords = bounds.transformCornerCoordinates(this),
|
||||
min = coords.slice(0, 2),
|
||||
max = coords.slice(0);
|
||||
for (var i = 2; i < 8; i++) {
|
||||
var c = coords[i], j = i & 1; // i & 1 == i % 2 == i modulo 2
|
||||
if (c < min[j])
|
||||
min[j] = c;
|
||||
else if (c > max[j])
|
||||
max[j] = c;
|
||||
var val = coords[i],
|
||||
j = i & 1;
|
||||
if (val < min[j])
|
||||
min[j] = val;
|
||||
else if (val > max[j])
|
||||
max[j] = val;
|
||||
}
|
||||
return new Rectangle(min[0], min[1], max[0] - min[0], max[1] - min[1]);
|
||||
return Rectangle.create(min[0], min[1],
|
||||
max[0] - min[0], max[1] - min[1]);
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
|
@ -243,27 +243,6 @@ var Rectangle = this.Rectangle = Base.extend({
|
|||
: coords;
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns the 'transformed' bounds rectangle by transforming each corner
|
||||
* point and finding the new bounding box to these points. This is not
|
||||
* really the transformed reactangle!
|
||||
*/
|
||||
transformBounds: function(matrix) {
|
||||
var coords = this.transformCornerCoordinates(matrix),
|
||||
min = coords.slice(0, 2),
|
||||
max = coords.slice(0);
|
||||
for (var i = 2; i < 8; i++) {
|
||||
var val = coords[i],
|
||||
j = i & 1;
|
||||
if (val < min[i])
|
||||
min[i] = val;
|
||||
else if (val > max[i])
|
||||
max[i] = val;
|
||||
}
|
||||
return Rectangle.create(min[0], min[1],
|
||||
max[0] - min[0], max[1] - min[1]);
|
||||
},
|
||||
|
||||
statics: {
|
||||
// See Point.create()
|
||||
create: function(x, y, width, height) {
|
||||
|
|
|
@ -191,7 +191,7 @@ var Raster = this.Raster = Item.extend({
|
|||
|
||||
getBounds: function() {
|
||||
if (!this._bounds) {
|
||||
this._bounds = this.matrix.transformBounds(
|
||||
this._bounds = this.matrix._transformBounds(
|
||||
new Rectangle(this._size).setCenter(0, 0));
|
||||
}
|
||||
return this._bounds;
|
||||
|
|
Loading…
Reference in a new issue