It’s about spatial hashing for 2d… (Excuse me if it’s not spatial hashing I’m talking about)
We translate x and y coord to an index in array representing buckets (groups).
All papers/articles I’ve read, and myself use:
int grid_cell = x/cell_size + y/cell_size*width;
In AS3, would it be more efficient to precalculate the indices for every x and y and storing the results in 2 vectors such as xMap:Vector.<int> contains x/cell_size and yMap:Vector.<int> y/cell_size*width then retrieve it using:
int grid_cell = xMap[x] + yMap[y]; // grid being the array of buckets
In short: is retrieving an item from a vector faster than a calculation such as y/cell_size*width in AS3 ??
My own bench-marking’s results fluctuate a lot for me to decide and this is a performance critical function.
Unless the Vector is really, really massive it will be quicker to look up values than calculate them.