mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-03 19:45:44 -05:00
Add Size.create(), in analogy to Point.create().
This commit is contained in:
parent
5508e6eab6
commit
dca26949ff
1 changed files with 21 additions and 13 deletions
|
@ -33,31 +33,31 @@ var Size = Base.extend({
|
||||||
|
|
||||||
add: function() {
|
add: function() {
|
||||||
var size = Size.read(arguments);
|
var size = Size.read(arguments);
|
||||||
return new Size(this.width + size.width, this.height + size.height);
|
return Size.create(this.width + size.width, this.height + size.height);
|
||||||
},
|
},
|
||||||
|
|
||||||
subtract: function() {
|
subtract: function() {
|
||||||
var size = Size.read(arguments);
|
var size = Size.read(arguments);
|
||||||
return new Size(this.width - size.width, this.height - size.height);
|
return Size.create(this.width - size.width, this.height - size.height);
|
||||||
},
|
},
|
||||||
|
|
||||||
multiply: function() {
|
multiply: function() {
|
||||||
var size = Size.read(arguments);
|
var size = Size.read(arguments);
|
||||||
return new Size(this.width * size.width, this.height * size.height);
|
return Size.create(this.width * size.width, this.height * size.height);
|
||||||
},
|
},
|
||||||
|
|
||||||
divide: function() {
|
divide: function() {
|
||||||
var size = Size.read(arguments);
|
var size = Size.read(arguments);
|
||||||
return new Size(this.width / size.width, this.height / size.height);
|
return Size.create(this.width / size.width, this.height / size.height);
|
||||||
},
|
},
|
||||||
|
|
||||||
modulo: function() {
|
modulo: function() {
|
||||||
var size = Size.read(arguments);
|
var size = Size.read(arguments);
|
||||||
return new Size(this.width % size.width, this.height % size.height);
|
return Size.create(this.width % size.width, this.height % size.height);
|
||||||
},
|
},
|
||||||
|
|
||||||
negate: function() {
|
negate: function() {
|
||||||
return new Size(-this.width, -this.height);
|
return Size.create(-this.width, -this.height);
|
||||||
},
|
},
|
||||||
|
|
||||||
equals: function() {
|
equals: function() {
|
||||||
|
@ -70,19 +70,19 @@ var Size = Base.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
round: function() {
|
round: function() {
|
||||||
return new Size(Math.round(this.width), Math.round(this.height));
|
return Size.create(Math.round(this.width), Math.round(this.height));
|
||||||
},
|
},
|
||||||
|
|
||||||
ceil: function() {
|
ceil: function() {
|
||||||
return new Size(Math.ceil(this.width), Math.ceil(this.height));
|
return Size.create(Math.ceil(this.width), Math.ceil(this.height));
|
||||||
},
|
},
|
||||||
|
|
||||||
floor: function() {
|
floor: function() {
|
||||||
return new Size(Math.floor(this.width), Math.floor(this.height));
|
return Size.create(Math.floor(this.width), Math.floor(this.height));
|
||||||
},
|
},
|
||||||
|
|
||||||
abs: function() {
|
abs: function() {
|
||||||
return new Size(Math.abs(this.width), Math.abs(this.height));
|
return Size.create(Math.abs(this.width), Math.abs(this.height));
|
||||||
},
|
},
|
||||||
|
|
||||||
dot: function(Size) {
|
dot: function(Size) {
|
||||||
|
@ -94,6 +94,14 @@ var Size = Base.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
statics: {
|
statics: {
|
||||||
|
// See Point.create()
|
||||||
|
create: function(width, height) {
|
||||||
|
var size = new Size(Size.dont);
|
||||||
|
size.width = width;
|
||||||
|
size.height = height;
|
||||||
|
return size;
|
||||||
|
},
|
||||||
|
|
||||||
read: function(args, index, length) {
|
read: function(args, index, length) {
|
||||||
var index = index || 0, length = length || args.length - index;
|
var index = index || 0, length = length || args.length - index;
|
||||||
if (length == 1 && args[index] instanceof Size) {
|
if (length == 1 && args[index] instanceof Size) {
|
||||||
|
@ -108,19 +116,19 @@ var Size = Base.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
min: function(Size1, Size2) {
|
min: function(Size1, Size2) {
|
||||||
return new Size(
|
return Size.create(
|
||||||
Math.min(Size1.width, Size2.width),
|
Math.min(Size1.width, Size2.width),
|
||||||
Math.min(Size1.height, Size2.height));
|
Math.min(Size1.height, Size2.height));
|
||||||
},
|
},
|
||||||
|
|
||||||
max: function(Size1, Size2) {
|
max: function(Size1, Size2) {
|
||||||
return new Size(
|
return Size.create(
|
||||||
Math.max(Size1.width, Size2.width),
|
Math.max(Size1.width, Size2.width),
|
||||||
Math.max(Size1.height, Size2.height));
|
Math.max(Size1.height, Size2.height));
|
||||||
},
|
},
|
||||||
|
|
||||||
random: function() {
|
random: function() {
|
||||||
return new Size(Math.random(), Math.random());
|
return Size.create(Math.random(), Math.random());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue