MCPcopy Create free account
hub / github.com/OpenXcom/OpenXcom / distance

Method distance

src/Battlescape/TileEngine.cpp:2393–2398  ·  view source on GitHub ↗

* Calculates the distance between 2 points. Rounded up to first INT. * @param pos1 Position of first square. * @param pos2 Position of second square. * @return Distance. */

Source from the content-addressed store, hash-verified

2391 * @return Distance.
2392 */
2393int TileEngine::distance(const Position &pos1, const Position &pos2) const
2394{
2395 int x = pos1.x - pos2.x;
2396 int y = pos1.y - pos2.y;
2397 return (int)Round(sqrt(float(x*x + y*y)));
2398}
2399
2400/**
2401 * Calculates the distance squared between 2 points. No sqrt(), not floating point math, and sometimes it's all you need.

Callers 15

addAlienMethod · 0.80
setupAmbushMethod · 0.80
setupEscapeMethod · 0.80
getSpottingUnitsMethod · 0.80
selectNearestTargetMethod · 0.80
selectRandomTargetMethod · 0.80
explosiveEfficacyMethod · 0.80
meleeActionMethod · 0.80
selectFireMethodMethod · 0.80
psiActionMethod · 0.80
drawTerrainMethod · 0.80

Calls 1

RoundFunction · 0.85

Tested by

no test coverage detected