1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-19 22:58:07 +02:00

Change Util.applyInverseTransform to use the point-argument as an in/out parameter

This will help reduce the total number of Array allocations, which cannot hurt.
This commit is contained in:
Jonas Jenwald 2025-04-01 23:03:44 +02:00
parent fa643bb22f
commit c852e877d8
2 changed files with 6 additions and 4 deletions

View file

@ -287,7 +287,9 @@ class PageViewport {
* @see {@link convertToViewportPoint}
*/
convertToPdfPoint(x, y) {
return Util.applyInverseTransform([x, y], this.transform);
const p = [x, y];
Util.applyInverseTransform(p, this.transform);
return p;
}
}

View file

@ -758,10 +758,10 @@ class Util {
}
static applyInverseTransform(p, m) {
const [p0, p1] = p;
const d = m[0] * m[3] - m[1] * m[2];
const xt = (p[0] * m[3] - p[1] * m[2] + m[2] * m[5] - m[4] * m[3]) / d;
const yt = (-p[0] * m[1] + p[1] * m[0] + m[4] * m[1] - m[5] * m[0]) / d;
return [xt, yt];
p[0] = (p0 * m[3] - p1 * m[2] + m[2] * m[5] - m[4] * m[3]) / d;
p[1] = (-p0 * m[1] + p1 * m[0] + m[4] * m[1] - m[5] * m[0]) / d;
}
// Applies the transform to the rectangle and finds the minimum axially