mirror of
https://forge.murkfall.net/bluesaxman/blue.js.git
synced 2026-03-13 09:34:20 -06:00
added boundValue to bluemath.js
This commit is contained in:
@@ -125,3 +125,28 @@ class bound {
|
|||||||
return valueArray.map((value,index) => Math.min(Math.max(value,this.min[index]),this.max[index]));
|
return valueArray.map((value,index) => Math.min(Math.max(value,this.min[index]),this.max[index]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class boundValue {
|
||||||
|
constructor (bounds=new bound(),value=0) {
|
||||||
|
this.bounds = bounds instanceof bound ? bounds : new bound();
|
||||||
|
this.value = !isNaN(value) ? value : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
setValue(value=0) {
|
||||||
|
value = !isNaN(value) ? value : 0;
|
||||||
|
return this.value = this.bounds.clamp([value])[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
getValue() {
|
||||||
|
return this.bounds.clamp([this.value])[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
getValuePercent() {
|
||||||
|
return this.bounds.normalize([this.value])[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
modValue(mod=0) {
|
||||||
|
mod = !isNaN(mod) ? mod : 0;
|
||||||
|
return this.setValue(this.value+mod);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user