added boundValue to bluemath.js
This commit is contained in:
parent
aa34ceeae4
commit
1d9f4377b1
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user