diff options
author | Rémi Tétreault <tetreault.remi@gmail.com> | 2017-02-22 00:20:09 -0500 |
---|---|---|
committer | Rémi Tétreault <tetreault.remi@gmail.com> | 2017-02-22 00:20:09 -0500 |
commit | 669c10a76ebd164c147d7f896fa162784c0b49df (patch) | |
tree | 7e8a86edc4b6bdcfb478347ef25e2a854b852f20 /src/number.js | |
parent | 2d11717fe6ccd6b420f2faa5d56e3064e8574d18 (diff) | |
download | svg.js-669c10a76ebd164c147d7f896fa162784c0b49df.tar.gz svg.js-669c10a76ebd164c147d7f896fa162784c0b49df.zip |
Allow 0 to be passed without unit
This commit finish fixing issue #552. It makes it unnecessary to specify a
unit with 0 when interacting with another SVG.Number that has a unit.
This was accomplished by modifying the operation methods of SVG.Number to
allow them to use the unit of the passed number when this number as no unit.
Diffstat (limited to 'src/number.js')
-rw-r--r-- | src/number.js | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/number.js b/src/number.js index d0ccf4e..8198e7c 100644 --- a/src/number.js +++ b/src/number.js @@ -57,19 +57,23 @@ SVG.Number = SVG.invent({ } // Add number , plus: function(number) { - return new SVG.Number(this + new SVG.Number(number), this.unit) + number = new SVG.Number(number) + return new SVG.Number(this + number, this.unit || number.unit) } // Subtract number , minus: function(number) { - return this.plus(-new SVG.Number(number)) + number = new SVG.Number(number) + return new SVG.Number(this - number, this.unit || number.unit) } // Multiply number , times: function(number) { - return new SVG.Number(this * new SVG.Number(number), this.unit) + number = new SVG.Number(number) + return new SVG.Number(this * number, this.unit || number.unit) } // Divide number , divide: function(number) { - return new SVG.Number(this / new SVG.Number(number), this.unit) + number = new SVG.Number(number) + return new SVG.Number(this / number, this.unit || number.unit) } // Convert to different unit , to: function(unit) { |