environment: Add Math.clamp

The good old clamp function, now part of the Math family.
Clamp is happy after so many years of loneliness.

This is a strict implementation of the draft ECMAScript
proposal.

https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1295
This commit is contained in:
Georges Basile Stavracas Neto
2020-06-02 00:41:43 -03:00
parent 5569090d1c
commit 8154728d09
5 changed files with 12 additions and 25 deletions

View File

@ -28,10 +28,6 @@ const State = {
SCROLLING: 1,
};
function clamp(value, min, max) {
return Math.max(min, Math.min(max, value));
}
const TouchpadSwipeGesture = GObject.registerClass({
Properties: {
'enabled': GObject.ParamSpec.boolean(
@ -558,8 +554,8 @@ var SwipeTracker = GObject.registerClass({
let firstPoint = this._snapPoints[0];
let lastPoint = this._snapPoints[this._snapPoints.length - 1];
this._progress = clamp(this._progress, firstPoint, lastPoint);
this._progress = clamp(this._progress,
this._progress = Math.clamp(this._progress, firstPoint, lastPoint);
this._progress = Math.clamp(this._progress,
this._initialProgress - 1, this._initialProgress + 1);
this.emit('update', this._progress);
@ -606,7 +602,7 @@ var SwipeTracker = GObject.registerClass({
let duration = Math.abs((this._progress - endProgress) / velocity * DURATION_MULTIPLIER);
if (duration > 0) {
duration = clamp(duration,
duration = Math.clamp(duration,
MIN_ANIMATION_DURATION, MAX_ANIMATION_DURATION);
}