summaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorUlrich-Matthias Schäfer <ulima.ums@googlemail.com>2018-05-15 10:58:32 +0200
committerUlrich-Matthias Schäfer <ulima.ums@googlemail.com>2018-05-15 10:58:32 +0200
commit601ab0e2494a91bc392fe89046a8166e098ff0d7 (patch)
tree5f3cbc2dacf68c770711b24afc6452e6e5967404 /spec
parent685d53295dd005c6f513b6123d8cd3fb3e671c8a (diff)
downloadsvg.js-601ab0e2494a91bc392fe89046a8166e098ff0d7.tar.gz
svg.js-601ab0e2494a91bc392fe89046a8166e098ff0d7.zip
fixed morphing. Changed easing function so that it can handle strings
- error in Matrix constructor which ignores translateX (and more?) - generelized all morphable objects so that they behave logical - SVG.Morphable can handle all datatypes now
Diffstat (limited to 'spec')
-rw-r--r--spec/spec/morphing.js62
1 files changed, 47 insertions, 15 deletions
diff --git a/spec/spec/morphing.js b/spec/spec/morphing.js
index 14882b2..31279ee 100644
--- a/spec/spec/morphing.js
+++ b/spec/spec/morphing.js
@@ -3,7 +3,7 @@ describe('Morphing', function () {
describe('constructors', function () {
- it(`Creates a morphable out of a SVG.Number`, function () {
+ it(`Creates a morphable out of an SVG.Number`, function () {
var morpher = new SVG.Number(5).to(10)
expect(morpher instanceof SVG.Morphable).toBe(true)
@@ -12,17 +12,17 @@ describe('Morphing', function () {
expect(morpher.at(0.5).valueOf()).toBe(7.5)
})
- it(`Creates a morphable out of a SVG.Color`, function () {
+ it(`Creates a morphable out of an SVG.Color`, function () {
var morpher = new SVG.Color('#fff').to('#000')
expect(morpher instanceof SVG.Morphable).toBe(true)
expect(morpher.type()).toBe(SVG.Color)
expect(morpher.at(0.5) instanceof SVG.Color).toBe(true)
- expect(morpher.at(0.5).toHex()).toBe('#888')
+ expect(morpher.at(0.5).toHex()).toBe('#808080')
})
- it(`Creates a morphable out of a SVG.Box`, function () {
- var morpher = new SVG.Box(1,2,3,4).to(5,6,7,8)
+ it(`Creates a morphable out of an SVG.Box`, function () {
+ var morpher = new SVG.Box(1, 2, 3, 4).to([5, 6, 7, 8])
expect(morpher instanceof SVG.Morphable).toBe(true)
expect(morpher.type()).toBe(SVG.Box)
@@ -30,16 +30,43 @@ describe('Morphing', function () {
expect(morpher.at(0.5)).toEqual(jasmine.objectContaining({x: 3, y: 4, width: 5, height: 6}))
})
- it(`Creates a morphable out of a SVG.Matrix`, function () {
- var morpher = new SVG.Matrix(1,2,3,4,5,6).to(3,4,5,6,7,8)
+ it(`Creates a morphable out of an SVG.Matrix`, function () {
+ var morpher = new SVG.Matrix(1, 2, 3, 4, 5, 6).to([3, 4, 5, 6, 7, 8])
expect(morpher instanceof SVG.Morphable).toBe(true)
expect(morpher.type()).toBe(SVG.Matrix)
expect(morpher.at(0.5) instanceof SVG.Matrix).toBe(true)
- expect(morpher.at(0.5).toBe(jasmine.objectContaining({a: 2, b: 3, c: 4, d: 5, e: 6, f: 7}))
+ expect(morpher.at(0.5)).toEqual(jasmine.objectContaining(new SVG.Matrix(2, 3, 4, 5, 6, 7)))
})
- it(`Creates a morphable out of a SVG.Morphable.NonMorphable`, function () {
+ it(`Creates a morphable out of an SVG.Array`, function () {
+ var morpher = new SVG.Array([1,2,3,4,5,6]).to([3,4,5,6,7,8])
+
+ expect(morpher instanceof SVG.Morphable).toBe(true)
+ expect(morpher.type()).toBe(SVG.Array)
+ expect(morpher.at(0.5) instanceof SVG.Array).toBe(true)
+ expect(morpher.at(0.5).toArray()).toEqual(jasmine.arrayContaining([2, 3, 4, 5, 6, 7]))
+ })
+
+ it(`Creates a morphable out of an SVG.PointArray`, function () {
+ var morpher = new SVG.PointArray([1, 2, 3, 4, 5, 6]).to([3, 4, 5, 6, 7, 8])
+
+ expect(morpher instanceof SVG.Morphable).toBe(true)
+ expect(morpher.type()).toBe(SVG.PointArray)
+ expect(morpher.at(0.5) instanceof SVG.PointArray).toBe(true)
+ expect(morpher.at(0.5).toArray()).toEqual(jasmine.arrayContaining([2, 3, 4, 5, 6, 7]))
+ })
+
+ it(`Creates a morphable out of an SVG.PathArray`, function () {
+ var morpher = new SVG.PathArray(['M', 1, 2, 'L', 3, 4, 'L', 5, 6]).to(['M', 3, 4, 'L', 5, 6, 'L', 7, 8])
+
+ expect(morpher instanceof SVG.Morphable).toBe(true)
+ expect(morpher.type()).toBe(SVG.PathArray)
+ expect(morpher.at(0.5) instanceof SVG.PathArray).toBe(true)
+ expect(morpher.at(0.5).toArray()).toEqual(jasmine.arrayContaining(['M', 2, 3, 'L', 4, 5, 'L', 6, 7]))
+ })
+
+ it(`Creates a morphable out of an SVG.Morphable.NonMorphable`, function () {
var morpher = new SVG.Morphable.NonMorphable('foo').to('bar')
expect(morpher instanceof SVG.Morphable).toBe(true)
@@ -49,22 +76,27 @@ describe('Morphing', function () {
expect(morpher.at(1).valueOf()).toBe('bar')
})
- it(`Creates a morphable out of a SVG.Morphable.TransformBag`, function () {
- var morpher = new SVG.Morphable.TransformBag({}).to({rotation: 50, tx: 20})
+ it(`Creates a morphable out of an SVG.Morphable.TransformBag`, function () {
+ var morpher = new SVG.Morphable.TransformBag({}).to({rotate: 50, translateX: 20})
+
+ // FIXME: SVG.Matrix does now allow translateX to be passed but decompose returns it!!!!!
+ console.log(new SVG.Morphable.TransformBag({rotate: 50, tx: 20}).valueOf().decompose())
expect(morpher instanceof SVG.Morphable).toBe(true)
expect(morpher.type()).toBe(SVG.Morphable.TransformBag)
expect(morpher.at(0.5) instanceof SVG.Morphable.TransformBag).toBe(true)
- expect(morpher.at(0.5).valueOf()).toBe(jasmine.objectContaining({rotation: 25, tx: 10}))
+
+ // TODO: This fails because of roundingerrors and the FIXME above
+ expect(morpher.at(0.5).valueOf().decompose()).toBe(jasmine.objectContaining({rotate: 25, translateX: 10}))
})
- it(`Creates a morphable out of a SVG.Morphable.ObjectBag`, function () {
+ it(`Creates a morphable out of an SVG.Morphable.ObjectBag`, function () {
var morpher = new SVG.Morphable.ObjectBag({a:5, b: 10}).to({a: 10, b: 20})
expect(morpher instanceof SVG.Morphable).toBe(true)
expect(morpher.type()).toBe(SVG.Morphable.ObjectBag)
- expect(morpher.at(0.5) instanceof SVG.Morphable.ObjectBag).toBe(true)
- expect(morpher.at(0.5).valueOf()).toBe(jasmine.objectContaining({a: 7.5, b: 15}))
+ expect(morpher.at(0.5) instanceof Object).toBe(true)
+ expect(morpher.at(0.5).valueOf()).toEqual(jasmine.objectContaining({a: 7.5, b: 15}))
})
})
})