blob: 0cafc384cf6e43f3254efaef0a71825abb526569 [file] [log] [blame]
Kevin Lubick644d8e72018-08-09 13:58:04 -04001
2describe('PathKit\'s Path Behavior', function() {
3 // Note, don't try to print the PathKit object - it can cause Karma/Jasmine to lock up.
4 var PathKit = null;
Kevin Lubick97d6d982018-08-10 15:53:16 -04005 const LoadPathKit = new Promise(function(resolve, reject) {
Kevin Lubick644d8e72018-08-09 13:58:04 -04006 if (PathKit) {
7 resolve();
8 } else {
9 PathKitInit({
Kevin Lubick97d6d982018-08-10 15:53:16 -040010 locateFile: (file) => '/pathkit/'+file,
Kevin Lubick644d8e72018-08-09 13:58:04 -040011 }).then((_PathKit) => {
12 PathKit = _PathKit;
13 resolve();
14 });
15 }
16 });
17
18 it('dynamically updates getBounds()', function(done){
19 LoadPathKit.then(() => {
20 // Based on test_bounds_crbug_513799
21 let path = PathKit.NewPath();
22 expect(path.getBounds()).toEqual(PathKit.MakeLTRBRect(0, 0, 0, 0));
23 path.moveTo(-5, -8);
24 expect(path.getBounds()).toEqual(PathKit.MakeLTRBRect(-5, -8, -5, -8));
25 path.rect(1, 2, 2, 2);
26 expect(path.getBounds()).toEqual(PathKit.MakeLTRBRect(-5, -8, 3, 4));
27 path.moveTo(1, 2);
28 expect(path.getBounds()).toEqual(PathKit.MakeLTRBRect(-5, -8, 3, 4));
29 path.delete();
30 done();
31 });
32 });
33
Kevin Lubick97d6d982018-08-10 15:53:16 -040034 function bits2float(str) {
35 return PathKit.SkBits2FloatUnsigned(parseInt(str))
36 }
37
Kevin Lubick644d8e72018-08-09 13:58:04 -040038 it('has getBounds() and computeTightBounds()', function(done){
39 LoadPathKit.then(() => {
40 // Based on PathOpsTightBoundsIllBehaved
41 let path = PathKit.NewPath();
42 path.moveTo(1, 1);
43 path.quadraticCurveTo(4, 3, 2, 2);
44 expect(path.getBounds()).toEqual(PathKit.MakeLTRBRect(1, 1, 4, 3));
45 expect(path.computeTightBounds()).toEqual(PathKit.MakeLTRBRect(1, 1,
Kevin Lubick97d6d982018-08-10 15:53:16 -040046 bits2float("0x40333334"), // 2.8
47 bits2float("0x40155556"))); // 2.3333333
Kevin Lubick644d8e72018-08-09 13:58:04 -040048 path.delete();
49
50 done();
51 });
52 });
53
Kevin Lubick97d6d982018-08-10 15:53:16 -040054 it('does NOT approximates conics when dumping as toCmds', function(done){
55 LoadPathKit.then(() => {
56 let path = PathKit.NewPath();
57 path.moveTo(20, 120);
58 path.arc(20, 120, 18, 0, 1.75 * Math.PI);
59 path.lineTo(20, 120);
60
61 let expectedCmds = [
62 [PathKit.MOVE_VERB, 20, 120],
63 [PathKit.LINE_VERB, 38, 120],
64 [PathKit.CONIC_VERB, 38, 138, 20, 138, bits2float("0x3f3504f3)")], // 0.707107f
65 [PathKit.CONIC_VERB, 2, 138, 2, 120, bits2float("0x3f3504f3)")], // 0.707107f
66 [PathKit.CONIC_VERB, 2, 102, 20, 102, bits2float("0x3f3504f3)")], // 0.707107f
67 [PathKit.CONIC_VERB, bits2float("0x41dba58e"), 102, bits2float("0x4202e962"), bits2float("0x42d68b4d"), bits2float("0x3f6c8361")], // 27.4558, 102, 32.7279, 107.272, 0.92388
68 [PathKit.LINE_VERB, 20, 120],
69 ];
70 let actual = path.toCmds();
71 expect(actual).toEqual(expectedCmds);
72
73 path.delete();
74 done();
75 });
76 });
77
Kevin Lubick644d8e72018-08-09 13:58:04 -040078});