Skip to content

Commit e93497a

Browse files
authored
Simplify and fix flip (#879)
* Write missing tests for the Flip plugin * Remove broken code branch in Flip plugin Removing this unnecessary "shortcut": - Has no bad effect on complexity - Removes dependency on Rotate plugin - Fixes #829 - Actually shortens and simplifies the implementation
1 parent dd7a6ba commit e93497a

File tree

2 files changed

+99
-5
lines changed

2 files changed

+99
-5
lines changed

packages/plugin-flip/src/index.js

-5
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,6 @@ function flipFn(horizontal, vertical, cb) {
1515
cb
1616
);
1717

18-
if (horizontal && vertical) {
19-
// shortcut
20-
return this.rotate(180, true, cb);
21-
}
22-
2318
const bitmap = Buffer.alloc(this.bitmap.data.length);
2419
this.scanQuiet(0, 0, this.bitmap.width, this.bitmap.height, function(
2520
x,
+99
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
import { Jimp, mkJGD } from '@jimp/test-utils';
2+
3+
import configure from '@jimp/custom';
4+
5+
import flip from '../src';
6+
7+
const jimp = configure({ plugins: [flip] }, Jimp);
8+
9+
describe('Flipping plugin', () => {
10+
it('can flip horizontally', async () => {
11+
const src = await jimp.read(
12+
mkJGD(
13+
'AAAABBBB',
14+
'AAABAAAB',
15+
'ABABABAB',
16+
'CCCCCCCC',
17+
'CCCCCCCC',
18+
'CCCCCCCC',
19+
'AACCCCAA'
20+
)
21+
);
22+
23+
const result = src.flip(true, false);
24+
25+
result
26+
.getJGDSync()
27+
.should.be.sameJGD(
28+
mkJGD(
29+
'BBBBAAAA',
30+
'BAAABAAA',
31+
'BABABABA',
32+
'CCCCCCCC',
33+
'CCCCCCCC',
34+
'CCCCCCCC',
35+
'AACCCCAA'
36+
)
37+
);
38+
});
39+
40+
it('can flip vertically', async () => {
41+
const src = await jimp.read(
42+
mkJGD(
43+
'AAAABBBB',
44+
'AAABAAAB',
45+
'ABABABAB',
46+
'CCCCCCCC',
47+
'CCCCCCCC',
48+
'CCCCCCCC',
49+
'AACCCCAA'
50+
)
51+
);
52+
53+
const result = src.flip(false, true);
54+
55+
result
56+
.getJGDSync()
57+
.should.be.sameJGD(
58+
mkJGD(
59+
'AACCCCAA',
60+
'CCCCCCCC',
61+
'CCCCCCCC',
62+
'CCCCCCCC',
63+
'ABABABAB',
64+
'AAABAAAB',
65+
'AAAABBBB'
66+
)
67+
);
68+
});
69+
70+
it('can flip both horizontally and vertically at once', async () => {
71+
const src = await jimp.read(
72+
mkJGD(
73+
'AAAABBBB',
74+
'AAABAAAB',
75+
'ABABABAB',
76+
'CCCCCCCC',
77+
'CCCCCCCC',
78+
'CCCCCCCC',
79+
'AACCCCAA'
80+
)
81+
);
82+
83+
const result = src.flip(true, true);
84+
85+
result
86+
.getJGDSync()
87+
.should.be.sameJGD(
88+
mkJGD(
89+
'AACCCCAA',
90+
'CCCCCCCC',
91+
'CCCCCCCC',
92+
'CCCCCCCC',
93+
'BABABABA',
94+
'BAAABAAA',
95+
'BBBBAAAA'
96+
)
97+
);
98+
});
99+
});

0 commit comments

Comments
 (0)