From 14585d5e4f8ce51829f4da6759c2fe04dde37b5c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Ulrich-Matthias=20Sch=C3=A4fer?= Date: Sat, 3 Mar 2018 21:11:14 +0100 Subject: [PATCH] make `at()` method of morphable objects throw when no destination is set (#797) --- spec/spec/array.js | 13 ++++++------- spec/spec/boxes.js | 4 ++-- spec/spec/color.js | 4 ++-- spec/spec/matrix.js | 4 ++-- spec/spec/number.js | 4 ++-- spec/spec/point.js | 4 ++-- src/array.js | 2 +- src/boxes.js | 2 +- src/color.js | 2 +- src/matrix.js | 2 +- src/number.js | 2 +- src/patharray.js | 2 +- src/point.js | 2 +- src/pointarray.js | 2 +- 14 files changed, 24 insertions(+), 25 deletions(-) diff --git a/spec/spec/array.js b/spec/spec/array.js index 7530ea1..03046ca 100644 --- a/spec/spec/array.js +++ b/spec/spec/array.js @@ -113,8 +113,8 @@ describe('Array', function () { arr1.morph(arr2) expect(arr1.at(0.5).value).toEqual([1.5, 2.5, 3.5, 4.5]) }) - it('returns itself if no destination was specified', function() { - expect(arr1.at(0.5)).toBe(arr1) + it('throws when no destination was specified', function() { + expect(arr1.at).toThrow() }) }) }) @@ -221,8 +221,8 @@ describe('PointArray', function () { arr1.morph(arr2) expect(arr1.at(0.5).value).toEqual([[1.5, 2.5], [3.5, 4.5]]) }) - it('returns itself if no destination was specified', function() { - expect(arr1.at(0.5)).toBe(arr1) + it('throws when no destination was specified', function() { + expect(arr1.at).toThrow() }) }) }) @@ -394,10 +394,9 @@ describe('PathArray', function () { expect(morphedPathArray.value[1][4]).toBe(1) expect(morphedPathArray.value[1][5]).toBe(0) }) - it('return itself if the destination attribute is null', function(){ + it('throws when no destination was specified', function(){ var pathArray = new SVG.PathArray('M 13 13 A 25 37 0 0 1 43 25') - pathArray.destination = null - expect(pathArray.at(0.45)).toBe(pathArray) + expect(pathArray.at).toThrow() }) }) diff --git a/spec/spec/boxes.js b/spec/spec/boxes.js index 9e33c60..cc428e4 100644 --- a/spec/spec/boxes.js +++ b/spec/spec/boxes.js @@ -148,9 +148,9 @@ describe('Box', function() { expect(box2.toString()).toBe('50 -100 300 300') expect(box3.toString()).toBe('30 0 250 300') }) - it('returns itself when no destination given', function() { + it('throws itself when no destination was specified', function() { var box = new SVG.Box(10, 100, 200, 300) - expect(box.at(0.5)).toBe(box) + expect(box.at).toThrow() }) }) }) diff --git a/spec/spec/color.js b/spec/spec/color.js index 1e86544..b70af1b 100644 --- a/spec/spec/color.js +++ b/spec/spec/color.js @@ -77,8 +77,8 @@ describe('Color', function() { expect(morphed.b).toBe(255) }) - it('returns itself when no destination specified', function() { - expect(color.at(0.5)).toBe(color) + it('throws when no destination specified', function() { + expect(color.at).toThrow() }) }) diff --git a/spec/spec/matrix.js b/spec/spec/matrix.js index 0816f66..aaebd68 100644 --- a/spec/spec/matrix.js +++ b/spec/spec/matrix.js @@ -193,9 +193,9 @@ describe('Matrix', function() { expect(matrix2.toString()).toBe('matrix(1,0,0,1,4,3)') expect(matrix3.toString()).toBe('matrix(1.5,0,0,3,2,1.5)') }) - it('returns itself when no destination specified', function() { + it('throws when no destination specified', function() { var matrix = new SVG.Matrix(2, 0, 0, 5, 0, 0) - expect(matrix.at(0.5)).toBe(matrix) + expect(matrix.at).toThrow() }) }) diff --git a/spec/spec/number.js b/spec/spec/number.js index 58c14bd..2d33fef 100644 --- a/spec/spec/number.js +++ b/spec/spec/number.js @@ -237,8 +237,8 @@ describe('Number', function() { it('use the unit of this number as the unit of the returned number when the destination number as no unit', function() { expect(expect(new SVG.Number('100s').morph(50).at(0.5).unit).toBe('s')) }) - it('returns itself when no destination specified', function() { - expect(number.at(0.5)).toBe(number) + it('throws when no destination specified', function() { + expect(number.at).toThrow() }) }) diff --git a/spec/spec/point.js b/spec/spec/point.js index 8eacb84..80cc414 100644 --- a/spec/spec/point.js +++ b/spec/spec/point.js @@ -117,9 +117,9 @@ describe('Point', function() { expect(point3).toEqual(new SVG.Point(1.5, 1.5)) }) - it('returns itself when no destination specified', function() { + it('throws when no destination specified', function() { var point = new SVG.Point(1,1) - expect(point.at(0.4)).toBe(point) + expect(point.at).toThrow() }) }) diff --git a/src/array.js b/src/array.js index ca51d8e..5ce0160 100644 --- a/src/array.js +++ b/src/array.js @@ -49,7 +49,7 @@ SVG.extend(SVG.Array, { // Get morphed array at given position at: function (pos) { // make sure a destination is defined - if (!this.destination) return this + if (!this.destination) throw new Error('No destination set') // generate morphed array for (var i = 0, il = this.value.length, array = []; i < il; i++) { diff --git a/src/boxes.js b/src/boxes.js index f0154bd..de96081 100644 --- a/src/boxes.js +++ b/src/boxes.js @@ -74,7 +74,7 @@ SVG.Box = SVG.invent({ }, at: function (pos) { - if (!this.destination) return this + if (!this.destination) throw new Error('No destination set') return new SVG.Box( this.x + (this.destination.x - this.x) * pos diff --git a/src/color.js b/src/color.js index 8f47f70..22b8506 100644 --- a/src/color.js +++ b/src/color.js @@ -68,7 +68,7 @@ SVG.extend(SVG.Color, { // Get morphed color at given position at: function (pos) { // make sure a destination is defined - if (!this.destination) return this + if (!this.destination) throw new Error('No destination set') // normalise pos pos = pos < 0 ? 0 : pos > 1 ? 1 : pos diff --git a/src/matrix.js b/src/matrix.js index e823a81..8028b15 100644 --- a/src/matrix.js +++ b/src/matrix.js @@ -68,7 +68,7 @@ SVG.Matrix = SVG.invent({ // Get morphed matrix at a given position at: function (pos) { // make sure a destination is defined - if (!this.destination) return this + if (!this.destination) throw new Error('No destination set') // calculate morphed matrix at a given position var matrix = new SVG.Matrix({ diff --git a/src/number.js b/src/number.js index 6413f94..ba95151 100644 --- a/src/number.js +++ b/src/number.js @@ -91,7 +91,7 @@ SVG.Number = SVG.invent({ // Get morphed number at given position at: function (pos) { // Make sure a destination is defined - if (!this.destination) return this + if (!this.destination) throw new Error('No destination set') // Generate new morphed number return new SVG.Number(this.destination) diff --git a/src/patharray.js b/src/patharray.js index d9ffecd..ca58513 100644 --- a/src/patharray.js +++ b/src/patharray.js @@ -195,7 +195,7 @@ SVG.extend(SVG.PathArray, { // Get morphed path array at given position at: function (pos) { // make sure a destination is defined - if (!this.destination) return this + if (!this.destination) throw new Error('No destination set') var sourceArray = this.value var destinationArray = this.destination.value diff --git a/src/point.js b/src/point.js index 682092e..72a9572 100644 --- a/src/point.js +++ b/src/point.js @@ -32,7 +32,7 @@ SVG.Point = SVG.invent({ // Get morphed point at a given position at: function (pos) { // make sure a destination is defined - if (!this.destination) return this + if (!this.destination) throw new Error('No destination set') // calculate morphed matrix at a given position var point = new SVG.Point({ diff --git a/src/pointarray.js b/src/pointarray.js index ecf5c40..6229e2e 100644 --- a/src/pointarray.js +++ b/src/pointarray.js @@ -32,7 +32,7 @@ SVG.extend(SVG.PointArray, { // Get morphed array at given position at: function (pos) { // make sure a destination is defined - if (!this.destination) return this + if (!this.destination) throw new Error('No destination set') // generate morphed point string for (var i = 0, il = this.value.length, array = []; i < il; i++) { -- 2.39.5