From ca1ddbdeed7c3df35543fa0ee87723cf379fb02a Mon Sep 17 00:00:00 2001 From: Quentin Leonetti Date: Sat, 13 Jul 2019 21:35:47 +0200 Subject: [PATCH 1/2] add clamp function --- desktop/sources/scripts/library.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/desktop/sources/scripts/library.js b/desktop/sources/scripts/library.js index 647d6a6..060e0ff 100644 --- a/desktop/sources/scripts/library.js +++ b/desktop/sources/scripts/library.js @@ -108,4 +108,8 @@ function Library (ronin) { this.div = function (a, b) { return a / b } + + this.clamp = function (val, min, max) { + return Math.min(max, Math.max(min, val)) + } } From 92657c629c05038a47f3fda327cb7ea26afa4462 Mon Sep 17 00:00:00 2001 From: Quentin Leonetti Date: Sat, 13 Jul 2019 21:42:48 +0200 Subject: [PATCH 2/2] Add step function --- desktop/sources/scripts/library.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/desktop/sources/scripts/library.js b/desktop/sources/scripts/library.js index 060e0ff..7d35cfe 100644 --- a/desktop/sources/scripts/library.js +++ b/desktop/sources/scripts/library.js @@ -112,4 +112,8 @@ function Library (ronin) { this.clamp = function (val, min, max) { return Math.min(max, Math.max(min, val)) } + + this.step = function (val, step) { + return Math.round(val / step) * step + } }