Skip to content

Commit 0ad4820

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 0ad4820

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,6 +22,7 @@ import {
2222
string32,
2323
stringToBytes,
2424
stringToPDFString,
25+
Util,
2526
} from "../../src/shared/util.js";
2627

2728
describe("util", function () {
@@ -258,4 +259,29 @@ describe("util", function () {
258259
expect(uuid.length).toBeGreaterThanOrEqual(32);
259260
});
260261
});
262+
263+
describe("applyTransform", function () {
264+
it("should apply transformations correctly without subarray creation", async function () {
265+
const cases = [
266+
{ transform: [1, 0, 0, 1, 10, 20], points: [5, 5, 10, 10] }, // translation
267+
{ transform: [0.5, 0.3, -0.3, 0.5, -5, 5], points: [0, 0, 1, 1] }, // scale+shear+translate
268+
{ transform: [2, 0, 0, 2, 0, 0], points: [-2, 3, 4, -5] }, // simple doubling
269+
];
270+
271+
for (const { transform, points: original } of cases) {
272+
const pts = original.slice();
273+
274+
const [a, b, c, d, e, f] = transform;
275+
const ex0x = a * original[0] + c * original[1] + e;
276+
const ex0y = b * original[0] + d * original[1] + f;
277+
const ex1x = a * original[2] + c * original[3] + e;
278+
const ex1y = b * original[2] + d * original[3] + f;
279+
const expected = [ex0x, ex0y, ex1x, ex1y];
280+
281+
Util.applyTransform(pts, transform, 0);
282+
Util.applyTransform(pts, transform, 2);
283+
expect(pts).toEqual(expected);
284+
}
285+
});
286+
});
261287
});

0 commit comments

Comments
 (0)