diff --git a/lib/utils.js b/lib/utils.js index e28aef9..97b47ae 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -65,7 +65,16 @@ Number.prototype.fromScale = function(start, end) { // // Returns an integer representing the scaled value Number.prototype.toScale = function(start, end) { - return this * (Math.max(start, end) - Math.min(start, end)) + Math.min(start, end); + var i = this * (Math.max(start, end) - Math.min(start, end)) + Math.min(start, end); + if (i < Math.min(start, end)) { + return Math.min(start, end) + } + else if (i > Math.max(start,end)){ + return Math.max(start, end) + } + else { + return i + } }; var Utils = {