Skip to content

Commit 1bd4c4f

Browse files
Merge pull request #21026 from Snuffleupagus/more-MathClamp
Use the `MathClamp` helper function more
2 parents e37709e + c012ff6 commit 1bd4c4f

2 files changed

Lines changed: 8 additions & 18 deletions

File tree

src/core/postscript/js_evaluator.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
PS_VALUE_TYPE,
2020
PSStackToTree,
2121
} from "./ast.js";
22+
import { MathClamp } from "../../shared/util.js";
2223
import { TOKEN } from "./lexer.js";
2324

2425
// Consecutive integers for a dense jump table in _execute.
@@ -341,7 +342,7 @@ class PsJsCompiler {
341342
const slot = ir[ip++] | 0;
342343
const min = ir[ip++];
343344
const max = ir[ip++];
344-
dest[destOffset + slot] = Math.max(Math.min(stack[--sp], max), min);
345+
dest[destOffset + slot] = MathClamp(stack[--sp], min, max);
345346
break;
346347
}
347348
case OP.IF: {

src/display/canvas_dependency_tracker.js

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* limitations under the License.
1414
*/
1515

16-
import { FeatureTest, Util } from "../shared/util.js";
16+
import { FeatureTest, MathClamp, Util } from "../shared/util.js";
1717

1818
const FORCED_DEPENDENCY_LABEL = "__forcedDependency";
1919

@@ -257,22 +257,11 @@ class CanvasBBoxTracker {
257257

258258
const bbox = [Infinity, Infinity, -Infinity, -Infinity];
259259
Util.axialAlignedBoundingBox([minX, minY, maxX, maxY], transform, bbox);
260-
this.#pendingBBox[0] = Math.min(
261-
this.#pendingBBox[0],
262-
Math.max(bbox[0], clipBox[0])
263-
);
264-
this.#pendingBBox[1] = Math.min(
265-
this.#pendingBBox[1],
266-
Math.max(bbox[1], clipBox[1])
267-
);
268-
this.#pendingBBox[2] = Math.max(
269-
this.#pendingBBox[2],
270-
Math.min(bbox[2], clipBox[2])
271-
);
272-
this.#pendingBBox[3] = Math.max(
273-
this.#pendingBBox[3],
274-
Math.min(bbox[3], clipBox[3])
275-
);
260+
261+
this.#pendingBBox[0] = MathClamp(bbox[0], clipBox[0], this.#pendingBBox[0]);
262+
this.#pendingBBox[1] = MathClamp(bbox[1], clipBox[1], this.#pendingBBox[1]);
263+
this.#pendingBBox[2] = MathClamp(bbox[2], this.#pendingBBox[2], clipBox[2]);
264+
this.#pendingBBox[3] = MathClamp(bbox[3], this.#pendingBBox[3], clipBox[3]);
276265
return this;
277266
}
278267

0 commit comments

Comments
 (0)