Skip to content

Instantly share code, notes, and snippets.

@mimshwright
Created March 6, 2011 02:03
Show Gist options
  • Select an option

  • Save mimshwright/856948 to your computer and use it in GitHub Desktop.

Select an option

Save mimshwright/856948 to your computer and use it in GitHub Desktop.
A shortcut function for limiting a value between a lower and upper boundary. I use this all the time.
package org.as3lib.math
{
/**
* Global function for returning a number within an upper and lower limit.
*
* @param value The number to limit
* @param lowLimit The lowest value that will be returned.
* @param highLimit The highest value that will be returned.
* @return value if lowLimit < value < highLimit, otherwise returns the lowLimit or highLimit.
*/
public function limit(value:Number, lowLimit:Number, highLimit:Number):Number {
return Math.max(lowLimit, Math.min(highLimit, value));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment