mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-07-07 10:14:02 -04:00
Rearrange method sequence in basic types.
This commit is contained in:
parent
3f634f6420
commit
a0066b61c3
4 changed files with 120 additions and 114 deletions
src/basic
|
@ -70,18 +70,6 @@ var Matrix = this.Matrix = Base.extend(/** @lends Matrix# */{
|
|||
throw new Error('Unsupported matrix parameters');
|
||||
},
|
||||
|
||||
_serialize: function(options) {
|
||||
return Base.serialize(this.getValues(), options);
|
||||
},
|
||||
|
||||
/**
|
||||
* @return {Matrix} A copy of this transform.
|
||||
*/
|
||||
clone: function() {
|
||||
return Matrix.create(this._a, this._c, this._b, this._d,
|
||||
this._tx, this._ty);
|
||||
},
|
||||
|
||||
/**
|
||||
* Sets this transform to the matrix specified by the 6 values.
|
||||
*
|
||||
|
@ -103,6 +91,40 @@ var Matrix = this.Matrix = Base.extend(/** @lends Matrix# */{
|
|||
return this;
|
||||
},
|
||||
|
||||
_serialize: function(options) {
|
||||
return Base.serialize(this.getValues(), options);
|
||||
},
|
||||
|
||||
/**
|
||||
* @return {Matrix} A copy of this transform.
|
||||
*/
|
||||
clone: function() {
|
||||
return Matrix.create(this._a, this._c, this._b, this._d,
|
||||
this._tx, this._ty);
|
||||
},
|
||||
|
||||
/**
|
||||
* Checks whether the two matrices describe the same transformation.
|
||||
*
|
||||
* @param {Matrix} matrix the matrix to compare this matrix to
|
||||
* @return {Boolean} {@true if the matrices are equal}
|
||||
*/
|
||||
equals: function(mx) {
|
||||
return mx && this._a == mx._a && this._b == mx._b && this._c == mx._c
|
||||
&& this._d == mx._d && this._tx == mx._tx && this._ty == mx._ty;
|
||||
},
|
||||
|
||||
/**
|
||||
* @return {String} A string representation of this transform.
|
||||
*/
|
||||
toString: function() {
|
||||
var format = Format.number;
|
||||
return '[[' + [format(this._a), format(this._b),
|
||||
format(this._tx)].join(', ') + '], ['
|
||||
+ [format(this._c), format(this._d),
|
||||
format(this._ty)].join(', ') + ']]';
|
||||
},
|
||||
|
||||
/**
|
||||
* "Resets" the matrix by setting its values to the ones of the identity
|
||||
* matrix that results in no transformation.
|
||||
|
@ -255,28 +277,6 @@ var Matrix = this.Matrix = Base.extend(/** @lends Matrix# */{
|
|||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* @return {String} A string representation of this transform.
|
||||
*/
|
||||
toString: function() {
|
||||
var format = Format.number;
|
||||
return '[[' + [format(this._a), format(this._b),
|
||||
format(this._tx)].join(', ') + '], ['
|
||||
+ [format(this._c), format(this._d),
|
||||
format(this._ty)].join(', ') + ']]';
|
||||
},
|
||||
|
||||
/**
|
||||
* Checks whether the two matrices describe the same transformation.
|
||||
*
|
||||
* @param {Matrix} matrix the matrix to compare this matrix to
|
||||
* @return {Boolean} {@true if the matrices are equal}
|
||||
*/
|
||||
equals: function(mx) {
|
||||
return mx && this._a == mx._a && this._b == mx._b && this._c == mx._c
|
||||
&& this._d == mx._d && this._tx == mx._tx && this._ty == mx._ty;
|
||||
},
|
||||
|
||||
/**
|
||||
* @return {Boolean} Whether this transform is the identity transform
|
||||
*/
|
||||
|
|
|
@ -164,15 +164,6 @@ var Point = this.Point = Base.extend(/** @lends Point# */{
|
|||
}
|
||||
},
|
||||
|
||||
_serialize: function(options) {
|
||||
var format = Format.number;
|
||||
// For speed reasons, we directly call Format.number() here with
|
||||
// precision, instead of converting array through Base.serialize() which
|
||||
// makes a copy.
|
||||
return [format(this.x, options.precision),
|
||||
format(this.y, options.precision)];
|
||||
},
|
||||
|
||||
/**
|
||||
* The x coordinate of the point
|
||||
*
|
||||
|
@ -193,6 +184,24 @@ var Point = this.Point = Base.extend(/** @lends Point# */{
|
|||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* Checks whether the coordinates of the point are equal to that of the
|
||||
* supplied point.
|
||||
*
|
||||
* @param {Point} point
|
||||
* @return {Boolean} {@true if the points are equal}
|
||||
*
|
||||
* @example
|
||||
* var point = new Point(5, 10);
|
||||
* console.log(point == new Point(5, 10)); // true
|
||||
* console.log(point == new Point(1, 1)); // false
|
||||
* console.log(point != new Point(1, 1)); // true
|
||||
*/
|
||||
equals: function(point) {
|
||||
point = Point.read(arguments);
|
||||
return this.x == point.x && this.y == point.y;
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns a copy of the point.
|
||||
*
|
||||
|
@ -218,6 +227,16 @@ var Point = this.Point = Base.extend(/** @lends Point# */{
|
|||
return '{ x: ' + format(this.x) + ', y: ' + format(this.y) + ' }';
|
||||
},
|
||||
|
||||
_serialize: function(options) {
|
||||
var format = Format.number,
|
||||
precision = options.precision;
|
||||
// For speed reasons, we directly call Format.number() here with
|
||||
// precision, instead of converting array through Base.serialize() which
|
||||
// makes a copy.
|
||||
return [format(this.x, precision),
|
||||
format(this.y, precision)];
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns the addition of the supplied value to both coordinates of
|
||||
* the point as a new point.
|
||||
|
@ -639,24 +658,6 @@ var Point = this.Point = Base.extend(/** @lends Point# */{
|
|||
return center ? point.add(center) : point;
|
||||
},
|
||||
|
||||
/**
|
||||
* Checks whether the coordinates of the point are equal to that of the
|
||||
* supplied point.
|
||||
*
|
||||
* @param {Point} point
|
||||
* @return {Boolean} {@true if the points are equal}
|
||||
*
|
||||
* @example
|
||||
* var point = new Point(5, 10);
|
||||
* console.log(point == new Point(5, 10)); // true
|
||||
* console.log(point == new Point(1, 1)); // false
|
||||
* console.log(point != new Point(1, 1)); // true
|
||||
*/
|
||||
equals: function(point) {
|
||||
point = Point.read(arguments);
|
||||
return this.x == point.x && this.y == point.y;
|
||||
},
|
||||
|
||||
/**
|
||||
* {@grouptitle Tests}
|
||||
*
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
* rectangular path, it is not an item.
|
||||
*/
|
||||
var Rectangle = this.Rectangle = Base.extend(/** @lends Rectangle# */{
|
||||
_type: 'Rectangle',
|
||||
// Tell Base.read that the Rectangle constructor supporst reading with index
|
||||
_readIndex: true,
|
||||
|
||||
|
@ -173,7 +174,7 @@ var Rectangle = this.Rectangle = Base.extend(/** @lends Rectangle# */{
|
|||
* @type Number
|
||||
*/
|
||||
|
||||
// DOCS: why does jsdocs document this function, when there are no comments?
|
||||
// DOCS: Why does jsdocs document this function, when there are no comments?
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
|
@ -186,6 +187,36 @@ var Rectangle = this.Rectangle = Base.extend(/** @lends Rectangle# */{
|
|||
},
|
||||
|
||||
/**
|
||||
* Returns a copy of the rectangle.
|
||||
*/
|
||||
clone: function() {
|
||||
return Rectangle.create(this.x, this.y, this.width, this.height);
|
||||
},
|
||||
|
||||
/**
|
||||
* Checks whether the coordinates and size of the rectangle are equal to
|
||||
* that of the supplied rectangle.
|
||||
*
|
||||
* @param {Rectangle} rect
|
||||
* @return {Boolean} {@true if the rectangles are equal}
|
||||
*/
|
||||
equals: function(rect) {
|
||||
rect = Rectangle.read(arguments);
|
||||
return this.x == rect.x && this.y == rect.y
|
||||
&& this.width == rect.width && this.height == rect.height;
|
||||
},
|
||||
|
||||
/**
|
||||
* @return {String} A string representation of this rectangle.
|
||||
*/
|
||||
toString: function() {
|
||||
var format = Format.number;
|
||||
return '{ x: ' + format(this.x)
|
||||
+ ', y: ' + format(this.y)
|
||||
+ ', width: ' + format(this.width)
|
||||
+ ', height: ' + format(this.height)
|
||||
+ ' }';
|
||||
},
|
||||
* The top-left point of the rectangle
|
||||
*
|
||||
* @type Point
|
||||
|
@ -393,19 +424,6 @@ var Rectangle = this.Rectangle = Base.extend(/** @lends Rectangle# */{
|
|||
* @type Point
|
||||
*/
|
||||
|
||||
/**
|
||||
* Checks whether the coordinates and size of the rectangle are equal to
|
||||
* that of the supplied rectangle.
|
||||
*
|
||||
* @param {Rectangle} rect
|
||||
* @return {Boolean} {@true if the rectangles are equal}
|
||||
*/
|
||||
equals: function(rect) {
|
||||
rect = Rectangle.read(arguments);
|
||||
return this.x == rect.x && this.y == rect.y
|
||||
&& this.width == rect.width && this.height == rect.height;
|
||||
},
|
||||
|
||||
/**
|
||||
* @return {Boolean} {@true the rectangle is empty}
|
||||
*/
|
||||
|
@ -413,18 +431,6 @@ var Rectangle = this.Rectangle = Base.extend(/** @lends Rectangle# */{
|
|||
return this.width == 0 || this.height == 0;
|
||||
},
|
||||
|
||||
/**
|
||||
* @return {String} A string representation of this rectangle.
|
||||
*/
|
||||
toString: function() {
|
||||
var format = Format.number;
|
||||
return '{ x: ' + format(this.x)
|
||||
+ ', y: ' + format(this.y)
|
||||
+ ', width: ' + format(this.width)
|
||||
+ ', height: ' + format(this.height)
|
||||
+ ' }';
|
||||
},
|
||||
|
||||
/**
|
||||
* {@grouptitle Geometric Tests}
|
||||
*
|
||||
|
|
|
@ -121,15 +121,6 @@ var Size = this.Size = Base.extend(/** @lends Size# */{
|
|||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* @return {String} A string representation of the size.
|
||||
*/
|
||||
toString: function() {
|
||||
var format = Format.number;
|
||||
return '{ width: ' + format(this.width)
|
||||
+ ', height: ' + format(this.height) + ' }';
|
||||
},
|
||||
|
||||
/**
|
||||
* The width of the size
|
||||
*
|
||||
|
@ -150,6 +141,24 @@ var Size = this.Size = Base.extend(/** @lends Size# */{
|
|||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* Checks whether the width and height of the size are equal to those of the
|
||||
* supplied size.
|
||||
*
|
||||
* @param {Size}
|
||||
* @return {Boolean}
|
||||
*
|
||||
* @example
|
||||
* var size = new Size(5, 10);
|
||||
* console.log(size == new Size(5, 10)); // true
|
||||
* console.log(size == new Size(1, 1)); // false
|
||||
* console.log(size != new Size(1, 1)); // true
|
||||
*/
|
||||
equals: function(size) {
|
||||
size = Size.read(arguments);
|
||||
return this.width == size.width && this.height == size.height;
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns a copy of the size.
|
||||
*/
|
||||
|
@ -158,6 +167,14 @@ var Size = this.Size = Base.extend(/** @lends Size# */{
|
|||
},
|
||||
|
||||
/**
|
||||
* @return {String} A string representation of the size.
|
||||
*/
|
||||
toString: function() {
|
||||
var format = Format.number;
|
||||
return '{ width: ' + format(this.width)
|
||||
+ ', height: ' + format(this.height) + ' }';
|
||||
},
|
||||
|
||||
* Returns the addition of the supplied value to the width and height of the
|
||||
* size as a new size. The object itself is not modified!
|
||||
*
|
||||
|
@ -331,24 +348,6 @@ var Size = this.Size = Base.extend(/** @lends Size# */{
|
|||
return Size.create(-this.width, -this.height);
|
||||
},
|
||||
|
||||
/**
|
||||
* Checks whether the width and height of the size are equal to those of the
|
||||
* supplied size.
|
||||
*
|
||||
* @param {Size}
|
||||
* @return {Boolean}
|
||||
*
|
||||
* @example
|
||||
* var size = new Size(5, 10);
|
||||
* console.log(size == new Size(5, 10)); // true
|
||||
* console.log(size == new Size(1, 1)); // false
|
||||
* console.log(size != new Size(1, 1)); // true
|
||||
*/
|
||||
equals: function(size) {
|
||||
size = Size.read(arguments);
|
||||
return this.width == size.width && this.height == size.height;
|
||||
},
|
||||
|
||||
/**
|
||||
* {@grouptitle Tests}
|
||||
* Checks if this size has both the width and height set to 0.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue