aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorSaivan <savian@me.com>2018-03-02 12:14:42 +1100
committerSaivan <savian@me.com>2018-03-02 12:14:42 +1100
commit1582edb4236628fbc7875242f159c16283b769c2 (patch)
tree1d915c21fce7ce3997edaedd92f4f1a8d8968d9d /spec
parent13cf84b716cd3e06330fa0ea6f077bbe7de0eb88 (diff)
downloadsvg.js-1582edb4236628fbc7875242f159c16283b769c2.tar.gz
svg.js-1582edb4236628fbc7875242f159c16283b769c2.zip
Implemented new transformations
This commit implements the new transformation model, but it also needs to modify a few tests to fit the new format. This is still a work in progress.
Diffstat (limited to 'spec')
-rw-r--r--spec/SpecRunner.html16
-rw-r--r--spec/spec/element.js51
-rw-r--r--spec/spec/helper.js12
-rw-r--r--spec/spec/matrix.js256
4 files changed, 168 insertions, 167 deletions
diff --git a/spec/SpecRunner.html b/spec/SpecRunner.html
index 7461bdd..1ecef12 100644
--- a/spec/SpecRunner.html
+++ b/spec/SpecRunner.html
@@ -52,7 +52,7 @@
<!-- include spec files here... -->
- <script src="spec/adopter.js"></script>
+ <!-- <script src="spec/adopter.js"></script>
<script src="spec/arrange.js"></script>
<script src="spec/array.js"></script>
<script src="spec/bare.js"></script>
@@ -63,21 +63,21 @@
<script src="spec/container.js"></script>
<script src="spec/defs.js"></script>
<script src="spec/doc.js"></script>
- <script src="spec/easing.js"></script>
+ <script src="spec/easing.js"></script> -->
<script src="spec/element.js"></script>
- <script src="spec/ellipse.js"></script>
+ <!-- <script src="spec/ellipse.js"></script>
<script src="spec/event.js"></script>
<script src="spec/fx.js"></script>
<script src="spec/gradient.js"></script>
- <script src="spec/group.js"></script>
+ <script src="spec/group.js"></script>-->
<script src="spec/helper.js"></script>
- <script src="spec/hyperlink.js"></script>
+ <!-- <script src="spec/hyperlink.js"></script>
<script src="spec/image.js"></script>
<script src="spec/line.js"></script>
<script src="spec/marker.js"></script>
- <script src="spec/mask.js"></script>
+ <script src="spec/mask.js"></script> -->
<script src="spec/matrix.js"></script>
- <script src="spec/memory.js"></script>
+ <!-- <script src="spec/memory.js"></script>
<script src="spec/nested.js"></script>
<script src="spec/number.js"></script>
<script src="spec/path.js"></script>
@@ -97,7 +97,7 @@
<script src="spec/tspan.js"></script>
<script src="spec/use.js"></script>
<script src="spec/utils.js"></script>
- <script src="spec/viewbox.js"></script>
+ <script src="spec/viewbox.js"></script> -->
</body>
</html>
diff --git a/spec/spec/element.js b/spec/spec/element.js
index a5b26a1..3f62e5a 100644
--- a/spec/spec/element.js
+++ b/spec/spec/element.js
@@ -134,13 +134,13 @@ describe('Element', function() {
it('increases the global id sequence', function() {
var did = SVG.did
rect.id()
-
+
expect(did + 1).toBe(SVG.did)
})
it('adds a unique id containing the node name', function() {
var did = SVG.did
rect.id()
-
+
expect(rect.attr('id')).toBe('SvgjsRect' + did)
})
it('gets the value if the id attribute without an argument', function() {
@@ -194,23 +194,19 @@ describe('Element', function() {
rect = draw.rect(100,100)
})
- it('gets the current transformations', function() {
- expect(rect.transform()).toEqual(new SVG.Matrix(rect).extract())
+ it('gets the current transformation matrix', function() {
+ expect(rect.transform()).toEqual(new SVG.Matrix(rect))
})
it('sets the translation of and element', function() {
- rect.transform({ x: 10, y: 11 })
+ rect.transform({ translate: [10, 11] })
expect(window.matrixStringToArray(rect.node.getAttribute('transform'))).toEqual([1,0,0,1,10,11])
})
it('performs an absolute translation', function() {
- rect.transform({ x: 10, y: 11 }).transform({ x: 20, y: 21 })
+ rect.transform({ translate: [10, 11] }).transform({ translate: [20, 21] })
expect(window.matrixStringToArray(rect.node.getAttribute('transform'))).toEqual([1,0,0,1,20,21])
})
- it('performs a relative translation when relative is set to true', function() {
- rect.transform({ x: 10, y: 11 }).transform({ x: 20, y: 21, relative: true })
- expect(window.matrixStringToArray(rect.node.getAttribute('transform'))).toEqual([1,0,0,1,30,32])
- })
it('performs a relative translation with relative flag', function() {
- rect.transform({ x: 10, y: 11 }).transform({ x: 20, y: 21 }, true)
+ rect.transform({ translate: [10, 11] }).transform({ translate: [20, 21] }, true)
expect(window.matrixStringToArray(rect.node.getAttribute('transform'))).toEqual([1,0,0,1,30,32])
})
it('sets the scaleX and scaleY of an element', function() {
@@ -248,7 +244,7 @@ describe('Element', function() {
expect(ctm.f).toBe(0)
})
it('sets the skewX of an element with given center', function() {
- ctm = rect.transform({ skewX: 10, cx: 0, cy: 0 }).ctm()
+ ctm = rect.transform({ skewX: 10, ox: 0, oy: 0 }).ctm()
expect(ctm.a).toBe(1)
expect(ctm.b).toBe(0)
expect(ctm.c).toBeCloseTo(0.17632698070846498)
@@ -257,7 +253,7 @@ describe('Element', function() {
expect(ctm.f).toBe(0)
})
it('sets the skewY of an element', function() {
- ctm = rect.transform({ skewY: -10, cx: 0, cy: 0 }).ctm()
+ ctm = rect.transform({ skewY: -10, ox: 0, oy: 0 }).ctm()
expect(ctm.a).toBe(1)
expect(ctm.b).toBeCloseTo(-0.17632698070846498)
expect(ctm.c).toBe(0)
@@ -266,7 +262,7 @@ describe('Element', function() {
expect(ctm.f).toBe(0)
})
it('sets the skewX and skewY of an element', function() {
- ctm = rect.transform({ skewX: 10, skewY: -10, cx: 0, cy: 0 }).ctm()
+ ctm = rect.transform({ skewX: 10, skewY: -10, ox: 0, oy: 0 }).ctm()
expect(ctm.a).toBe(1)
expect(ctm.b).toBeCloseTo(-0.17632698070846498)
expect(ctm.c).toBeCloseTo(0.17632698070846498)
@@ -275,7 +271,7 @@ describe('Element', function() {
expect(ctm.f).toBe(0)
})
it('performs a uniform skew with skew given', function() {
- ctm = rect.transform({ skew: 5, cx: 0, cy: 0 }).ctm()
+ ctm = rect.transform({ skew: 5, ox: 0, oy: 0 }).ctm()
expect(ctm.a).toBe(1)
expect(ctm.b).toBeCloseTo(0.08748866352592401)
expect(ctm.c).toBeCloseTo(0.08748866352592401)
@@ -284,17 +280,16 @@ describe('Element', function() {
expect(ctm.f).toBe(0)
})
it('rotates the element around its centre if no rotation point is given', function() {
- ctm = rect.center(100, 100).transform({ rotation: 45 }).ctm()
+ ctm = rect.center(100, 100).transform({ rotate: 45 }).ctm()
expect(ctm.a).toBeCloseTo(0.7071068286895752)
expect(ctm.b).toBeCloseTo(0.7071068286895752)
expect(ctm.c).toBeCloseTo(-0.7071068286895752)
expect(ctm.d).toBeCloseTo(0.7071068286895752)
expect(ctm.e).toBeCloseTo(100)
expect(ctm.f).toBeCloseTo(-41.421356201171875)
- expect(rect.transform('rotation')).toBe(45)
})
it('rotates the element around the given rotation point', function() {
- ctm = rect.transform({ rotation: 55, cx: 80, cy:2 }).ctm()
+ ctm = rect.transform({ rotate: 55, origin: [80, 2] }).ctm()
expect(ctm.a).toBeCloseTo(0.5735765099525452)
expect(ctm.b).toBeCloseTo(0.8191521167755127)
expect(ctm.c).toBeCloseTo(-0.8191521167755127)
@@ -315,15 +310,15 @@ describe('Element', function() {
expect(window.matrixStringToArray(rect.node.getAttribute('transform'))).toEqual([-1,0,0,1,100,0])
})
it('flips the element on x axis with offset', function() {
- rect.transform({ flip: 'x', offset: 20 })
+ rect.transform({ flip: 'x', origin: [20, 0] })
expect(window.matrixStringToArray(rect.node.getAttribute('transform'))).toEqual([-1,0,0,1,40,0])
})
it('flips the element on y axis with offset', function() {
- rect.transform({ flip: 'y', offset: 20 })
+ rect.transform({ flip: 'y', origin: [0, 20] })
expect(window.matrixStringToArray(rect.node.getAttribute('transform'))).toEqual([1,0,0,-1,0,40])
})
it('flips the element on both axis with offset', function() {
- rect.transform({ flip: 'both', offset: 20 })
+ rect.transform({ flip: 'both', origin: [20, 20] })
expect(window.matrixStringToArray(rect.node.getAttribute('transform'))).toEqual([-1,0,0,-1,40,40])
})
it('flips the element on both axis', function() {
@@ -386,6 +381,20 @@ describe('Element', function() {
rect.attr('transform', 'translate(24,14) , translate(36,6)')
expect(rect.matrixify().toString()).toBe('matrix(1,0,0,1,60,20)')
})
+
+
+ it('merges non-commutative transformations correctly', function() {
+ // Spaces before the comma
+ rect.attr('transform', 'scale(3, 2) translate(20,16)')
+ expect(rect.matrixify().toString()).toBe('matrix(3,0,0,2,60,32)')
+ })
+
+ it('doesn\'t care if you have matrices there', function() {
+ // Spaces before the comma
+ rect.attr('transform', 'matrix(3, 0, 0, 2, 0, 0) translate(20,16)')
+ expect(rect.matrixify().toString()).toBe('matrix(3,0,0,2,60,32)')
+ })
+
})
describe('toParent()', function() {
diff --git a/spec/spec/helper.js b/spec/spec/helper.js
index 3dd6aff..4c15acd 100644
--- a/spec/spec/helper.js
+++ b/spec/spec/helper.js
@@ -16,17 +16,17 @@ if(typeof exports === 'object'){
for(var i in attrs){
el.setAttribute(i, attrs[i])
}
-
+
for(var i in children){
if(typeof children[i] == 'string')
children[i] = document.createTextNode(children[i])
-
+
el.appendChild(children[i])
}
-
+
return el
}
-
+
// create fixtures in svgdom
var el = tag('svg', {
height:0,
@@ -122,9 +122,9 @@ if(typeof exports === 'object'){
tag('polygon', {points: '200,10 250,190 160,210'}),
tag('polyline', {points: '20,20 40,25 60,40 80,120 120,140 200,180'})
])
-
+
document.appendChild(el)
-
+
}else{
drawing = document.createElement('div')
document.getElementsByTagName('body')[0].appendChild(drawing)
diff --git a/spec/spec/matrix.js b/spec/spec/matrix.js
index 0816f66..08e0280 100644
--- a/spec/spec/matrix.js
+++ b/spec/spec/matrix.js
@@ -18,27 +18,26 @@ describe('Matrix', function() {
expect(matrix.f).toBe(0)
})
- describe('extract()', function() {
- var extract
+ describe('decompose()', function() {
+ var decompose
beforeEach(function() {
- extract = matrix.extract()
+ decompose = matrix.decompose()
})
it('parses translation values', function() {
- expect(extract.x).toBe(0)
- expect(extract.y).toBe(0)
+ expect(decompose.translateX).toBe(0)
+ expect(decompose.translateY).toBe(0)
})
- it('parses skew values', function() {
- expect(extract.skewX).toBe(0)
- expect(extract.skewY).toBe(0)
+ it('parses shear values', function() {
+ expect(decompose.shear).toBe(0)
})
it('parses scale values', function() {
- expect(extract.scaleX).toBe(1)
- expect(extract.scaleY).toBe(1)
+ expect(decompose.scaleX).toBe(1)
+ expect(decompose.scaleY).toBe(1)
})
it('parses rotatoin value', function() {
- expect(extract.rotation).toBe(0)
+ expect(decompose.rotate).toBe(0)
})
})
@@ -53,48 +52,24 @@ describe('Matrix', function() {
var rect
beforeEach(function() {
+ // Draw is defined in helpers
rect = draw.rect(100, 100)
- .transform({ rotation: -10 }, true)
- .transform({ x: 40, y: 50 }, true)
- .transform({ scale: 2 }, true)
-
+ .transform({
+ rotate: -10,
+ translate: [40, 50],
+ scale: 2,
+ })
matrix = new SVG.Matrix(rect)
})
it('parses the current transform matrix from an element', function() {
- expect(matrix.a).toBeCloseTo(1.9696155786514282)
- expect(matrix.b).toBeCloseTo(-0.3472963869571686)
- expect(matrix.c).toBeCloseTo(0.3472963869571686)
- expect(matrix.d).toBeCloseTo(1.9696155786514282)
- expect(matrix.e).toBeCloseTo(-17.770875930786133)
- expect(matrix.f).toBeCloseTo(11.178505897521973)
- })
-
- describe('extract()', function() {
-
- it('parses translation values', function() {
- var extract = new SVG.Matrix(draw.rect(100, 100).translate(40, 50)).extract()
- expect(extract.x).toBeCloseTo(40)
- expect(extract.y).toBeCloseTo(50)
- })
- it('parses skewX value', function() {
- var extract = new SVG.Matrix(draw.rect(100, 100).skew(25, 0)).extract()
- expect(extract.skewX).toBeCloseTo(25)
- })
- it('parses skewY value', function() {
- var extract = new SVG.Matrix(draw.rect(100, 100).skew(0, 20)).extract()
- expect(extract.skewY).toBeCloseTo(20)
- })
- it('parses scale values', function() {
- var extract = new SVG.Matrix(draw.rect(100, 100).scale(2, 3)).extract()
- expect(extract.scaleX).toBeCloseTo(2)
- expect(extract.scaleY).toBeCloseTo(3)
- })
- it('parses rotatoin value', function() {
- var extract = new SVG.Matrix(draw.rect(100, 100).rotate(-100)).extract()
- expect(extract.rotation).toBeCloseTo(-100)
- })
+ expect(matrix.a).toBeCloseTo(1.969615506024416)
+ expect(matrix.b).toBeCloseTo(-0.34729635533386066)
+ expect(matrix.c).toBeCloseTo(0.34729635533386066)
+ expect(matrix.d).toBeCloseTo(1.969615506024416)
+ expect(matrix.e).toBeCloseTo(-25.84559306791384)
+ expect(matrix.f).toBeCloseTo(18.884042465472234)
})
})
@@ -201,20 +176,21 @@ describe('Matrix', function() {
describe('multiply()', function() {
it('multiplies two matices', function() {
- var matrix1 = new SVG.Matrix(2, 0, 0, 5, 0, 0)
- , matrix2 = new SVG.Matrix(1, 0, 0, 1, 4, 3)
+ var matrix1 = new SVG.Matrix(1, 4, 2, 5, 3, 6)
+ , matrix2 = new SVG.Matrix(7, 8, 8, 7, 9, 6)
, matrix3 = matrix1.multiply(matrix2)
- expect(matrix1.toString()).toBe('matrix(2,0,0,5,0,0)')
- expect(matrix2.toString()).toBe('matrix(1,0,0,1,4,3)')
- expect(matrix3.toString()).toBe('matrix(2,0,0,5,8,15)')
+ expect(matrix1.toString()).toBe('matrix(1,4,2,5,3,6)')
+ expect(matrix2.toString()).toBe('matrix(7,8,8,7,9,6)')
+ expect(matrix3.toString()).toBe('matrix(23,68,22,67,24,72)')
})
+
it('accepts matrices in any form', function() {
- var matrix1 = new SVG.Matrix(2, 0, 0, 5, 0, 0)
- , matrix2 = matrix1.multiply('1,0,0,1,4,3')
+ var matrix1 = new SVG.Matrix(1, 4, 2, 5, 3, 6)
+ , matrix2 = matrix1.multiply('7,8,8,7,9,6')
- expect(matrix1.toString()).toBe('matrix(2,0,0,5,0,0)')
- expect(matrix2.toString()).toBe('matrix(2,0,0,5,8,15)')
+ expect(matrix1.toString()).toBe('matrix(1,4,2,5,3,6)')
+ expect(matrix2.toString()).toBe('matrix(23,68,22,67,24,72)')
})
})
@@ -236,10 +212,15 @@ describe('Matrix', function() {
describe('translate()', function() {
it('translates matrix by given x and y values', function() {
var matrix = new SVG.Matrix(1, 0, 0, 1, 4, 3).translate(10, 12.5)
-
expect(matrix.e).toBe(14)
expect(matrix.f).toBe(15.5)
})
+
+ it('does nothing if you give it no x or y value', function() {
+ var matrix = new SVG.Matrix(1, 2, 3, 4, 5, 6).translate()
+ expect(matrix.e).toBe(5)
+ expect(matrix.f).toBe(6)
+ })
})
describe('scale()', function() {
@@ -248,51 +229,59 @@ describe('Matrix', function() {
expect(matrix.a).toBe(3)
expect(matrix.d).toBe(3)
- expect(matrix.e).toBe(4)
- expect(matrix.f).toBe(3)
+ expect(matrix.e).toBe(4 * 3)
+ expect(matrix.f).toBe(3 * 3)
})
it('performs a non-uniformal scale with two values', function() {
var matrix = new SVG.Matrix(1, 0, 0, 1, 4, 3).scale(2.5, 3.5)
expect(matrix.a).toBe(2.5)
expect(matrix.d).toBe(3.5)
- expect(matrix.e).toBe(4)
- expect(matrix.f).toBe(3)
+ expect(matrix.e).toBe(4 * 2.5)
+ expect(matrix.f).toBe(3 * 3.5)
})
it('performs a uniformal scale at a given center point with three values', function() {
- var matrix = new SVG.Matrix(1, 0, 0, 1, 4, 3).scale(3, 150, 100)
+ var matrix = new SVG.Matrix(1, 3, 2, 3, 4, 3).scale(3, 2, 3)
expect(matrix.a).toBe(3)
- expect(matrix.d).toBe(3)
- expect(matrix.e).toBe(-296)
- expect(matrix.f).toBe(-197)
+ expect(matrix.b).toBe(9)
+ expect(matrix.c).toBe(6)
+ expect(matrix.d).toBe(9)
+ expect(matrix.e).toBe(8)
+ expect(matrix.f).toBe(3)
})
it('performs a non-uniformal scale at a given center point with four values', function() {
- var matrix = new SVG.Matrix(1, 0, 0, 1, 4, 3).scale(3, 2, 150, 100)
+ var matrix = new SVG.Matrix(1, 3, 2, 3, 4, 3).scale(3, 2, 2, 3)
expect(matrix.a).toBe(3)
- expect(matrix.d).toBe(2)
- expect(matrix.e).toBe(-296)
- expect(matrix.f).toBe(-97)
+ expect(matrix.b).toBe(6)
+ expect(matrix.c).toBe(6)
+ expect(matrix.d).toBe(6)
+ expect(matrix.e).toBe(8)
+ expect(matrix.f).toBe(3)
})
})
describe('rotate()', function() {
it('performs a rotation with one argument', function() {
- var matrix = new SVG.Matrix(1, 0, 0, 1, 4, 3).rotate(30)
+ var matrix = new SVG.Matrix(1, 3, 2, 3, 4, 3).rotate(30)
- expect(matrix.a).toBeCloseTo(0.8660254037844387)
- expect(matrix.d).toBeCloseTo(0.8660254037844387)
- expect(matrix.e).toBe(4)
- expect(matrix.f).toBe(3)
+ expect(matrix.a).toBeCloseTo(-0.6339746)
+ expect(matrix.b).toBeCloseTo(3.09807621)
+ expect(matrix.c).toBeCloseTo(0.23205081)
+ expect(matrix.d).toBeCloseTo(3.59807621)
+ expect(matrix.e).toBeCloseTo(1.96410162)
+ expect(matrix.f).toBeCloseTo(4.59807621)
})
- it('performs a rotation on a given point with three arguments', function() {
- var matrix = new SVG.Matrix(1, 0, 0, 1, 4, 3).rotate(30, 150, 100)
+ it('performs a rotation around a given point with three arguments', function() {
+ var matrix = new SVG.Matrix(1, 3, 2, 3, 4, 3).rotate(30, 2, 3)
- expect(matrix.a).toBeCloseTo(0.8660254037844387)
- expect(matrix.d).toBeCloseTo(0.8660254037844387)
- expect(matrix.e).toBeCloseTo(74.0961894323342)
- expect(matrix.f).toBeCloseTo(-58.60254037844388)
+ expect(matrix.a).toBeCloseTo(-0.633974596216)
+ expect(matrix.b).toBeCloseTo(3.09807621135)
+ expect(matrix.c).toBeCloseTo(0.232050807569)
+ expect(matrix.d).toBeCloseTo(3.59807621135)
+ expect(matrix.e).toBeCloseTo(3.73205080757)
+ expect(matrix.f).toBeCloseTo(4.0)
})
})
@@ -303,7 +292,7 @@ describe('Matrix', function() {
expect(matrix.a).toBe(-1)
expect(matrix.d).toBe(1)
- expect(matrix.e).toBe(4)
+ expect(matrix.e).toBe(-4)
expect(matrix.f).toBe(3)
})
it('performs a flip over the horizontal axis over a given point with two arguments', function() {
@@ -311,7 +300,7 @@ describe('Matrix', function() {
expect(matrix.a).toBe(-1)
expect(matrix.d).toBe(1)
- expect(matrix.e).toBe(304)
+ expect(matrix.e).toBe(296)
expect(matrix.f).toBe(3)
})
})
@@ -322,7 +311,7 @@ describe('Matrix', function() {
expect(matrix.a).toBe(1)
expect(matrix.d).toBe(-1)
expect(matrix.e).toBe(4)
- expect(matrix.f).toBe(3)
+ expect(matrix.f).toBe(-3)
})
it('performs a flip over the vertical axis over a given point with two arguments', function() {
var matrix = new SVG.Matrix(1, 0, 0, 1, 4, 3).flip('y', 100)
@@ -330,7 +319,7 @@ describe('Matrix', function() {
expect(matrix.a).toBe(1)
expect(matrix.d).toBe(-1)
expect(matrix.e).toBe(4)
- expect(matrix.f).toBe(203)
+ expect(matrix.f).toBe(197)
})
})
describe('with no axis given', function() {
@@ -339,126 +328,129 @@ describe('Matrix', function() {
expect(matrix.a).toBe(-1)
expect(matrix.d).toBe(-1)
- expect(matrix.e).toBe(4)
- expect(matrix.f).toBe(3)
+ expect(matrix.e).toBe(-4)
+ expect(matrix.f).toBe(-3)
})
it('performs a flip over the horizontal and vertical axis over a given point with one argument that represent both coordinates', function() {
var matrix = new SVG.Matrix(1, 0, 0, 1, 4, 3).flip(100)
expect(matrix.a).toBe(-1)
expect(matrix.d).toBe(-1)
- expect(matrix.e).toBe(204)
- expect(matrix.f).toBe(203)
+ expect(matrix.e).toBe(196)
+ expect(matrix.f).toBe(197)
})
it('performs a flip over the horizontal and vertical axis over a given point with two arguments', function() {
var matrix = new SVG.Matrix(1, 0, 0, 1, 4, 3).flip(50, 100)
expect(matrix.a).toBe(-1)
expect(matrix.d).toBe(-1)
- expect(matrix.e).toBe(104)
- expect(matrix.f).toBe(203)
+ expect(matrix.e).toBe(96)
+ expect(matrix.f).toBe(197)
})
})
})
describe('skew()', function() {
it('performs a uniformal skew with one value', function() {
- var matrix = new SVG.Matrix(1, 0, 0, 1, 4, 3).skew(14)
+ var matrix = new SVG.Matrix(1, 0, 0, 1, 4, 3).skew(30)
expect(matrix.a).toBe(1)
- expect(matrix.b).toBeCloseTo(0.24932800284318)
- expect(matrix.c).toBeCloseTo(0.24932800284318)
+ expect(matrix.b).toBeCloseTo(0.57735026919)
+ expect(matrix.c).toBeCloseTo(0.57735026919)
expect(matrix.d).toBe(1)
- expect(matrix.e).toBe(4)
- expect(matrix.f).toBe(3)
+ expect(matrix.e).toBeCloseTo(5.73205080757)
+ expect(matrix.f).toBeCloseTo(5.30940107676)
})
+
it('performs a non-uniformal skew with two values', function() {
- var matrix = new SVG.Matrix(1, 0, 0, 1, 4, 3).skew(8, 5)
+ var matrix = new SVG.Matrix(1, 0, 0, 1, 4, 3).skew(30, 20)
expect(matrix.a).toBe(1)
- expect(matrix.b).toBeCloseTo(0.087488663525924)
- expect(matrix.c).toBeCloseTo(0.14054083470239)
+ expect(matrix.b).toBeCloseTo(0.363970234266)
+ expect(matrix.c).toBeCloseTo(0.57735026919)
expect(matrix.d).toBe(1)
- expect(matrix.e).toBe(4)
- expect(matrix.f).toBe(3)
+ expect(matrix.e).toBeCloseTo(5.73205080757)
+ expect(matrix.f).toBeCloseTo(4.45588093706)
})
+
it('performs a uniformal skew at a given center point with three values', function() {
- var matrix = new SVG.Matrix(1, 0, 0, 1, 4, 3).skew(3, 150, 100)
+ var matrix = new SVG.Matrix(1, 0, 0, 1, 4, 3).skew(30, 150, 100)
expect(matrix.a).toBe(1)
- expect(matrix.b).toBeCloseTo(0.052407779283041)
- expect(matrix.c).toBeCloseTo(0.052407779283041)
+ expect(matrix.b).toBeCloseTo(0.57735026919)
+ expect(matrix.c).toBeCloseTo(0.57735026919)
expect(matrix.d).toBe(1)
- expect(matrix.e).toBeCloseTo(-1.2407779283)
- expect(matrix.f).toBeCloseTo(-4.8611668924562)
+ expect(matrix.e).toBeCloseTo(-52.0029761114)
+ expect(matrix.f).toBeCloseTo(-81.2931393017)
})
+
it('performs a non-uniformal skew at a given center point with four values', function() {
- var matrix = new SVG.Matrix(1, 0, 0, 1, 4, 3).skew(9, 7, 150, 100)
+ var matrix = new SVG.Matrix(1, 0, 0, 1, 4, 3).skew(30, 20, 150, 100)
- expect(matrix.a).toBe(1)
- expect(matrix.b).toBeCloseTo(0.1227845609029)
- expect(matrix.c).toBeCloseTo(0.15838444032454)
- expect(matrix.d).toBe(1)
- expect(matrix.e).toBeCloseTo(-11.83844403245)
- expect(matrix.f).toBeCloseTo(-15.417684135435)
+ expect(matrix.a).toBe(1.0)
+ expect(matrix.b).toBeCloseTo(0.363970234266)
+ expect(matrix.c).toBeCloseTo(0.57735026919)
+ expect(matrix.d).toBe(1.0)
+ expect(matrix.e).toBeCloseTo(-52.0029761114)
+ expect(matrix.f).toBeCloseTo(-50.1396542029)
})
- it('can be chained', function(){
- var matrix = new SVG.Matrix(1, 0, 0, 1, 4, 3).skew(9, 7).skew(20, 40)
- expect(matrix.a).toBeCloseTo(1.1329003254605)
- expect(matrix.b).toBeCloseTo(0.96188419208018)
- expect(matrix.c).toBeCloseTo(0.52235467459074)
- expect(matrix.d).toBeCloseTo(1.0446899253961)
- expect(matrix.e).toBe(4)
- expect(matrix.f).toBe(3)
+ it('can be chained', function(){
+ var matrix = new SVG.Matrix(1, 0, 0, 1, 4, 3).skew(20, 30).skew(30, 20)
+ expect(matrix.a).toBeCloseTo(1.33333333333)
+ expect(matrix.b).toBeCloseTo(0.941320503456)
+ expect(matrix.c).toBeCloseTo(0.941320503456)
+ expect(matrix.d).toBeCloseTo(1.13247433143)
+ expect(matrix.e).toBeCloseTo(8.1572948437)
+ expect(matrix.f).toBeCloseTo(7.16270500812)
})
})
describe('skewX', function(){
it('performs a skew along the x axis with one value', function() {
- var matrix = new SVG.Matrix(1, 0, 0, 1, 4, 3).skewX(12)
+ var matrix = new SVG.Matrix(1, 0, 0, 1, 4, 3).skewX(30)
expect(matrix.a).toBe(1)
expect(matrix.b).toBe(0)
- expect(matrix.c).toBeCloseTo(0.21255656167002)
+ expect(matrix.c).toBeCloseTo(0.57735026919)
expect(matrix.d).toBe(1)
- expect(matrix.e).toBe(4)
+ expect(matrix.e).toBeCloseTo(5.73205080757)
expect(matrix.f).toBe(3)
})
it('performs a skew along the x axis at a given center point with three values', function() {
- var matrix = new SVG.Matrix(1, 0, 0, 1, 4, 3).skewX(5, 150, 100)
+ var matrix = new SVG.Matrix(1, 0, 0, 1, 4, 3).skewX(30, 150, 100)
expect(matrix.a).toBe(1)
expect(matrix.b).toBe(0)
- expect(matrix.c).toBeCloseTo(0.087488663525924)
+ expect(matrix.c).toBeCloseTo(0.57735026919)
expect(matrix.d).toBe(1)
- expect(matrix.e).toBeCloseTo(-4.74886635259)
+ expect(matrix.e).toBeCloseTo(-52.0029761114)
expect(matrix.f).toBe(3)
})
})
describe('skewY', function(){
it('performs a skew along the y axis with one value', function() {
- var matrix = new SVG.Matrix(1, 0, 0, 1, 4, 3).skewY(12)
+ var matrix = new SVG.Matrix(1, 0, 0, 1, 4, 3).skewY(30)
expect(matrix.a).toBe(1)
- expect(matrix.b).toBeCloseTo(0.21255656167002)
+ expect(matrix.b).toBeCloseTo(0.57735026919)
expect(matrix.c).toBe(0)
expect(matrix.d).toBe(1)
expect(matrix.e).toBe(4)
- expect(matrix.f).toBe(3)
+ expect(matrix.f).toBeCloseTo(5.30940107676)
})
it('performs a skew along the y axis at a given center point with three values', function() {
- var matrix = new SVG.Matrix(1, 0, 0, 1, 4, 3).skewY(5, 150, 100)
+ var matrix = new SVG.Matrix(1, 0, 0, 1, 4, 3).skewY(30, 150, 100)
expect(matrix.a).toBe(1)
- expect(matrix.b).toBeCloseTo(0.087488663525924)
+ expect(matrix.b).toBeCloseTo(0.57735026919)
expect(matrix.c).toBe(0)
expect(matrix.d).toBe(1)
expect(matrix.e).toBe(4)
- expect(matrix.f).toBeCloseTo(-10.123299528889)
+ expect(matrix.f).toBeCloseTo(-81.2931393017)
})
})