forked from 0ad/0ad
26 lines
748 B
JavaScript
Executable File
26 lines
748 B
JavaScript
Executable File
function AssocArraytoArray(assocArray) {
|
|
var endArray = [];
|
|
for (i in assocArray)
|
|
endArray.push(assocArray[i]);
|
|
return endArray;
|
|
};
|
|
|
|
// A is the reference, B must be in "range" of A
|
|
// this supposes the range is already squared
|
|
function inRange(a, b, range)// checks for X distance
|
|
{
|
|
// will avoid unnecessary checking for position in some rare cases... I'm lazy
|
|
if (a === undefined || b === undefined || range === undefined)
|
|
return undefined;
|
|
|
|
var dx = a[0] - b[0];
|
|
var dz = a[1] - b[1];
|
|
return ((dx*dx + dz*dz ) < range);
|
|
}
|
|
// slower than SquareVectorDistance, faster than VectorDistance but not exactly accurate.
|
|
function ManhattanDistance(a, b)
|
|
{
|
|
var dx = a[0] - b[0];
|
|
var dz = a[1] - b[1];
|
|
return Math.abs(dx) + Math.abs(dz);
|
|
} |