diff options
author | Ulrich-Matthias Schäfer <ulima.ums@googlemail.com> | 2018-11-07 15:08:41 +0100 |
---|---|---|
committer | Ulrich-Matthias Schäfer <ulima.ums@googlemail.com> | 2018-11-07 15:08:41 +0100 |
commit | 47fda3cf67cdc8ab20d3b1ba9d65a810adddf5ee (patch) | |
tree | c3dbd5df7f41c41ae5b41717ee8312ba84aeed07 /src/array.js | |
parent | 23595eba0ee68a86040d4667bdae4d9e6fe426ba (diff) | |
parent | 0cae4172fa0c7ee9b876b1cf2b38ea8be66d3584 (diff) | |
download | svg.js-47fda3cf67cdc8ab20d3b1ba9d65a810adddf5ee.tar.gz svg.js-47fda3cf67cdc8ab20d3b1ba9d65a810adddf5ee.zip |
Merge branch '875-es6' into 3.0.0
Diffstat (limited to 'src/array.js')
-rw-r--r-- | src/array.js | 92 |
1 files changed, 0 insertions, 92 deletions
diff --git a/src/array.js b/src/array.js deleted file mode 100644 index aa43d5c..0000000 --- a/src/array.js +++ /dev/null @@ -1,92 +0,0 @@ -/* global arrayClone */ - -// Module for array conversion -SVG.Array = function (array, fallback) { - array = (array || []).valueOf() - - // if array is empty and fallback is provided, use fallback - if (array.length === 0 && fallback) { - array = fallback.valueOf() - } - - // parse array - this.value = this.parse(array) -} - -SVG.extend(SVG.Array, { - // Make array morphable - morph: function (array) { - this.destination = this.parse(array) - - // normalize length of arrays - if (this.value.length !== this.destination.length) { - var lastValue = this.value[this.value.length - 1] - var lastDestination = this.destination[this.destination.length - 1] - - while (this.value.length > this.destination.length) { - this.destination.push(lastDestination) - } - while (this.value.length < this.destination.length) { - this.value.push(lastValue) - } - } - - return this - }, - // Clean up any duplicate points - settle: function () { - // find all unique values - for (var i = 0, il = this.value.length, seen = []; i < il; i++) { - if (seen.indexOf(this.value[i]) === -1) { - seen.push(this.value[i]) - } - } - - // set new value - this.value = seen - return seen - }, - // Get morphed array at given position - at: function (pos) { - // make sure a destination is defined - if (!this.destination) return this - - // generate morphed array - for (var i = 0, il = this.value.length, array = []; i < il; i++) { - array.push(this.value[i] + (this.destination[i] - this.value[i]) * pos) - } - - return new SVG.Array(array) - }, - toArray: function () { - return this.value - }, - // Convert array to string - toString: function () { - return this.value.join(' ') - }, - // Real value - valueOf: function () { - return this.value - }, - // Parse whitespace separated string - parse: function (array) { - array = array.valueOf() - - // if already is an array, no need to parse it - if (Array.isArray(array)) return array - - return array.trim().split(SVG.regex.delimiter).map(parseFloat) - }, - // Reverse array - reverse: function () { - this.value.reverse() - - return this - }, - clone: function () { - var clone = new this.constructor() - clone.value = arrayClone(this.value) - return clone - } -}) |