diff options
author | wout <wout@impinc.co.uk> | 2014-07-12 14:06:49 +0200 |
---|---|---|
committer | wout <wout@impinc.co.uk> | 2014-07-12 14:06:49 +0200 |
commit | 501cb5387007a89af382717376c773a1ec6b68ae (patch) | |
tree | 8edcd6d28407c02430a3ace7245384bc894eb867 /spec | |
parent | 462d2cd3738c904db0be7086878d1fcc17b79553 (diff) | |
download | svg.js-501cb5387007a89af382717376c773a1ec6b68ae.tar.gz svg.js-501cb5387007a89af382717376c773a1ec6b68ae.zip |
Further debugging matrix new implementation
Diffstat (limited to 'spec')
-rwxr-xr-x | spec/spec/element.js | 10 | ||||
-rw-r--r-- | spec/spec/matrix.js | 52 | ||||
-rwxr-xr-x | spec/spec/rect.js | 2 |
3 files changed, 37 insertions, 27 deletions
diff --git a/spec/spec/element.js b/spec/spec/element.js index 0611210..d6988fb 100755 --- a/spec/spec/element.js +++ b/spec/spec/element.js @@ -86,7 +86,6 @@ describe('Element', function() { }) it('correctly parses negative numeric values as a global getter', function() { rect.x(-30) - console.log(rect.native()) expect(rect.attr().x).toBe(-30) }) it('leaves unit values alone as a global getter', function() { @@ -166,16 +165,17 @@ describe('Element', function() { expect(rect.node.getAttribute('transform')).toBe('matrix(1,-0.17632698070846498,0,1,0,0)') }) it('rotates the element around its centre if no rotation point is given', function() { - var rect = draw.rect(100,100).transform({ rotation: 45 }) - expect(rect.node.getAttribute('transform')).toBe('rotate(45 50 50)') + var rect = draw.rect(100,100).center(150,150).transform({ rotation: 45 }) + expect(rect.node.getAttribute('transform')).toBe('matrix(0.7071067811865475,0.7071067811865475,-0.7071067811865475,0.7071067811865475,150,-62.13203435596424)') + expect(rect.transform('rotation')).toBe(45) }) it('rotates the element around the given rotation point', function() { var rect = draw.rect(100,100).transform({ rotation: 55, cx: 80, cy:2 }) - expect(rect.node.getAttribute('transform')).toBe('rotate(55 80 2)') + expect(rect.node.getAttribute('transform')).toBe('matrix(0.573576436351046,0.8191520442889917,-0.8191520442889917,0.573576436351046,35.7521891804943,-64.67931641582143)') }) it('transforms element using a matrix', function() { var rect = draw.rect(100,100).transform({ a: 0.5, c: 0.5 }) - expect(rect.node.getAttribute('transform')).toBe('matrix(0.5 0 0.5 1 0 0)') + expect(rect.node.getAttribute('transform')).toBe('matrix(0.5,0,0.5,1,0,0)') }) }) diff --git a/spec/spec/matrix.js b/spec/spec/matrix.js index 9689d81..1ccb419 100644 --- a/spec/spec/matrix.js +++ b/spec/spec/matrix.js @@ -17,37 +17,47 @@ describe('Matrix', function() { expect(matrix.e).toBe(0) expect(matrix.f).toBe(0) }) - it('parses translation values', function() { - expect(matrix.x).toBe(0) - expect(matrix.y).toBe(0) - }) - it('parses skew values', function() { - expect(matrix.skewX).toBe(0) - expect(matrix.skewY).toBe(0) - }) - it('parses scale values', function() { - expect(matrix.scaleX).toBe(1) - expect(matrix.scaleY).toBe(1) - }) - it('parses rotaton value', function() { - expect(matrix.rotation).toBe(0) + + describe('extract()', function() { + var extract + + beforeEach(function() { + extract = matrix.extract() + }) + + it('parses translation values', function() { + expect(extract.x).toBe(0) + expect(extract.y).toBe(0) + }) + it('parses skew values', function() { + expect(extract.skewX).toBe(0) + expect(extract.skewY).toBe(0) + }) + it('parses scale values', function() { + expect(extract.scaleX).toBe(1) + expect(extract.scaleY).toBe(1) + }) + it('parses rotaton value', function() { + expect(extract.rotation).toBe(0) + }) }) }) describe('with an element given', function() { beforeEach(function() { - matrix = new SVG.Matrix(draw.rect(100, 100).skew(10, 20).translate(50, 50).scale(3, 2)) + matrix = new SVG.Matrix(draw.rect(100, 100).skew(10, 20).translate(40, 50).scale(3, 2)) }) it('parses the current transform matrix form an element', function() { - expect(matrix.a).toBe(1) - expect(matrix.b).toBe(0) - expect(matrix.c).toBe(0) - expect(matrix.d).toBe(1) - expect(matrix.e).toBe(0) - expect(matrix.f).toBe(0) + expect(matrix.a).toBe(3.192533254623413) + expect(matrix.b).toBe(1.091910719871521) + expect(matrix.c).toBe(0.35265403985977173) + expect(matrix.d).toBe(2) + expect(matrix.e).toBe(51.383460998535156) + expect(matrix.f).toBe(64.55880737304688) }) + }) }) diff --git a/spec/spec/rect.js b/spec/spec/rect.js index 938bc46..f983d78 100755 --- a/spec/spec/rect.js +++ b/spec/spec/rect.js @@ -166,7 +166,7 @@ describe('Rect', function() { describe('translate()', function() { it('should set the translation of an element', function() { rect.transform({ x: 12, y: 12 }) - expect(rect.node.getAttribute('transform')).toBe('translate(12 12)') + expect(rect.node.getAttribute('transform')).toBe('matrix(1,0,0,1,12,12)') }) }) |