1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-19 14:48:08 +02:00

Use the MathClamp helper function more (PR 19617 follow-up)

There's a few spots that I accidentally missed in PR 19617.
This commit is contained in:
Jonas Jenwald 2025-03-08 12:19:56 +01:00
parent af89e77124
commit bee0f53c65
2 changed files with 10 additions and 6 deletions

View file

@ -18,6 +18,7 @@ import {
FormatError,
IDENTITY_MATRIX,
info,
MathClamp,
unreachable,
Util,
warn,
@ -843,17 +844,19 @@ class MeshShading extends BaseShading {
((figureMaxX - figureMinX) * MeshShading.TRIANGLE_DENSITY) /
(this.bounds[2] - this.bounds[0])
);
splitXBy = Math.max(
splitXBy = MathClamp(
splitXBy,
MeshShading.MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
Math.min(MeshShading.MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitXBy)
MeshShading.MAX_SPLIT_PATCH_CHUNKS_AMOUNT
);
let splitYBy = Math.ceil(
((figureMaxY - figureMinY) * MeshShading.TRIANGLE_DENSITY) /
(this.bounds[3] - this.bounds[1])
);
splitYBy = Math.max(
splitYBy = MathClamp(
splitYBy,
MeshShading.MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
Math.min(MeshShading.MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitYBy)
MeshShading.MAX_SPLIT_PATCH_CHUNKS_AMOUNT
);
const verticesPerRow = splitXBy + 1;

View file

@ -21,6 +21,7 @@ import {
$isSplittable,
$isThereMoreWidth,
} from "./symbol_utils.js";
import { MathClamp } from "../../shared/util.js";
import { measureToString } from "./html_utils.js";
// Subform and ExclGroup have a layout so they share these functions.
@ -141,7 +142,7 @@ function addHTML(node, html, bbox) {
break;
}
case "table": {
extra.width = Math.min(availableSpace.width, Math.max(extra.width, w));
extra.width = MathClamp(w, extra.width, availableSpace.width);
extra.height += h;
extra.children.push(html);
break;
@ -150,7 +151,7 @@ function addHTML(node, html, bbox) {
// Even if the subform can possibly take all the available width,
// we must compute the final width as it is in order to be able
// for example to center the subform within its parent.
extra.width = Math.min(availableSpace.width, Math.max(extra.width, w));
extra.width = MathClamp(w, extra.width, availableSpace.width);
extra.height += h;
extra.children.push(html);
break;