Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Fix bug with modulate where outA > outB and limit is true
- Loading branch information
Showing
with
9 additions
and
2 deletions.
-
+6
−2
framer/Utils.coffee
-
+3
−0
test/tests/UtilsTest.coffee
|
@@ -287,8 +287,12 @@ Utils.modulate = (value, rangeA, rangeB, limit=false) -> |
|
|
result = toLow + (((value - fromLow) / (fromHigh - fromLow)) * (toHigh - toLow)) |
|
|
|
|
|
if limit is true |
|
|
return toLow if result < toLow |
|
|
return toHigh if result > toHigh |
|
|
if toLow < toHigh |
|
|
return toLow if result < toLow |
|
|
return toHigh if result > toHigh |
|
|
else |
|
|
return toLow if result > toLow |
|
|
return toHigh if result < toHigh |
|
|
|
|
|
result |
|
|
|
|
|
|
@@ -193,6 +193,9 @@ describe "Utils", -> |
|
|
Utils.modulate(0, [1, 2], [0, 100], true).should.equal 0 |
|
|
Utils.modulate(0, [1, 2], [0, 100], false).should.equal -100 |
|
|
|
|
|
Utils.modulate(0, [1, 2], [100, 0], true).should.equal 100 |
|
|
Utils.modulate(0, [1, 2], [100, 0], false).should.equal 200 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|