Skip to content

Commit 4f349d8

Browse files
committed
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 #19825
1 parent bfc2025 commit 4f349d8

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

test/unit/util_spec.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ import {
2222
string32,
2323
stringToBytes,
2424
stringToPDFString,
25+
Util,
2526
} from "../../src/shared/util.js";
27+
import { DOMMatrix, DOMPoint } from "@napi-rs/canvas";
2628

2729
describe("util", function () {
2830
describe("BaseException", function () {
@@ -258,4 +260,28 @@ describe("util", function () {
258260
expect(uuid.length).toBeGreaterThanOrEqual(32);
259261
});
260262
});
263+
264+
describe("applyTransform", function () {
265+
it("should apply transformations correctly without subarray creation", async function () {
266+
const cases = [
267+
{ transform: [1, 0, 0, 1, 10, 20], points: [5, 5, 10, 10] }, // translation
268+
{ transform: [0.5, 0.3, -0.3, 0.5, -5, 5], points: [0, 0, 1, 1] }, // scale+shear+translate
269+
{ transform: [2, 0, 0, 2, 0, 0], points: [-2, 3, 4, -5] }, // simple doubling
270+
];
271+
272+
for (const { transform, points: original } of cases) {
273+
const M = new DOMMatrix(transform);
274+
const pts = original.slice();
275+
276+
const p0 = M.transformPoint(new DOMPoint(original[0], original[1]));
277+
const p1 = M.transformPoint(new DOMPoint(original[2], original[3]));
278+
const expected = [p0.x, p0.y, p1.x, p1.y];
279+
280+
Util.applyTransform(pts, transform, 0);
281+
Util.applyTransform(pts, transform, 2);
282+
283+
expect(pts).toEqual(expected);
284+
}
285+
});
286+
});
261287
});

0 commit comments

Comments
 (0)