• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1describe('PathKit\'s Effects', function() {
2
3    // see https://fiddle.skia.org/c/@discrete_path
4    function drawStar(X=128, Y=128, R=116) {
5        let p = PathKit.NewPath();
6        p.moveTo(X + R, Y);
7        for (let i = 1; i < 8; i++) {
8          let a = 2.6927937 * i;
9          p.lineTo(X + R * Math.cos(a), Y + R * Math.sin(a));
10        }
11        p.closePath();
12        return p;
13    }
14
15    it('effects_dash', function(done) {
16        function setup(ctx) {
17            ctx.path = drawStar();
18        }
19
20        function test(ctx) {
21            let path = ctx.path.copy().dash(10, 3, 1);
22            path.delete();
23        }
24
25        function teardown(ctx) {
26            ctx.path.delete();
27        }
28
29        LoadPathKit.then(() => {
30            benchmarkAndReport('effects_dash', setup, test, teardown).then(() => {
31                done();
32            }).catch(reportError(done));
33        });
34    });
35
36    it('effects_trim', function(done) {
37        function setup(ctx) {
38            ctx.path = drawStar();
39        }
40
41        function test(ctx) {
42            let path = ctx.path.copy().trim(0.25, .8);
43            path.delete();
44        }
45
46        function teardown(ctx) {
47            ctx.path.delete();
48        }
49
50        LoadPathKit.then(() => {
51            benchmarkAndReport('effects_trim', setup, test, teardown).then(() => {
52                done();
53            }).catch(reportError(done));
54        });
55    });
56
57    it('effects_trim_complement', function(done) {
58        function setup(ctx) {
59            ctx.path = drawStar();
60        }
61
62        function test(ctx) {
63            let path = ctx.path.copy().trim(0.25, .8, true);
64            path.delete();
65        }
66
67        function teardown(ctx) {
68            ctx.path.delete();
69        }
70
71        LoadPathKit.then(() => {
72            benchmarkAndReport('effects_trim_complement', setup, test, teardown).then(() => {
73                done();
74            }).catch(reportError(done));
75        });
76    });
77
78    it('effects_transform', function(done) {
79        function setup(ctx) {
80            ctx.path = drawStar();
81        }
82
83        function test(ctx) {
84            let path = ctx.path.copy().transform(3, 0, 0,
85                                             0, 3, 0,
86                                             0, 0, 1);
87            path.delete();
88        }
89
90        function teardown(ctx) {
91            ctx.path.delete();
92        }
93
94        LoadPathKit.then(() => {
95            benchmarkAndReport('effects_transform', setup, test, teardown).then(() => {
96                done();
97            }).catch(reportError(done));
98        });
99    });
100
101    it('effects_stroke', function(done) {
102        function setup(ctx) {
103            ctx.path = drawStar();
104        }
105
106        function test(ctx) {
107            let path = ctx.path.copy().stroke({
108                    width: 15,
109                    join: PathKit.StrokeJoin.BEVEL,
110                    cap: PathKit.StrokeCap.BUTT,
111                    miter_limit: 2,
112                });
113            path.delete();
114        }
115
116        function teardown(ctx) {
117            ctx.path.delete();
118        }
119
120        LoadPathKit.then(() => {
121            benchmarkAndReport('effects_stroke', setup, test, teardown).then(() => {
122                done();
123            }).catch(reportError(done));
124        });
125    });
126
127});