Merge 4f349d80e633a813bf047f6d5bf5f1210f751a52 into ec71e4ed651e659b06a4fa46ef0b18ff9ab2a8c7
This commit is contained in:
commit
361c73d523
@ -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);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user