Skip to content

Commit 59009fa

Browse files
fix: fix bug with transform function and fullImage:true (#487)
1 parent 1a96bf3 commit 59009fa

File tree

2 files changed

+28
-9
lines changed

2 files changed

+28
-9
lines changed

src/geometry/__tests__/transform.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,24 @@ test('compare result of clockwise rotation with opencv', () => {
3434
expect(transformed).toMatchImage('opencv/testClockwiseRot90.png');
3535
});
3636

37+
test('compare result of clockwise rotation with opencv and fullImage:true', () => {
38+
const img = testUtils.load('opencv/test.png');
39+
const transformed = img.transform(
40+
[
41+
[0, -1, img.width + 1],
42+
[1, 0, 0],
43+
],
44+
{
45+
inverse: false,
46+
fullImage: true,
47+
borderType: 'constant',
48+
borderValue: 0,
49+
interpolationType: 'bilinear',
50+
},
51+
);
52+
expect(transformed).toMatchImage('opencv/testClockwiseRot90.png');
53+
});
54+
3755
test('compare result of anti-clockwise rotation with opencv', () => {
3856
const img = testUtils.load('opencv/test.png');
3957
const transformed = img.transform(

src/geometry/transform.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,16 @@ export function transform(
6262
fullImage,
6363
} = options;
6464
let { width = image.width, height = image.height } = options;
65+
66+
if (!isValidMatrix(transformMatrix)) {
67+
throw new TypeError(
68+
`transformation matrix must be 2x3 or 3x3. Received ${transformMatrix.length}x${transformMatrix[1].length}`,
69+
);
70+
}
71+
if (transformMatrix.length === 2) {
72+
transformMatrix.push([0, 0, 1]);
73+
}
74+
6575
if (fullImage) {
6676
transformMatrix = transformMatrix.map((row) => row.slice());
6777
transformMatrix[0][2] = 0;
@@ -126,15 +136,6 @@ export function transform(
126136
height = Math.round(height);
127137
}
128138

129-
if (!isValidMatrix(transformMatrix)) {
130-
throw new TypeError(
131-
`transformation matrix must be 2x3 or 3x3. Received ${transformMatrix.length}x${transformMatrix[1].length}`,
132-
);
133-
}
134-
if (transformMatrix.length === 2) {
135-
transformMatrix.push([0, 0, 1]);
136-
}
137-
138139
if (!options.inverse) {
139140
transformMatrix = inverse(new Matrix(transformMatrix)).to2DArray();
140141
}

0 commit comments

Comments
 (0)