From bee0f53c653169b9580db9e5fe26e8c05fa8b2ce Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Sat, 8 Mar 2025 12:19:56 +0100 Subject: [PATCH] Use the `MathClamp` helper function more (PR 19617 follow-up) There's a few spots that I accidentally missed in PR 19617. --- src/core/pattern.js | 11 +++++++---- src/core/xfa/layout.js | 5 +++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/core/pattern.js b/src/core/pattern.js index 033e72383..946c0c964 100644 --- a/src/core/pattern.js +++ b/src/core/pattern.js @@ -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; diff --git a/src/core/xfa/layout.js b/src/core/xfa/layout.js index e3442a24d..a7cdfd9b0 100644 --- a/src/core/xfa/layout.js +++ b/src/core/xfa/layout.js @@ -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;