diff --git a/src/geometry/__tests__/transform.test.ts b/src/geometry/__tests__/transform.test.ts index 9a49acdb..ed4b30dc 100644 --- a/src/geometry/__tests__/transform.test.ts +++ b/src/geometry/__tests__/transform.test.ts @@ -34,6 +34,24 @@ test('compare result of clockwise rotation with opencv', () => { expect(transformed).toMatchImage('opencv/testClockwiseRot90.png'); }); +test('compare result of clockwise rotation with opencv and fullImage:true', () => { + const img = testUtils.load('opencv/test.png'); + const transformed = img.transform( + [ + [0, -1, img.width + 1], + [1, 0, 0], + ], + { + inverse: false, + fullImage: true, + borderType: 'constant', + borderValue: 0, + interpolationType: 'bilinear', + }, + ); + expect(transformed).toMatchImage('opencv/testClockwiseRot90.png'); +}); + test('compare result of anti-clockwise rotation with opencv', () => { const img = testUtils.load('opencv/test.png'); const transformed = img.transform( diff --git a/src/geometry/transform.ts b/src/geometry/transform.ts index ebf8ad93..3efff74c 100644 --- a/src/geometry/transform.ts +++ b/src/geometry/transform.ts @@ -62,6 +62,16 @@ export function transform( fullImage, } = options; let { width = image.width, height = image.height } = options; + + if (!isValidMatrix(transformMatrix)) { + throw new TypeError( + `transformation matrix must be 2x3 or 3x3. Received ${transformMatrix.length}x${transformMatrix[1].length}`, + ); + } + if (transformMatrix.length === 2) { + transformMatrix.push([0, 0, 1]); + } + if (fullImage) { transformMatrix = transformMatrix.map((row) => row.slice()); transformMatrix[0][2] = 0; @@ -126,15 +136,6 @@ export function transform( height = Math.round(height); } - if (!isValidMatrix(transformMatrix)) { - throw new TypeError( - `transformation matrix must be 2x3 or 3x3. Received ${transformMatrix.length}x${transformMatrix[1].length}`, - ); - } - if (transformMatrix.length === 2) { - transformMatrix.push([0, 0, 1]); - } - if (!options.inverse) { transformMatrix = inverse(new Matrix(transformMatrix)).to2DArray(); }