fixup std::abs in map_location.hpp
The reason that OS X wasn't finding std::abs(int) is that we weren't including <cstdlib>, which is where it resides, not <cmath>. This commit adds cstdlib, and reverts the other fix attempts. This fixes up two previous commits:b05773c409
7ce9199e47
This commit is contained in:
parent
0ed27f5043
commit
e97bd1a2bc
1 changed files with 4 additions and 8 deletions
|
@ -21,6 +21,7 @@ class config;
|
|||
class variable_set;
|
||||
|
||||
#include <cmath>
|
||||
#include <cstdlib>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
@ -350,14 +351,9 @@ inline bool tiles_adjacent(const map_location& a, const map_location& b)
|
|||
*/
|
||||
}
|
||||
|
||||
// OS X appears not to provide std::abs with overload for int
|
||||
inline int _abs(int x) {
|
||||
return (x < 0) ? -x : x;
|
||||
}
|
||||
|
||||
inline size_t distance_between(const map_location& a, const map_location& b)
|
||||
{
|
||||
const size_t hdistance = _abs(a.x - b.x);
|
||||
const size_t hdistance = std::abs(a.x - b.x);
|
||||
|
||||
const size_t vpenalty = ( (((a.x & 1)==0) && ((b.x & 1)==1) && (a.y < b.y))
|
||||
|| (((b.x & 1)==0) && ((a.x & 1)==1) && (b.y < a.y)) ) ? 1 : 0;
|
||||
|
@ -370,9 +366,9 @@ inline size_t distance_between(const map_location& a, const map_location& b)
|
|||
// previously returned (hdistance + vdistance - vsavings)
|
||||
// = hdistance + vdistance - minimum(vdistance,hdistance/2+hdistance%2)
|
||||
// = maximum(hdistance, vdistance+hdistance-hdistance/2-hdistance%2)
|
||||
// = maximum(hdistance,abs(a.y-b.y)+vpenalty+hdistance/2)
|
||||
// = maximum(hdistance,std::abs(a.y-b.y)+vpenalty+hdistance/2)
|
||||
|
||||
return std::max<int>(hdistance, _abs(a.y - b.y) + vpenalty + hdistance/2);
|
||||
return std::max<int>(hdistance, std::abs(a.y - b.y) + vpenalty + hdistance/2);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue