Add regression test for in-place transformations

Verify that 2×3 transformation matrices (translation, scale, shear) are applied in-place to multiple point pairs without creating subarrays.

See PR https://github.com/mozilla/pdf.js/pull/19825
This commit is contained in:
maettuu 2025-07-20 14:46:21 +02:00
parent bfc20250b2
commit 4f349d80e6

View File

@ -22,7 +22,9 @@ import {
string32, string32,
stringToBytes, stringToBytes,
stringToPDFString, stringToPDFString,
Util,
} from "../../src/shared/util.js"; } from "../../src/shared/util.js";
import { DOMMatrix, DOMPoint } from "@napi-rs/canvas";
describe("util", function () { describe("util", function () {
describe("BaseException", function () { describe("BaseException", function () {
@ -258,4 +260,28 @@ describe("util", function () {
expect(uuid.length).toBeGreaterThanOrEqual(32); expect(uuid.length).toBeGreaterThanOrEqual(32);
}); });
}); });
describe("applyTransform", function () {
it("should apply transformations correctly without subarray creation", async function () {
const cases = [
{ transform: [1, 0, 0, 1, 10, 20], points: [5, 5, 10, 10] }, // translation
{ transform: [0.5, 0.3, -0.3, 0.5, -5, 5], points: [0, 0, 1, 1] }, // scale+shear+translate
{ transform: [2, 0, 0, 2, 0, 0], points: [-2, 3, 4, -5] }, // simple doubling
];
for (const { transform, points: original } of cases) {
const M = new DOMMatrix(transform);
const pts = original.slice();
const p0 = M.transformPoint(new DOMPoint(original[0], original[1]));
const p1 = M.transformPoint(new DOMPoint(original[2], original[3]));
const expected = [p0.x, p0.y, p1.x, p1.y];
Util.applyTransform(pts, transform, 0);
Util.applyTransform(pts, transform, 2);
expect(pts).toEqual(expected);
}
});
});
}); });