diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index fbde4c9..83c7b14 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -112,7 +112,7 @@ }, set: function (value) { - this.scale.x = utils.sgn(this.scale.x) * value / this.texture._frame.width; + this.scale.x = utils.sign(this.scale.x) * value / this.texture._frame.width; this._width = value; } }, @@ -130,7 +130,7 @@ }, set: function (value) { - this.scale.y = utils.sgn(this.scale.y) * value / this.texture._frame.height; + this.scale.y = utils.sign(this.scale.y) * value / this.texture._frame.height; this._height = value; } }, @@ -182,12 +182,12 @@ // so if _width is 0 then width was not set.. if (this._width) { - this.scale.x = utils.sgn(this.scale.x) * this._width / this.texture.frame.width; + this.scale.x = utils.sign(this.scale.x) * this._width / this.texture.frame.width; } if (this._height) { - this.scale.y = utils.sgn(this.scale.y) * this._height / this.texture.frame.height; + this.scale.y = utils.sign(this.scale.y) * this._height / this.texture.frame.height; } }; diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index fbde4c9..83c7b14 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -112,7 +112,7 @@ }, set: function (value) { - this.scale.x = utils.sgn(this.scale.x) * value / this.texture._frame.width; + this.scale.x = utils.sign(this.scale.x) * value / this.texture._frame.width; this._width = value; } }, @@ -130,7 +130,7 @@ }, set: function (value) { - this.scale.y = utils.sgn(this.scale.y) * value / this.texture._frame.height; + this.scale.y = utils.sign(this.scale.y) * value / this.texture._frame.height; this._height = value; } }, @@ -182,12 +182,12 @@ // so if _width is 0 then width was not set.. if (this._width) { - this.scale.x = utils.sgn(this.scale.x) * this._width / this.texture.frame.width; + this.scale.x = utils.sign(this.scale.x) * this._width / this.texture.frame.width; } if (this._height) { - this.scale.y = utils.sgn(this.scale.y) * this._height / this.texture.frame.height; + this.scale.y = utils.sign(this.scale.y) * this._height / this.texture.frame.height; } }; diff --git a/src/core/utils/index.js b/src/core/utils/index.js index 420208f..6c51937 100644 --- a/src/core/utils/index.js +++ b/src/core/utils/index.js @@ -229,8 +229,8 @@ * @param n {number} * @returns {number} 0 if n is 0, -1 if n is negative, 1 if n i positive */ - sgn: function (n){ - return n === 0 ? 0 : n < 0 ? -1 : 1; + sign: function (n) { + return n ? (n < 0 ? -1 : 1) : 0; }, /** diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index fbde4c9..83c7b14 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -112,7 +112,7 @@ }, set: function (value) { - this.scale.x = utils.sgn(this.scale.x) * value / this.texture._frame.width; + this.scale.x = utils.sign(this.scale.x) * value / this.texture._frame.width; this._width = value; } }, @@ -130,7 +130,7 @@ }, set: function (value) { - this.scale.y = utils.sgn(this.scale.y) * value / this.texture._frame.height; + this.scale.y = utils.sign(this.scale.y) * value / this.texture._frame.height; this._height = value; } }, @@ -182,12 +182,12 @@ // so if _width is 0 then width was not set.. if (this._width) { - this.scale.x = utils.sgn(this.scale.x) * this._width / this.texture.frame.width; + this.scale.x = utils.sign(this.scale.x) * this._width / this.texture.frame.width; } if (this._height) { - this.scale.y = utils.sgn(this.scale.y) * this._height / this.texture.frame.height; + this.scale.y = utils.sign(this.scale.y) * this._height / this.texture.frame.height; } }; diff --git a/src/core/utils/index.js b/src/core/utils/index.js index 420208f..6c51937 100644 --- a/src/core/utils/index.js +++ b/src/core/utils/index.js @@ -229,8 +229,8 @@ * @param n {number} * @returns {number} 0 if n is 0, -1 if n is negative, 1 if n i positive */ - sgn: function (n){ - return n === 0 ? 0 : n < 0 ? -1 : 1; + sign: function (n) { + return n ? (n < 0 ? -1 : 1) : 0; }, /** diff --git a/test/unit/core/utils/util.test.js b/test/unit/core/utils/util.test.js index 7f5ee91..ee9e2cb 100644 --- a/test/unit/core/utils/util.test.js +++ b/test/unit/core/utils/util.test.js @@ -87,22 +87,22 @@ }); }); - describe('.sgn', function () { + describe('.sign', function () { it('should return 0 for 0', function () { - expect(PIXI.utils.sgn(0)) + expect(PIXI.utils.sign(0)) .to.be.equal(0); }); it('should return -1 for negative numbers', function () { for (var i = 0;i<10;i+=1){ - expect(PIXI.utils.sgn(-Math.random())) + expect(PIXI.utils.sign(-Math.random())) .to.be.equal(-1); } }); it('should return 1 for positive numbers', function () { for (var i = 0;i<10;i+=1){ - expect(PIXI.utils.sgn(Math.random() + 0.000001)) + expect(PIXI.utils.sign(Math.random() + 0.000001)) .to.be.equal(1); } });