Monday, April 28, 2008

Bit-101's Three Useful Methods

Keith Peters posted on his blog last week three useful methods.

I've added a couple of extra methods that I'm finding I use more often than not and might as well shove into this class. Shove is an inelegant word, but I'm an inelegant guy.

//thanks, Keith.

public static function distanceCalculation(x1:Number, y1:Number, x2:Number, y2:Number):Number
{
var dx:Number = x1 - x2;
var dy:Number = y1 - y2;
return Math.sqrt(dx * dx + dy * dy);
}

//I mixed something up here. Fixed the randomRange value return. Thanks again, Keith.

public static function randomRange(start:Number, end:Number):Number
{
return Math.floor(start + Math.random() * (end - start));
}
It's fair to note that I didn't create these methods. They were found at various times in various locations. I just keep misplacing them and looking for them again. Good to know that it's last time I'll do it.

It's nice to be spurred on to centralizing this stuff. Thanks, Keith!

Labels: ,