Created
March 6, 2011 02:03
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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