Posted By

burnandbass on 12/03/10


Tagged


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

weavermedia


Number utils - center, boundery


 / Published in: ActionScript 3
 

  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  

You need to login to post a comment.