Added outOfBoundsBy method to bound, and modified modValue of boundValue, this change breaks previous useages of boundValue
This commit is contained in:
parent
a793129169
commit
a45b364a80
@ -191,6 +191,20 @@ class bound {
|
||||
if (valueArray.length != this.min.length) { return [...this.min.map((v,i) => Math.min(Math.max(0, v), this.max[i]))]; }
|
||||
return valueArray.map((value,index) => Math.min(Math.max(value,this.min[index]),this.max[index]));
|
||||
}
|
||||
|
||||
outOfBoundsBy(valueArray=[...this.min.map(v => 0)]) {
|
||||
if (this.inbounds(valueArray)) {
|
||||
return [...this.min.map(e=>0)];
|
||||
} else {
|
||||
return this.min.map((value,index)=>{
|
||||
if (undefined == valueArray[index]) { return NaN }
|
||||
if (valueArray[index] < value) { return -(value - valueArray[index]) }
|
||||
if (valueArray[index] > this.max[index]) { return valueArray[index] - this.max[index] }
|
||||
return 0;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class boundValue {
|
||||
@ -214,7 +228,8 @@ class boundValue {
|
||||
|
||||
modValue(mod=0) {
|
||||
mod = !isNaN(mod) ? mod : 0;
|
||||
return this.setValue(this.value+mod);
|
||||
var outOfBoundsBy = this.bounds.outOfBoundsBy([this.value+mod]);
|
||||
return {newValue:this.setValue(this.value+mod),remainder:outOfBoundsBy};
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user