Permalink
Browse files

Fix bug with modulate where outA > outB and limit is true

  • Loading branch information...
koenbok committed Sep 30, 2014
1 parent e9c3c4a commit c548c394892d80f2cbc6d911a92aff4ceeb7f4f9
Showing with 9 additions and 2 deletions.
  1. +6 −2 framer/Utils.coffee
  2. +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

0 comments on commit c548c39

Please sign in to comment.