From 7f8731b03405f6780a57e53f446163c54962e98c Mon Sep 17 00:00:00 2001 From: EscapedGibbon Date: Tue, 1 Jul 2025 09:27:24 +0200 Subject: [PATCH 1/2] fix: fix bug with matrix size check --- src/geometry/transform.ts | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/geometry/transform.ts b/src/geometry/transform.ts index ebf8ad932..3efff74cf 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(); } From ff7ab8e5664e5220a35ba9552bc0c97707a54bc9 Mon Sep 17 00:00:00 2001 From: EscapedGibbon Date: Tue, 1 Jul 2025 09:27:51 +0200 Subject: [PATCH 2/2] test: add testing case for fullImage:true --- src/geometry/__tests__/transform.test.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/geometry/__tests__/transform.test.ts b/src/geometry/__tests__/transform.test.ts index 9a49acdba..ed4b30dc9 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(