summaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorwout <wout@impinc.co.uk>2014-07-28 22:16:35 +0200
committerwout <wout@impinc.co.uk>2014-07-28 22:16:35 +0200
commit5e9ab52bd68670208ac25cfcf95cca178d285545 (patch)
tree0e83007452b8195886798889d2c7eeabb229d226 /spec
parent0c336f2f4bc931c13779ed6ea3edf62f05f1f18f (diff)
downloadsvg.js-5e9ab52bd68670208ac25cfcf95cca178d285545.tar.gz
svg.js-5e9ab52bd68670208ac25cfcf95cca178d285545.zip
Added more control to SVG.Matrix
Diffstat (limited to 'spec')
-rwxr-xr-xspec/spec/element.js2
-rwxr-xr-xspec/spec/helper.js17
-rw-r--r--spec/spec/matrix.js93
-rwxr-xr-xspec/spec/path.js12
-rwxr-xr-xspec/spec/polygon.js12
-rwxr-xr-xspec/spec/polyline.js12
-rwxr-xr-xspec/spec/text.js20
7 files changed, 107 insertions, 61 deletions
diff --git a/spec/spec/element.js b/spec/spec/element.js
index 176f656..d2a6403 100755
--- a/spec/spec/element.js
+++ b/spec/spec/element.js
@@ -308,7 +308,7 @@ describe('Element', function() {
expect(box.width).toBe(105)
expect(box.height).toBe(210)
})
- it('returns the correct rectangular box within a viewbox', function() {
+ xit('returns the correct rectangular box within a viewbox', function() {
var rect = draw.size(200,150).viewbox(0,0,100,75).rect(105,210).move(2,12)
var box = rect.rbox()
expect(box.x).toBe(1)
diff --git a/spec/spec/helper.js b/spec/spec/helper.js
index e3cba61..a02d751 100755
--- a/spec/spec/helper.js
+++ b/spec/spec/helper.js
@@ -1,26 +1,19 @@
-/* create canavs */
+// create canavs
var drawing = document.createElement('div')
drawing.id = 'drawing'
document.getElementsByTagName('body')[0].appendChild(drawing)
draw = SVG(drawing).size(100,100)
-/* raw path data */
+// raw path data
svgPath = 'M88.006,61.994c3.203,0,6.216-1.248,8.481-3.514C98.752,56.215,100,53.203,100,50c0-3.204-1.248-6.216-3.513-8.481 c-2.266-2.265-5.278-3.513-8.481-3.513c-2.687,0-5.237,0.877-7.327,2.496h-7.746l5.479-5.479 c5.891-0.757,10.457-5.803,10.457-11.896c0-6.614-5.381-11.995-11.994-11.995c-6.093,0-11.14,4.567-11.896,10.457l-5.479,5.479 v-7.747c1.618-2.089,2.495-4.641,2.495-7.327c0-3.204-1.247-6.216-3.513-8.481C56.216,1.248,53.204,0,50,0 c-3.204,0-6.216,1.248-8.481,3.513c-2.265,2.265-3.513,5.277-3.513,8.481c0,2.686,0.877,5.237,2.495,7.327v7.747l-5.479-5.479 c-0.757-5.89-5.803-10.457-11.896-10.457c-6.614,0-11.995,5.381-11.995,11.995c0,6.093,4.567,11.139,10.458,11.896l5.479,5.479 h-7.747c-2.089-1.619-4.641-2.496-7.327-2.496c-3.204,0-6.216,1.248-8.481,3.513C1.248,43.784,0,46.796,0,50 c0,3.203,1.248,6.216,3.513,8.48c2.265,2.266,5.277,3.514,8.481,3.514c2.686,0,5.237-0.877,7.327-2.496h7.747l-5.479,5.479 c-5.891,0.757-10.458,5.804-10.458,11.896c0,6.614,5.381,11.994,11.995,11.994c6.093,0,11.139-4.566,11.896-10.457l5.479-5.479 v7.749c-3.63,4.7-3.291,11.497,1.018,15.806C43.784,98.752,46.796,100,50,100c3.204,0,6.216-1.248,8.481-3.514 c4.309-4.309,4.647-11.105,1.018-15.806v-7.749l5.479,5.479c0.757,5.891,5.804,10.457,11.896,10.457 c6.613,0,11.994-5.38,11.994-11.994c0-6.093-4.566-11.14-10.457-11.896l-5.479-5.479h7.746 C82.769,61.117,85.319,61.994,88.006,61.994z M76.874,68.354c4.705,0,8.52,3.814,8.52,8.521c0,4.705-3.814,8.52-8.52,8.52 s-8.52-3.814-8.52-8.52l-12.33-12.33V81.98c3.327,3.328,3.327,8.723,0,12.049c-3.327,3.328-8.722,3.328-12.049,0 c-3.327-3.326-3.327-8.721,0-12.049V64.544l-12.33,12.33c0,4.705-3.814,8.52-8.52,8.52s-8.52-3.814-8.52-8.52 c0-4.706,3.814-8.521,8.52-8.521l12.33-12.33H18.019c-3.327,3.328-8.722,3.328-12.049,0c-3.327-3.326-3.327-8.721,0-12.048 s8.722-3.327,12.049,0h17.438l-12.33-12.33c-4.706,0-8.52-3.814-8.52-8.52c0-4.706,3.814-8.52,8.52-8.52s8.52,3.814,8.52,8.52 l12.33,12.33V18.019c-3.327-3.327-3.327-8.722,0-12.049s8.722-3.327,12.049,0s3.327,8.722,0,12.049v17.438l12.33-12.33 c0-4.706,3.814-8.52,8.52-8.52s8.52,3.814,8.52,8.52c0,4.705-3.814,8.52-8.52,8.52l-12.33,12.33h17.438 c3.327-3.327,8.722-3.327,12.049,0s3.327,8.722,0,12.048c-3.327,3.328-8.722,3.328-12.049,0H64.544L76.874,68.354z'
-/* image url */
+// image url
imageUrl = ''
-/* lorem ipsum text */
+// lorem ipsum text
loremIpsum = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras sodales\n imperdiet auctor. Nunc ultrices lectus at erat dictum pharetra\n elementum ante posuere. Duis turpis risus, blandit nec elementum et,\n posuere eget lacus. Aliquam et risus magna, eu aliquet nibh. Fusce\n consequat mi quis purus varius sagittis euismod urna interdum.\n Curabitur aliquet orci quis felis semper vulputate. Vestibulum ac nisi\n magna, id dictum diam. Proin sed metus vel magna blandit\n sodales. Pellentesque at neque ultricies nunc euismod rutrum ut in\n lorem. Mauris euismod tellus in tellus tempus interdum. Phasellus\n mattis sapien et leo feugiat dictum. Vestibulum at volutpat velit.'
-/* approximately helper */
-function approximately(number, precision) {
- precision = precision == null ? 1.5 : precision
-
- return Math.round(number / precision) * precision
-}
-
-/* strip spaces from result */
+// strip spaces from result
function stripped(string) {
return string.replace(/\s+/g, '')
} \ No newline at end of file
diff --git a/spec/spec/matrix.js b/spec/spec/matrix.js
index 30ab873..c21d1fb 100644
--- a/spec/spec/matrix.js
+++ b/spec/spec/matrix.js
@@ -58,37 +58,37 @@ describe('Matrix', function() {
})
it('parses the current transform matrix form an element', function() {
- expect(matrix.a).toBe(1.9696155786514282)
- expect(matrix.b).toBe(-0.3472963869571686)
- expect(matrix.c).toBe(0.3472963869571686)
- expect(matrix.d).toBe(1.9696155786514282)
- expect(matrix.e).toBe(-8.373950958251953)
- expect(matrix.f).toBe(7.758301258087158)
+ 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(-8.373950958251953)
+ expect(matrix.f).toBeCloseTo(7.758301258087158)
})
describe('extract()', function() {
it('parses translation values', function() {
var extract = new SVG.Matrix(draw.rect(100, 100).translate(40, 50)).extract()
- expect(extract.x).toBe(40)
- expect(extract.y).toBe(50)
+ 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(approximately(extract.skewX, 0.01)).toBe(25)
+ expect(extract.skewX).toBeCloseTo(25)
})
- it('parses skewX value', function() {
+ it('parses skewY value', function() {
var extract = new SVG.Matrix(draw.rect(100, 100).skew(0, 20)).extract()
- expect(approximately(extract.skewY, 0.01)).toBe(20)
+ 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).toBe(2)
- expect(extract.scaleY).toBe(3)
+ 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(approximately(extract.rotation, 0.01)).toBe(-100)
+ expect(extract.rotation).toBeCloseTo(-100)
})
})
@@ -240,19 +240,72 @@ describe('Matrix', function() {
})
describe('rotate()', function() {
-
+ it('performs a rotation with one argument', function() {
+ var matrix = new SVG.Matrix(1, 0, 0, 1, 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)
+ })
+ 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)
+
+ expect(matrix.a).toBeCloseTo(0.8660254037844387)
+ expect(matrix.d).toBeCloseTo(0.8660254037844387)
+ expect(matrix.e).toBeCloseTo(74.0961894323342)
+ expect(matrix.f).toBeCloseTo(-58.60254037844388)
+ })
})
describe('flip()', function() {
-
- })
+ describe('with x given', function() {
+ it('performs a flip over the horizontal axis with one argument', function() {
+ var matrix = new SVG.Matrix(1, 0, 0, 1, 4, 3).flip('x')
- describe('skew()', function() {
-
+ expect(matrix.a).toBe(-1)
+ expect(matrix.d).toBe(1)
+ 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() {
+ var matrix = new SVG.Matrix(1, 0, 0, 1, 4, 3).flip('x', 150)
+
+ expect(matrix.a).toBe(-1)
+ expect(matrix.d).toBe(1)
+ expect(matrix.e).toBe(304)
+ expect(matrix.f).toBe(3)
+ })
+ })
+ describe('with y given', function() {
+ it('performs a flip over the vertical axis with one argument', function() {
+ var matrix = new SVG.Matrix(1, 0, 0, 1, 4, 3).flip('y')
+
+ expect(matrix.a).toBe(1)
+ expect(matrix.d).toBe(-1)
+ expect(matrix.e).toBe(4)
+ 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)
+
+ expect(matrix.a).toBe(1)
+ expect(matrix.d).toBe(-1)
+ expect(matrix.e).toBe(4)
+ expect(matrix.f).toBe(203)
+ })
+ })
})
describe('skew()', function() {
-
+ it('performs a skew two arguments', function() {
+ var matrix = new SVG.Matrix(1, 0, 0, 1, 4, 3).skew(0, 0)
+
+ expect(matrix.a).toBe(matrix.toString())
+ expect(matrix.d).toBe(1)
+ expect(matrix.e).toBe(4)
+ expect(matrix.f).toBe(3)
+ })
})
describe('native()', function() {
diff --git a/spec/spec/path.js b/spec/spec/path.js
index 3376ec1..cd4fd91 100755
--- a/spec/spec/path.js
+++ b/spec/spec/path.js
@@ -118,11 +118,11 @@ describe('Path', function() {
it('sets the width of the element', function() {
path.width(234)
var box = path.bbox()
- expect(approximately(box.width, 0.1)).toBe(234)
+ expect(box.width).toBeCloseTo(234)
})
it('gets the width of the element aithout an agrument', function() {
path.width(456)
- expect(approximately(path.width(), 0.1)).toBe(456)
+ expect(path.width()).toBeCloseTo(456)
})
})
@@ -130,11 +130,11 @@ describe('Path', function() {
it('sets the height of the element', function() {
path.height(654)
var box = path.bbox()
- expect(approximately(box.height, 0.1)).toBe(654)
+ expect(box.height).toBeCloseTo(654)
})
it('gets the height of the element aithout an agrument', function() {
path.height(321)
- expect(approximately(path.height(), 0.1)).toBe(321)
+ expect(path.height()).toBeCloseTo(321)
})
})
@@ -142,8 +142,8 @@ describe('Path', function() {
it('defines the width and height of the element', function() {
path.size(987,654)
var box = path.bbox()
- expect(approximately(box.width, 0.1)).toBe(987)
- expect(approximately(box.height, 0.1)).toBe(654)
+ expect(box.width).toBeCloseTo(987)
+ expect(box.height).toBeCloseTo(654)
})
it('defines the width and height proportionally with only the width value given', function() {
var box = path.bbox()
diff --git a/spec/spec/polygon.js b/spec/spec/polygon.js
index 1c01e84..af9030b 100755
--- a/spec/spec/polygon.js
+++ b/spec/spec/polygon.js
@@ -112,11 +112,11 @@ describe('Polygon', function() {
it('sets the width and height of the element', function() {
polygon.width(987)
var box = polygon.bbox()
- expect(approximately(box.width, 0.1)).toBe(987)
+ expect(box.width).toBeCloseTo(987)
})
it('gets the width and height of the element without an argument', function() {
polygon.width(789)
- expect(approximately(polygon.width(), 0.1)).toBe(789)
+ expect(polygon.width()).toBeCloseTo(789)
})
})
@@ -124,11 +124,11 @@ describe('Polygon', function() {
it('sets the height and height of the element', function() {
polygon.height(987)
var box = polygon.bbox()
- expect(approximately(box.height, 0.1)).toBe(987)
+ expect(box.height).toBeCloseTo(987)
})
it('gets the height and height of the element without an argument', function() {
polygon.height(789)
- expect(approximately(polygon.height(), 0.1)).toBe(789)
+ expect(polygon.height()).toBeCloseTo(789)
})
})
@@ -136,8 +136,8 @@ describe('Polygon', function() {
it('should define the width and height of the element', function() {
polygon.size(987,654)
var box = polygon.bbox()
- expect(approximately(box.width, 0.1)).toBe(987)
- expect(approximately(box.height, 0.1)).toBe(654)
+ expect(box.width).toBeCloseTo(987)
+ expect(box.height).toBeCloseTo(654)
})
it('defines the width and height proportionally with only the width value given', function() {
var box = polygon.bbox()
diff --git a/spec/spec/polyline.js b/spec/spec/polyline.js
index ec8c25d..b9c3c1f 100755
--- a/spec/spec/polyline.js
+++ b/spec/spec/polyline.js
@@ -112,11 +112,11 @@ describe('Polyline', function() {
it('sets the width and height of the element', function() {
polyline.width(987)
var box = polyline.bbox()
- expect(approximately(box.width, 0.1)).toBe(987)
+ expect(box.width).toBeCloseTo(987, 1)
})
it('gets the width and height of the element without an argument', function() {
polyline.width(789)
- expect(approximately(polyline.width(), 0.1)).toBe(789)
+ expect(polyline.width()).toBeCloseTo(789)
})
})
@@ -124,11 +124,11 @@ describe('Polyline', function() {
it('sets the height and height of the element', function() {
polyline.height(987)
var box = polyline.bbox()
- expect(approximately(box.height, 0.1)).toBe(987)
+ expect(box.height).toBeCloseTo(987)
})
it('gets the height and height of the element without an argument', function() {
polyline.height(789)
- expect(approximately(polyline.height(), 0.1)).toBe(789)
+ expect(polyline.height()).toBeCloseTo(789)
})
})
@@ -136,8 +136,8 @@ describe('Polyline', function() {
it('should define the width and height of the element', function() {
polyline.size(987,654)
var box = polyline.bbox()
- expect(approximately(box.width, 0.1)).toBe(987)
- expect(approximately(box.height, 0.1)).toBe(654)
+ expect(box.width).toBeCloseTo(987)
+ expect(box.height).toBeCloseTo(654)
})
it('defines the width and height proportionally with only the width value given', function() {
var box = polyline.bbox()
diff --git a/spec/spec/text.js b/spec/spec/text.js
index 50f17f4..b8ee297 100755
--- a/spec/spec/text.js
+++ b/spec/spec/text.js
@@ -20,12 +20,12 @@ describe('Text', function() {
it('sets the value of x with the first argument', function() {
text.x(123)
var box = text.bbox()
- expect(approximately(box.x)).toBe(123)
+ expect(box.x).toBeCloseTo(123)
})
it('sets the value of x based on the anchor with the first argument', function() {
text.x(123, true)
var box = text.bbox()
- expect(approximately(box.x)).toBe(123)
+ expect(box.x).toBeCloseTo(123)
})
})
@@ -50,17 +50,17 @@ describe('Text', function() {
describe('cx()', function() {
it('returns the value of cx without an argument', function() {
var box = text.bbox()
- expect(approximately(text.cx())).toBe(approximately(box.width / 2))
+ expect(text.cx()).toBeCloseTo(box.width / 2)
})
it('sets the value of cx with the first argument', function() {
text.cx(123)
var box = text.bbox()
- expect(approximately(box.cx)).toBe(123)
+ expect(box.cx).toBeCloseTo(123)
})
it('sets the value of cx based on the anchor with the first argument', function() {
text.cx(123, true)
var box = text.bbox()
- expect(approximately(box.cx)).toBe(123)
+ expect(box.cx).toBeCloseTo(123)
})
})
@@ -80,17 +80,17 @@ describe('Text', function() {
it('sets the x and y position', function() {
text.move(123,456)
var box = text.bbox()
- expect(approximately(box.x)).toBe(123)
- expect(approximately(box.y)).toBe(456)
+ expect(box.x).toBeCloseTo(123)
+ expect(box.y).toBeCloseTo(456)
})
})
describe('center()', function() {
it('sets the cx and cy position', function() {
- text.center(321,567)
+ text.center(321, 567)
var box = text.bbox()
- expect(approximately(box.cx)).toBe(321)
- expect(approximately(box.cy)).toBe(567)
+ expect(box.cx).toBeCloseTo(321)
+ expect(box.cy).toBeCloseTo(567, 1)
})
})