CalcTools

August 11th, 2008

Here’s a calculator utility package which contains a few handy Mathematical shortcuts.

A lot of it came out of some old game code, such as getIsInRange($p1,$p2,range) which returns true if position1 is within the specified range of position2. $p1 and $p2 are instances of PositionObject which contains coordinates.

PositionObject supports 1, 2 or 3 dimensions, but getIsInRange only works with 1 or 2-dimensional PositionObjects at the moment – i.e. z-distance is ignored. I’ll update the maths to work in 3D at some point!

Files:
com.aderowbotham.utils.calc.CalcTools
com.aderowbotham.utils.calc.CalcReturnObject
com.aderowbotham.utils.calc.PositionObject

Example usage:

import com.aderowbotham.utils.calc.CalcTools;
import com.aderowbotham.utils.calc.PositionObject;

var p1:PositionObject = new PositionObject(100,0);
var p2:PositionObject = new PositionObject(100,20);

trace("check range: "+CalcTools.getIsInRange(p1,p2,30));
//returns true because distance is 20 but the range tested was 30

There’s loads of other stuff in there too.

Leave a Reply