mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-08-28 22:08:54 -04:00
Imrove Point, Size and Rectangle constructors.
This commit is contained in:
parent
fd0d409d9e
commit
cb2e4aaa04
3 changed files with 44 additions and 47 deletions
|
@ -6,25 +6,24 @@
|
|||
var Point = this.Point = Base.extend({
|
||||
beans: true,
|
||||
|
||||
initialize: function() {
|
||||
initialize: function(arg0, arg1) {
|
||||
if (arguments.length == 2) {
|
||||
this.x = arguments[0];
|
||||
this.y = arguments[1];
|
||||
this.x = arg0;
|
||||
this.y = arg1;
|
||||
} else if (arguments.length == 1) {
|
||||
var arg = arguments[0];
|
||||
if (arg == null) {
|
||||
if (arg0 == null) {
|
||||
this.x = this.y = 0;
|
||||
} else if (arg.x !== undefined) {
|
||||
this.x = arg.x;
|
||||
this.y = arg.y;
|
||||
} else if (arg.width !== undefined) {
|
||||
this.x = arg.width;
|
||||
this.y = arg.height;
|
||||
} else if (Array.isArray(arg)) {
|
||||
this.x = arg[0];
|
||||
this.y = arg.length > 1 ? arg[1] : arg[0];
|
||||
} else if (typeof arg === 'number') {
|
||||
this.x = this.y = arg;
|
||||
} else if (arg0.x !== undefined) {
|
||||
this.x = arg0.x;
|
||||
this.y = arg0.y;
|
||||
} else if (arg0.width !== undefined) {
|
||||
this.x = arg0.width;
|
||||
this.y = arg0.height;
|
||||
} else if (Array.isArray(arg0)) {
|
||||
this.x = arg0[0];
|
||||
this.y = arg0.length > 1 ? arg0[1] : arg0[0];
|
||||
} else if (typeof arg0 === 'number') {
|
||||
this.x = this.y = arg0;
|
||||
} else {
|
||||
this.x = this.y = 0;
|
||||
}
|
||||
|
|
|
@ -1,19 +1,18 @@
|
|||
var Rectangle = this.Rectangle = Base.extend({
|
||||
beans: true,
|
||||
|
||||
initialize: function() {
|
||||
initialize: function(arg0, arg1, arg2, arg3) {
|
||||
if (arguments.length == 1) {
|
||||
var rect = arguments[0];
|
||||
// Use 0 as defaults, in case we're reading from a Point or Size
|
||||
this.x = rect.x || 0;
|
||||
this.y = rect.y || 0;
|
||||
this.width = rect.width || 0;
|
||||
this.height = rect.height || 0;
|
||||
this.x = arg0.x || 0;
|
||||
this.y = arg0.y || 0;
|
||||
this.width = arg0.width || 0;
|
||||
this.height = arg0.height || 0;
|
||||
} else if (arguments.length == 2) {
|
||||
if (arguments[1].x !== undefined) {
|
||||
if (arg1.x !== undefined) {
|
||||
// new Rectangle(point1, point2)
|
||||
var point1 = new Point(arguments[0]);
|
||||
var point2 = new Point(arguments[1]);
|
||||
var point1 = Point.read(arguments, 0, 1);
|
||||
var point2 = Point.read(arguments, 1, 1);
|
||||
this.x = point1.x;
|
||||
this.y = point1.y;
|
||||
this.width = point2.x - point1.x;
|
||||
|
@ -28,8 +27,8 @@ var Rectangle = this.Rectangle = Base.extend({
|
|||
}
|
||||
} else {
|
||||
// new Rectangle(point, size)
|
||||
var point = new Point(arguments[0]);
|
||||
var size = new Size(arguments[1]);
|
||||
var point = Point.read(arguments, 0, 1);
|
||||
var size = Size.read(arguments, 1, 1);
|
||||
this.x = point.x;
|
||||
this.y = point.y;
|
||||
this.width = size.width;
|
||||
|
@ -37,10 +36,10 @@ var Rectangle = this.Rectangle = Base.extend({
|
|||
}
|
||||
} else if (arguments.length == 4) {
|
||||
// new Rectangle(x, y, width, height)
|
||||
this.x = arguments[0];
|
||||
this.y = arguments[1];
|
||||
this.width = arguments[2];
|
||||
this.height = arguments[3];
|
||||
this.x = arg0;
|
||||
this.y = arg1;
|
||||
this.width = arg2;
|
||||
this.height = arg3;
|
||||
} else {
|
||||
// new Rectangle()
|
||||
this.x = this.y = this.width = this.height = 0;
|
||||
|
|
|
@ -1,23 +1,22 @@
|
|||
var Size = this.Size = Base.extend({
|
||||
initialize: function() {
|
||||
initialize: function(arg0, arg1) {
|
||||
if (arguments.length == 2) {
|
||||
this.width = arguments[0];
|
||||
this.height = arguments[1];
|
||||
this.width = arg0;
|
||||
this.height = arg1;
|
||||
} else if (arguments.length == 1) {
|
||||
var arg = arguments[0];
|
||||
if (arg == null) {
|
||||
if (arg0 == null) {
|
||||
this.width = this.height = 0;
|
||||
} else if (arg.width !== undefined) {
|
||||
this.width = arg.width;
|
||||
this.height = arg.height;
|
||||
} else if (arg.x !== undefined) {
|
||||
this.width = arg.x;
|
||||
this.height = arg.y;
|
||||
} else if (Array.isArray(arg)) {
|
||||
this.width = arg[0];
|
||||
this.height = arg.length > 1 ? arg[1] : arg[0];
|
||||
} else if (typeof arg === 'number') {
|
||||
this.width = this.height = arg;
|
||||
} else if (arg0.width !== undefined) {
|
||||
this.width = arg0.width;
|
||||
this.height = arg0.height;
|
||||
} else if (arg0.x !== undefined) {
|
||||
this.width = arg0.x;
|
||||
this.height = arg0.y;
|
||||
} else if (Array.isArray(arg0)) {
|
||||
this.width = arg0[0];
|
||||
this.height = arg0.length > 1 ? arg0[1] : arg0[0];
|
||||
} else if (typeof arg0 === 'number') {
|
||||
this.width = this.height = arg0;
|
||||
} else {
|
||||
this.width = this.height = 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue