Skip to content

constrain

Subhajit Sahu edited this page Aug 8, 2022 · 2 revisions

Constrain a number within a minimum and a maximum value.

Similar: constrain, normalize, remap, lerp.


function constrain(x, min, max)
// x:   a number
// min: minimum value
// max: maximum value

const xmath = require('extra-math');


xmath.constrain(20, 0, 50);
// → 20

xmath.constrain(-10, 0, 100);
// → 0

xmath.constrain(120, 0, 100);
// → 100


References

Clone this wiki locally