Ensure toScale stays within defined range
This commit is contained in:
parent
bb9838e3e6
commit
1ee0b8b87a
11
lib/utils.js
11
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 = {
|
||||
|
|
Loading…
Reference in New Issue