Optimised the constrain function

Optimised the constrain function to make it a little faster. [Test proof](http://jsperf.com/javascript-clamp).

Apologies for not including a minified version, there's nothing in the repo for minification so I figured you would want to handle that yourself.