Number utils - center, boundery


/ Published in: ActionScript 3
Save to your folder(s)



Copy this code and paste it in your HTML
  1. /**
  2. * takes a number and gives it to bounderies:
  3. @n --> the number
  4. @nMin --> minimal value fo the @n number
  5. @nMax --> the maximal value
  6. example: NumberTools.boundrary(10,5,15) returns 10, NumberTools.boundrary(4,5,15) returns 5(min). NumberTools.boundrary(20,5,15) returns 15
  7. **/
  8. public static function boundrary(n:Number, nMin:Number=0, nMax:Number=1):Number{
  9. return Math.max(Math.min(n, nMax),nMin);
  10. }
  11.  
  12. /**
  13. *The function centers values
  14. **/
  15. public static function center( container:Number, content:Number):int {
  16. return Math.round((container - content)/2);
  17. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.