blob: d1be9ec8622975a43a02014b2f12810c1ee4cf98 [file] [log] [blame]
Kevin Lubick556350d2018-10-12 15:21:17 -04001
2
3describe('PathKit\'s Effects', function() {
4 // Note, don't try to print the PathKit object - it can cause Karma/Jasmine to lock up.
5 var PathKit = null;
6 const LoadPathKit = new Promise(function(resolve, reject) {
7 if (PathKit) {
8 resolve();
9 } else {
10 PathKitInit({
11 locateFile: (file) => '/pathkit/'+file,
12 }).then((_PathKit) => {
13 PathKit = _PathKit;
14 resolve();
15 });
16 }
17 });
18
19 // see https://fiddle.skia.org/c/@discrete_path
20 function drawStar(X=128, Y=128, R=116) {
21 let p = PathKit.NewPath();
22 p.moveTo(X + R, Y);
23 for (let i = 1; i < 8; i++) {
24 let a = 2.6927937 * i;
25 p.lineTo(X + R * Math.cos(a), Y + R * Math.sin(a));
26 }
27 p.closePath();
28 return p;
29 }
30
31 it('effects_dash', function(done) {
32 function setup(ctx) {
33 ctx.path = drawStar();
34 }
35
36 function test(ctx) {
37 let path = ctx.path.copy().dash(10, 3, 1);
38 path.delete();
39 }
40
41 function teardown(ctx) {
42 ctx.path.delete();
43 }
44
45 LoadPathKit.then(() => {
46 benchmarkAndReport('effects_dash', setup, test, teardown).then(() => {
47 done();
48 }).catch(reportError(done));
49 });
50 });
51
52 it('effects_trim', function(done) {
53 function setup(ctx) {
54 ctx.path = drawStar();
55 }
56
57 function test(ctx) {
58 let path = ctx.path.copy().trim(0.25, .8);
59 path.delete();
60 }
61
62 function teardown(ctx) {
63 ctx.path.delete();
64 }
65
66 LoadPathKit.then(() => {
67 benchmarkAndReport('effects_trim', setup, test, teardown).then(() => {
68 done();
69 }).catch(reportError(done));
70 });
71 });
72
73 it('effects_trim_complement', function(done) {
74 function setup(ctx) {
75 ctx.path = drawStar();
76 }
77
78 function test(ctx) {
79 let path = ctx.path.copy().trim(0.25, .8, true);
80 path.delete();
81 }
82
83 function teardown(ctx) {
84 ctx.path.delete();
85 }
86
87 LoadPathKit.then(() => {
88 benchmarkAndReport('effects_trim_complement', setup, test, teardown).then(() => {
89 done();
90 }).catch(reportError(done));
91 });
92 });
93
94 it('effects_transform', function(done) {
95 function setup(ctx) {
96 ctx.path = drawStar();
97 }
98
99 function test(ctx) {
100 let path = ctx.path.copy().transform(3, 0, 0,
101 0, 3, 0,
102 0, 0, 1);
103 path.delete();
104 }
105
106 function teardown(ctx) {
107 ctx.path.delete();
108 }
109
110 LoadPathKit.then(() => {
111 benchmarkAndReport('effects_transform', setup, test, teardown).then(() => {
112 done();
113 }).catch(reportError(done));
114 });
115 });
116
117 it('effects_stroke', function(done) {
118 function setup(ctx) {
119 ctx.path = drawStar();
120 }
121
122 function test(ctx) {
123 let path = ctx.path.copy().stroke({
124 width: 15,
125 join: PathKit.StrokeJoin.BEVEL,
126 cap: PathKit.StrokeCap.BUTT,
127 miter_limit: 2,
128 });
129 path.delete();
130 }
131
132 function teardown(ctx) {
133 ctx.path.delete();
134 }
135
136 LoadPathKit.then(() => {
137 benchmarkAndReport('effects_stroke', setup, test, teardown).then(() => {
138 done();
139 }).catch(reportError(done));
140 });
141 });
142
143});