Convert uses of abs to std::abs
This commit is contained in:
parent
1167bc3c3c
commit
1fa6a2d4b2
22 changed files with 42 additions and 42 deletions
|
@ -1451,7 +1451,7 @@ int generic_combat_modifier(int lawful_bonus, unit_type::ALIGNMENT alignment,
|
|||
bonus = -lawful_bonus;
|
||||
break;
|
||||
case unit_type::ALIGNMENT::LIMINAL:
|
||||
bonus = -abs(lawful_bonus);
|
||||
bonus = -std::abs(lawful_bonus);
|
||||
break;
|
||||
default:
|
||||
bonus = 0;
|
||||
|
|
|
@ -1119,7 +1119,7 @@ double readonly_context_impl::power_projection(const map_location& loc, const mo
|
|||
} else if(un.alignment() == unit_type::ALIGNMENT::CHAOTIC) {
|
||||
tod_modifier = -lawful_bonus;
|
||||
} else if(un.alignment() == unit_type::ALIGNMENT::LIMINAL) {
|
||||
tod_modifier = -(abs(lawful_bonus));
|
||||
tod_modifier = -(std::abs(lawful_bonus));
|
||||
}
|
||||
|
||||
// The 0.5 power avoids underestimating too much the damage of a wounded unit.
|
||||
|
|
|
@ -262,8 +262,8 @@ std::vector<target> default_ai_context_impl::find_targets(const move_map& enemy_
|
|||
continue;
|
||||
}
|
||||
|
||||
const double distance = abs(j->loc.x - i->loc.x) +
|
||||
abs(j->loc.y - i->loc.y);
|
||||
const double distance = std::abs(j->loc.x - i->loc.x) +
|
||||
std::abs(j->loc.y - i->loc.y);
|
||||
new_values.back() += j->value/(distance*distance);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -235,7 +235,7 @@ pathfind::plain_route formula_ai::shortest_path_calculator(const map_location &s
|
|||
}
|
||||
|
||||
static const size_t NDIRECTIONS = map_location::NDIRECTIONS;
|
||||
unsigned int difference = abs(int(preferred - n));
|
||||
unsigned int difference = std::abs(int(preferred - n));
|
||||
if(difference > NDIRECTIONS/2) {
|
||||
difference = NDIRECTIONS - difference;
|
||||
}
|
||||
|
|
|
@ -344,7 +344,7 @@ private:
|
|||
if ( diff > enemy_tollerancy) {
|
||||
valid = false;
|
||||
break;
|
||||
} else if( abs(diff) < enemy_border_tollerancy )
|
||||
} else if( std::abs(diff) < enemy_border_tollerancy )
|
||||
enemy_border = true;
|
||||
}
|
||||
|
||||
|
|
|
@ -252,7 +252,7 @@ void arrow::update_symbols()
|
|||
exit = exit + "_ending";
|
||||
}
|
||||
|
||||
assert(abs(enter_dir - exit_dir) > 1); //impossible turn?
|
||||
assert(std::abs(enter_dir - exit_dir) > 1); //impossible turn?
|
||||
if (enter_dir < exit_dir)
|
||||
{
|
||||
prefix = enter;
|
||||
|
|
|
@ -451,7 +451,7 @@ void display::fill_images_list(const std::string& prefix, std::vector<std::strin
|
|||
const std::string& display::get_variant(const std::vector<std::string>& variants, const map_location &loc) const
|
||||
{
|
||||
//TODO use better noise function
|
||||
return variants[abs(loc.x + loc.y) % variants.size()];
|
||||
return variants[std::abs(loc.x + loc.y) % variants.size()];
|
||||
}
|
||||
|
||||
void display::rebuild_all()
|
||||
|
@ -1963,14 +1963,14 @@ bool display::scroll(int xmove, int ymove, bool force)
|
|||
SDL_Rect r = map_area();
|
||||
if(dy < 0)
|
||||
r.y = r.y + r.h + dy;
|
||||
r.h = abs(dy);
|
||||
r.h = std::abs(dy);
|
||||
invalidate_locations_in_rect(r);
|
||||
}
|
||||
if (dx != 0) {
|
||||
SDL_Rect r = map_area();
|
||||
if (dx < 0)
|
||||
r.x = r.x + r.w + dx;
|
||||
r.w = abs(dx);
|
||||
r.w = std::abs(dx);
|
||||
invalidate_locations_in_rect(r);
|
||||
}
|
||||
scroll_event_.notify_observers();
|
||||
|
|
|
@ -521,8 +521,8 @@ void pump()
|
|||
static const int DoubleClickTime = 500;
|
||||
static const int DoubleClickMaxMove = 3;
|
||||
if(last_mouse_down >= 0 && info.ticks() - last_mouse_down < DoubleClickTime &&
|
||||
abs(event.button.x - last_click_x) < DoubleClickMaxMove &&
|
||||
abs(event.button.y - last_click_y) < DoubleClickMaxMove) {
|
||||
std::abs(event.button.x - last_click_x) < DoubleClickMaxMove &&
|
||||
std::abs(event.button.y - last_click_y) < DoubleClickMaxMove) {
|
||||
SDL_UserEvent user_event;
|
||||
user_event.type = DOUBLE_CLICK_EVENT;
|
||||
user_event.code = 0;
|
||||
|
|
|
@ -948,7 +948,7 @@ variant variant::build_range(const variant& v) const {
|
|||
v.must_be(TYPE_INT);
|
||||
|
||||
int lhs = as_int(), rhs = v.as_int();
|
||||
int len = abs(rhs - lhs) + 1;
|
||||
int len = std::abs(rhs - lhs) + 1;
|
||||
|
||||
std::vector< variant > res;
|
||||
res.reserve(len);
|
||||
|
@ -1004,7 +1004,7 @@ void variant::serialize_to_string(std::string& str) const
|
|||
|
||||
s << integer << ".";
|
||||
|
||||
fractional = abs(fractional);
|
||||
fractional = std::abs(fractional);
|
||||
|
||||
if( fractional < 100) {
|
||||
if( fractional < 10)
|
||||
|
@ -1102,7 +1102,7 @@ std::string variant::string_cast() const
|
|||
|
||||
s << integer << ".";
|
||||
|
||||
fractional = abs(fractional);
|
||||
fractional = std::abs(fractional);
|
||||
|
||||
if( fractional < 100) {
|
||||
if( fractional < 10)
|
||||
|
@ -1175,7 +1175,7 @@ std::string variant::to_debug_string(std::vector<const game_logic::formula_calla
|
|||
s << '-';
|
||||
s << integer << ".";
|
||||
|
||||
fractional = abs(fractional);
|
||||
fractional = std::abs(fractional);
|
||||
|
||||
if( fractional < 100) {
|
||||
if( fractional < 10)
|
||||
|
|
|
@ -317,8 +317,8 @@ height_map default_map_generator_job::generate_height_map(size_t width, size_t h
|
|||
|
||||
// We have to check whether this is actually a valley
|
||||
if(island_size != 0) {
|
||||
const size_t diffx = abs(x1 - int(center_x));
|
||||
const size_t diffy = abs(y1 - int(center_y));
|
||||
const size_t diffx = std::abs(x1 - int(center_x));
|
||||
const size_t diffy = std::abs(y1 - int(center_y));
|
||||
const size_t dist = size_t(std::sqrt(double(diffx*diffx + diffy*diffy)));
|
||||
is_valley = dist > island_size;
|
||||
}
|
||||
|
|
|
@ -266,8 +266,8 @@ void tmouse_motion::mouse_motion(twidget* mouse_over, const tpoint& coordinate)
|
|||
owner_.fire(event::MOUSE_MOTION, *mouse_over, coordinate);
|
||||
|
||||
if(hover_timer_) {
|
||||
if((abs(hover_position_.x - coordinate.x) > 5)
|
||||
|| (abs(hover_position_.y - coordinate.y) > 5)) {
|
||||
if((std::abs(hover_position_.x - coordinate.x) > 5)
|
||||
|| (std::abs(hover_position_.y - coordinate.y) > 5)) {
|
||||
|
||||
stop_hover_timer();
|
||||
start_hover_timer(mouse_over, coordinate);
|
||||
|
|
|
@ -139,7 +139,7 @@ std::pair<double, double> joystick_manager::get_mouse_axis_pair() {
|
|||
return std::make_pair(0.0, 0.0);
|
||||
|
||||
// TODO do some math to normalize over the value - deadzone.
|
||||
//const double relation = abs( (double)values.first / (double)values.second );
|
||||
//const double relation = std::abs( (double)values.first / (double)values.second );
|
||||
//const int range_x = values.first - round_double(relation * deadzone);
|
||||
//const int range_y = values.second - ((1.0 - relation) * deadzone);
|
||||
//double x_value = ((double)(values.first - deadzone) / (double)(32768 - deadzone)) *
|
||||
|
|
|
@ -235,9 +235,9 @@ map_location::DIRECTION map_location::get_relative_dir(const map_location & loc,
|
|||
|
||||
if (dx==0 && dy==0) return NDIRECTIONS;
|
||||
|
||||
int dist = abs(dx); // Distance from north-south line
|
||||
int dist_diag_SW_NE = abs(dy + (dx + (dy>0?0:1) )/2); // Distance from diagonal line SW-NE
|
||||
int dist_diag_SE_NW = abs(dy - (dx - (dy>0?0:1) )/2); // Distance from diagonal line SE-NW
|
||||
int dist = std::abs(dx); // Distance from north-south line
|
||||
int dist_diag_SW_NE = std::abs(dy + (dx + (dy>0?0:1) )/2); // Distance from diagonal line SW-NE
|
||||
int dist_diag_SE_NW = std::abs(dy - (dx - (dy>0?0:1) )/2); // Distance from diagonal line SE-NW
|
||||
|
||||
if (dy > 0) dir = SOUTH;
|
||||
else dir = NORTH;
|
||||
|
|
|
@ -373,8 +373,8 @@ inline bool tiles_adjacent(const map_location& a, const map_location& b)
|
|||
}
|
||||
|
||||
/*
|
||||
const int xdiff = abs(a.x - b.x);
|
||||
const int ydiff = abs(a.y - b.y);
|
||||
const int xdiff = std::abs(a.x - b.x);
|
||||
const int ydiff = std::abs(a.y - b.y);
|
||||
return (ydiff == 1 && a.x == b.x) || (xdiff == 1 && a.y == b.y) ||
|
||||
(xdiff == 1 && ydiff == 1 && (a.y > b.y ? is_even(a.x) : is_even(b.x)));
|
||||
*/
|
||||
|
|
|
@ -427,11 +427,11 @@ map_location mouse_handler::current_unit_attacks_from(const map_location& loc) c
|
|||
if (current_paths_.destinations.contains(adj[n]))
|
||||
{
|
||||
static const size_t NDIRECTIONS = map_location::NDIRECTIONS;
|
||||
unsigned int difference = abs(int(preferred - n));
|
||||
unsigned int difference = std::abs(int(preferred - n));
|
||||
if(difference > NDIRECTIONS/2) {
|
||||
difference = NDIRECTIONS - difference;
|
||||
}
|
||||
unsigned int second_difference = abs(int(second_preferred - n));
|
||||
unsigned int second_difference = std::abs(int(second_preferred - n));
|
||||
if(second_difference > NDIRECTIONS/2) {
|
||||
second_difference = NDIRECTIONS - second_difference;
|
||||
}
|
||||
|
|
|
@ -207,7 +207,7 @@ void movetype::terrain_info::data::merge(const config & new_values, bool overwri
|
|||
// provided value, capped between minimum and maximum, then
|
||||
// given the sign of the old value.
|
||||
// (Think defenses for why we might have negative values.)
|
||||
int value = abs(old) + a.second.to_int(0);
|
||||
int value = std::abs(old) + a.second.to_int(0);
|
||||
value = std::max(params_.min_value, std::min(value, params_.max_value));
|
||||
if ( old < 0 )
|
||||
value = -value;
|
||||
|
|
|
@ -1127,7 +1127,7 @@ static config time_of_day_at(reports::context & rc, const map_location& mouseove
|
|||
<< _("Chaotic units: ") << "<span foreground=\"" << chaotic_color << "\">"
|
||||
<< utils::signed_percent(-b) << "</span>\n"
|
||||
<< _("Liminal units: ") << "<span foreground=\"" << liminal_color << "\">"
|
||||
<< utils::signed_percent(-(abs(b))) << "</span>\n";
|
||||
<< utils::signed_percent(-(std::abs(b))) << "</span>\n";
|
||||
|
||||
std::string tod_image = tod.image;
|
||||
if (tod.bonus_modified > 0) tod_image += "~BRIGHTEN()";
|
||||
|
@ -1176,7 +1176,7 @@ static config unit_box_at(reports::context & rc, const map_location& mouseover_h
|
|||
<< _("Chaotic units: ") << "<span foreground=\"" << chaotic_color << "\">"
|
||||
<< utils::signed_percent(-bonus) << "</span>\n"
|
||||
<< _("Liminal units: ") << "<span foreground=\"" << liminal_color << "\">"
|
||||
<< utils::signed_percent(-(abs(bonus))) << "</span>\n";
|
||||
<< utils::signed_percent(-(std::abs(bonus))) << "</span>\n";
|
||||
|
||||
std::string local_tod_image = "themes/classic/" + local_tod.image;
|
||||
std::string global_tod_image = "themes/classic/" + global_tod.image;
|
||||
|
|
|
@ -472,7 +472,7 @@ bool string_bool(const std::string& str, bool def) {
|
|||
std::string signed_value(int val)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << (val >= 0 ? "+" : font::unicode_minus) << abs(val);
|
||||
oss << (val >= 0 ? "+" : font::unicode_minus) << std::abs(val);
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
|
@ -481,7 +481,7 @@ std::string half_signed_value(int val)
|
|||
std::ostringstream oss;
|
||||
if (val < 0)
|
||||
oss << font::unicode_minus;
|
||||
oss << abs(val);
|
||||
oss << std::abs(val);
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
|
|
|
@ -145,10 +145,10 @@ BOOST_AUTO_TEST_CASE(test_formula_function_concatenate)
|
|||
|
||||
BOOST_AUTO_TEST_CASE(test_formula_function_math)
|
||||
{
|
||||
BOOST_CHECK_EQUAL(formula("abs(5)").evaluate().as_int(), 5);
|
||||
BOOST_CHECK_EQUAL(formula("abs(-5)").evaluate().as_int(), 5);
|
||||
BOOST_CHECK_EQUAL(formula("abs(5.0)").evaluate().as_int(), 5);
|
||||
BOOST_CHECK_EQUAL(formula("abs(-5.0)").evaluate().as_int(), 5);
|
||||
BOOST_CHECK_EQUAL(formula("std::abs(5)").evaluate().as_int(), 5);
|
||||
BOOST_CHECK_EQUAL(formula("std::abs(-5)").evaluate().as_int(), 5);
|
||||
BOOST_CHECK_EQUAL(formula("std::abs(5.0)").evaluate().as_int(), 5);
|
||||
BOOST_CHECK_EQUAL(formula("std::abs(-5.0)").evaluate().as_int(), 5);
|
||||
|
||||
BOOST_CHECK_EQUAL(formula("min(3,5)").evaluate().as_int(), 3);
|
||||
BOOST_CHECK_EQUAL(formula("min(5,2)").evaluate().as_int(), 2);
|
||||
|
|
|
@ -605,7 +605,7 @@ void unit_attack(display * disp, game_board & board,
|
|||
unit_ability_list helpers = defender.get_abilities("resistance");
|
||||
|
||||
std::string text = number_and_text(damage, hit_text);
|
||||
std::string text_2 = number_and_text(abs(drain_amount), att_text);
|
||||
std::string text_2 = number_and_text(std::abs(drain_amount), att_text);
|
||||
|
||||
unit_animation::hit_type hit_type;
|
||||
if(damage >= defender.hitpoints()) {
|
||||
|
|
|
@ -1784,7 +1784,7 @@ std::string unit::describe_builtin_effect(std::string apply_to, const config& ef
|
|||
std::string description = utils::print_modifier(increase) + " ";
|
||||
const char* const singular = N_("attack per turn");
|
||||
const char* const plural = N_("attacks per turn");
|
||||
if (increase[increase.size()-1] == '%' || abs(std::stoi(increase)) != 1) {
|
||||
if (increase[increase.size()-1] == '%' || std::abs(std::stoi(increase)) != 1) {
|
||||
description += t_string(plural, "wesnoth");
|
||||
} else {
|
||||
description += t_string(singular, "wesnoth");
|
||||
|
|
|
@ -396,7 +396,7 @@ void textbox::erase_selection()
|
|||
return;
|
||||
|
||||
ucs4::string::iterator itor = text_.begin() + std::min(selstart_, selend_);
|
||||
text_.erase(itor, itor + abs(selend_ - selstart_));
|
||||
text_.erase(itor, itor + std::abs(selend_ - selstart_));
|
||||
cursor_ = std::min(selstart_, selend_);
|
||||
selstart_ = selend_ = -1;
|
||||
}
|
||||
|
@ -647,9 +647,9 @@ void textbox::handle_event(const SDL_Event& event, bool was_forwarded)
|
|||
|
||||
// Check individually each distance (if, one day, we support
|
||||
// RTL languages, char_x_[c] may not be monotonous.)
|
||||
if(abs(x - char_x_[i]) < distance && yscroll_ + y < char_y_[i] + line_height_) {
|
||||
if(std::abs(x - char_x_[i]) < distance && yscroll_ + y < char_y_[i] + line_height_) {
|
||||
pos = i;
|
||||
distance = abs(x - char_x_[i]);
|
||||
distance = std::abs(x - char_x_[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue