Merge pull request #21026 from Snuffleupagus/more-MathClamp

Use the `MathClamp` helper function more
This commit is contained in:
Jonas Jenwald 2026-04-02 11:21:46 +02:00 committed by GitHub
commit 1bd4c4fbde
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 18 deletions

View File

@ -19,6 +19,7 @@ import {
PS_VALUE_TYPE,
PSStackToTree,
} from "./ast.js";
import { MathClamp } from "../../shared/util.js";
import { TOKEN } from "./lexer.js";
// Consecutive integers for a dense jump table in _execute.
@ -341,7 +342,7 @@ class PsJsCompiler {
const slot = ir[ip++] | 0;
const min = ir[ip++];
const max = ir[ip++];
dest[destOffset + slot] = Math.max(Math.min(stack[--sp], max), min);
dest[destOffset + slot] = MathClamp(stack[--sp], min, max);
break;
}
case OP.IF: {

View File

@ -13,7 +13,7 @@
* limitations under the License.
*/
import { FeatureTest, Util } from "../shared/util.js";
import { FeatureTest, MathClamp, Util } from "../shared/util.js";
const FORCED_DEPENDENCY_LABEL = "__forcedDependency";
@ -257,22 +257,11 @@ class CanvasBBoxTracker {
const bbox = [Infinity, Infinity, -Infinity, -Infinity];
Util.axialAlignedBoundingBox([minX, minY, maxX, maxY], transform, bbox);
this.#pendingBBox[0] = Math.min(
this.#pendingBBox[0],
Math.max(bbox[0], clipBox[0])
);
this.#pendingBBox[1] = Math.min(
this.#pendingBBox[1],
Math.max(bbox[1], clipBox[1])
);
this.#pendingBBox[2] = Math.max(
this.#pendingBBox[2],
Math.min(bbox[2], clipBox[2])
);
this.#pendingBBox[3] = Math.max(
this.#pendingBBox[3],
Math.min(bbox[3], clipBox[3])
);
this.#pendingBBox[0] = MathClamp(bbox[0], clipBox[0], this.#pendingBBox[0]);
this.#pendingBBox[1] = MathClamp(bbox[1], clipBox[1], this.#pendingBBox[1]);
this.#pendingBBox[2] = MathClamp(bbox[2], this.#pendingBBox[2], clipBox[2]);
this.#pendingBBox[3] = MathClamp(bbox[3], this.#pendingBBox[3], clipBox[3]);
return this;
}