Skip to content

Commit

Permalink
Correctly namespace more math functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
kevingranade committed Apr 18, 2020
1 parent a664636 commit 30960c2
Show file tree
Hide file tree
Showing 26 changed files with 83 additions and 83 deletions.
6 changes: 3 additions & 3 deletions src/ballistics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,14 +240,14 @@ dealt_projectile_attack projectile_attack( const projectile &proj_arg, const tri
rad += ( one_in( 2 ) ? 1 : -1 ) * std::min( ARCMIN( aim.dispersion ), DEGREES( 30 ) );

// TODO: This should also represent the miss on z axis
const int offset = std::min<int>( range, sqrtf( aim.missed_by_tiles ) );
const int offset = std::min<int>( range, std::sqrt( aim.missed_by_tiles ) );
int new_range = no_overshoot ?
range + rng( -offset, offset ) :
rng( range - offset, proj_arg.range );
new_range = std::max( new_range, 1 );

target.x = source.x + roll_remainder( new_range * cos( rad ) );
target.y = source.y + roll_remainder( new_range * sin( rad ) );
target.x = source.x + roll_remainder( new_range * std::cos( rad ) );
target.y = source.y + roll_remainder( new_range * std::sin( rad ) );

if( target == source ) {
target.x = source.x + sgn( dx );
Expand Down
4 changes: 2 additions & 2 deletions src/bionics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ bool Character::activate_bionic( int b, bool eff_only )
int humidity = get_local_humidity( weatherPoint.humidity, g->weather.weather,
g->is_sheltered( g->u.pos() ) );
// thirst units = 5 mL
int water_available = lround( humidity * 3.0 / 100.0 );
int water_available = std::lround( humidity * 3.0 / 100.0 );
if( water_available == 0 ) {
bio.powered = false;
add_msg_if_player( m_bad, _( "There is not enough humidity in the air for your %s to function." ),
Expand Down Expand Up @@ -1526,7 +1526,7 @@ void Character::process_bionic( int b )
int humidity = get_local_humidity( weatherPoint.humidity, g->weather.weather,
g->is_sheltered( g->u.pos() ) );
// in thirst units = 5 mL water
int water_available = lround( humidity * 3.0 / 100.0 );
int water_available = std::lround( humidity * 3.0 / 100.0 );
// At 50% relative humidity or more, the player will draw 10 mL
// At 16% relative humidity or less, the bionic will give up
if( water_available == 0 ) {
Expand Down
2 changes: 1 addition & 1 deletion src/consumption.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -957,7 +957,7 @@ bool player::eat( item &food, bool force )
}

if( has_active_bionic( bio_taste_blocker ) ) {
mod_power_level( units::from_kilojoule( -abs( food.get_comestible_fun() ) ) );
mod_power_level( units::from_kilojoule( -std::abs( food.get_comestible_fun() ) ) );
}

if( food.has_flag( flag_FUNGAL_VECTOR ) && !has_trait( trait_M_IMMUNE ) ) {
Expand Down
2 changes: 1 addition & 1 deletion src/debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ static time_info get_time() noexcept
const auto current = localtime( &tt );

return time_info { current->tm_hour, current->tm_min, current->tm_sec,
static_cast<int>( lround( tv.tv_usec / 1000.0 ) )
static_cast<int>( std::lround( tv.tv_usec / 1000.0 ) )
};
}
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/explosion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ static float mass_to_area( const float mass )
// Density of steel in g/cm^3
constexpr float steel_density = 7.85;
float fragment_volume = ( mass / 1000.0 ) / steel_density;
float fragment_radius = cbrt( ( fragment_volume * 3.0 ) / ( 4.0 * M_PI ) );
float fragment_radius = std::cbrt( ( fragment_volume * 3.0 ) / ( 4.0 * M_PI ) );
return fragment_radius * fragment_radius * M_PI;
}

Expand Down
10 changes: 5 additions & 5 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3597,7 +3597,7 @@ void game::draw_minimap()
double slope = ( cursx != targ.x ) ? static_cast<double>( targ.y - cursy ) / static_cast<double>
( targ.x - cursx ) : 4;

if( cursx == targ.x || fabs( slope ) > 3.5 ) { // Vertical slope
if( cursx == targ.x || std::fabs( slope ) > 3.5 ) { // Vertical slope
if( targ.y > cursy ) {
mvwputch( w_minimap, point( 3, 6 ), c_red, "*" );
} else {
Expand All @@ -3606,7 +3606,7 @@ void game::draw_minimap()
} else {
int arrowx = -1;
int arrowy = -1;
if( fabs( slope ) >= 1. ) { // y diff is bigger!
if( std::fabs( slope ) >= 1. ) { // y diff is bigger!
arrowy = ( targ.y > cursy ? 6 : 0 );
arrowx = static_cast<int>( 3 + 3 * ( targ.y > cursy ? slope : ( 0 - slope ) ) );
if( arrowx < 0 ) {
Expand Down Expand Up @@ -11106,10 +11106,10 @@ void game::perhaps_add_random_npc()

float density = get_option<float>( "NPC_DENSITY" );
static constexpr int density_search_radius = 60;
const int npc_num = overmap_buffer.get_npcs_near_player( density_search_radius ).size();
if( npc_num > 0 ) {
const float npc_num = overmap_buffer.get_npcs_near_player( density_search_radius ).size();
if( npc_num > 0.0 ) {
// 100%, 80%, 64%, 52%, 41%, 33%...
density *= powf( 0.8f, npc_num );
density *= std::pow( 0.8f, npc_num );
}

if( !x_in_y( density, 100 ) ) {
Expand Down
32 changes: 16 additions & 16 deletions src/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1638,8 +1638,8 @@ void item::food_info( const item *food_item, std::vector<iteminfo> &info,
const double multiplier = g->u.vitamin_rate( v.first ) / 1_days * 100;
const int min_value = min_nutr.get_vitamin( v.first );
const int max_value = v.second;
const int min_rda = lround( min_value * multiplier );
const int max_rda = lround( max_value * multiplier );
const int min_rda = std::lround( min_value * multiplier );
const int max_rda = std::lround( max_value * multiplier );
const std::string format = min_rda == max_rda ? "%s (%i%%)" : "%s (%i-%i%%)";
return string_format( format, v.first->name(), min_value, max_value );
};
Expand Down Expand Up @@ -5170,7 +5170,7 @@ static int calc_hourly_rotpoints_at_temp( const int temp )
} else if( temp < dropoff ) {
return ( temp - temperatures::freezing ) * dstep;
} else {
return lround( 215.46 * std::pow( 2.0, static_cast<float>( temp ) / 16.0 ) );
return std::lround( 215.46 * std::pow( 2.0, static_cast<float>( temp ) / 16.0 ) );
}
}

Expand Down Expand Up @@ -5271,7 +5271,7 @@ units::volume item::get_storage() const
}
units::volume storage = t->storage;
float mod = get_clothing_mod_val( clothing_mod_type_storage );
storage += lround( mod ) * units::legacy_volume_factor;
storage += std::lround( mod ) * units::legacy_volume_factor;

return storage;
}
Expand Down Expand Up @@ -5590,7 +5590,7 @@ int item::bash_resist( bool to_self ) const
resist /= mat_types.size();
}

return lround( ( resist * eff_thickness ) + mod );
return std::lround( ( resist * eff_thickness ) + mod );
}

int item::cut_resist( bool to_self ) const
Expand Down Expand Up @@ -5619,7 +5619,7 @@ int item::cut_resist( bool to_self ) const
resist /= mat_types.size();
}

return lround( ( resist * eff_thickness ) + mod );
return std::lround( ( resist * eff_thickness ) + mod );
}

#if defined(_MSC_VER)
Expand Down Expand Up @@ -5663,7 +5663,7 @@ int item::acid_resist( bool to_self, int base_env_resist ) const
resist *= env / 10.0f;
}

return lround( resist + mod );
return std::lround( resist + mod );
}

int item::fire_resist( bool to_self, int base_env_resist ) const
Expand Down Expand Up @@ -5694,7 +5694,7 @@ int item::fire_resist( bool to_self, int base_env_resist ) const
resist *= env / 10.0f;
}

return lround( resist + mod );
return std::lround( resist + mod );
}

int item::chip_resistance( bool worst ) const
Expand Down Expand Up @@ -8128,8 +8128,8 @@ void item::set_item_specific_energy( const float new_specific_energy )
} else if( new_item_temperature < temp_to_kelvin( temperatures::cold ) ) {
item_tags.insert( "COLD" );
}
temperature = lround( 100000 * new_item_temperature );
specific_energy = lround( 100000 * new_specific_energy );
temperature = std::lround( 100000 * new_item_temperature );
specific_energy = std::lround( 100000 * new_specific_energy );
reset_temp_check();
}

Expand Down Expand Up @@ -8163,8 +8163,8 @@ void item::set_item_temperature( float new_temperature )
float new_specific_energy = get_specific_energy_from_temperature( new_temperature );
float freeze_percentage = 0;

temperature = lround( 100000 * new_temperature );
specific_energy = lround( 100000 * new_specific_energy );
temperature = std::lround( 100000 * new_temperature );
specific_energy = std::lround( 100000 * new_specific_energy );

const float completely_frozen_specific_energy = specific_heat_solid *
freezing_temperature; // Energy that the item would have if it was completely solid at freezing temperature
Expand Down Expand Up @@ -8933,8 +8933,8 @@ void item::calc_temp( const int temp, const float insulation, const time_point &
} else if( new_item_temperature < temp_to_kelvin( temperatures::cold ) ) {
item_tags.insert( "COLD" );
}
temperature = lround( 100000 * new_item_temperature );
specific_energy = lround( 100000 * new_specific_energy );
temperature = std::lround( 100000 * new_item_temperature );
specific_energy = std::lround( 100000 * new_specific_energy );

last_temp_check = time;
}
Expand All @@ -8954,7 +8954,7 @@ void item::heat_up()
// Set item temperature to 60 C (333.15 K, 122 F)
// Also set the energy to match
temperature = 333.15 * 100000;
specific_energy = lround( 100000 * get_specific_energy_from_temperature( 333.15 ) );
specific_energy = std::lround( 100000 * get_specific_energy_from_temperature( 333.15 ) );

reset_temp_check();
}
Expand All @@ -8968,7 +8968,7 @@ void item::cold_up()
// Set item temperature to 3 C (276.15 K, 37.4 F)
// Also set the energy to match
temperature = 276.15 * 100000;
specific_energy = lround( 100000 * get_specific_energy_from_temperature( 276.15 ) );
specific_energy = std::lround( 100000 * get_specific_energy_from_temperature( 276.15 ) );

reset_temp_check();
}
Expand Down
8 changes: 4 additions & 4 deletions src/lightmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1421,15 +1421,15 @@ void map::apply_light_arc( const tripoint &p, int angle, float luminance, int wi
if( trigdist ) {
double fdist = ( ao * M_PI_2 ) / wangle;
double orad = ( M_PI * ao / 180.0 );
end.x = static_cast<int>( p.x + ( static_cast<double>( range ) - fdist * 2.0 ) * cos(
end.x = static_cast<int>( p.x + ( static_cast<double>( range ) - fdist * 2.0 ) * std::cos(
rad + orad ) );
end.y = static_cast<int>( p.y + ( static_cast<double>( range ) - fdist * 2.0 ) * sin(
end.y = static_cast<int>( p.y + ( static_cast<double>( range ) - fdist * 2.0 ) * std::sin(
rad + orad ) );
apply_light_ray( lit, p, end, luminance );

end.x = static_cast<int>( p.x + ( static_cast<double>( range ) - fdist * 2.0 ) * cos(
end.x = static_cast<int>( p.x + ( static_cast<double>( range ) - fdist * 2.0 ) * std::cos(
rad - orad ) );
end.y = static_cast<int>( p.y + ( static_cast<double>( range ) - fdist * 2.0 ) * sin(
end.y = static_cast<int>( p.y + ( static_cast<double>( range ) - fdist * 2.0 ) * std::sin(
rad - orad ) );
apply_light_ray( lit, p, end, luminance );
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/lightmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#define LIGHT_TRANSPARENCY_OPEN_AIR 0.038376418216
#define LIGHT_TRANSPARENCY_CLEAR 1

#define LIGHT_RANGE(b) static_cast<int>( -log(LIGHT_AMBIENT_LOW / static_cast<float>(b)) * (1.0 / LIGHT_TRANSPARENCY_OPEN_AIR) )
#define LIGHT_RANGE(b) static_cast<int>( -std::log(LIGHT_AMBIENT_LOW / static_cast<float>(b)) * (1.0 / LIGHT_TRANSPARENCY_OPEN_AIR) )

enum lit_level {
LL_DARK = 0,
Expand Down
16 changes: 8 additions & 8 deletions src/line.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -606,16 +606,16 @@ rl_vec3d rl_vec3d::normalized() const
rl_vec2d rl_vec2d::rotated( float angle ) const
{
return rl_vec2d(
x * cos( angle ) - y * sin( angle ),
x * sin( angle ) + y * cos( angle )
x * std::cos( angle ) - y * std::sin( angle ),
x * std::sin( angle ) + y * std::cos( angle )
);
}

rl_vec3d rl_vec3d::rotated( float angle ) const
{
return rl_vec3d(
x * cos( angle ) - y * sin( angle ),
x * sin( angle ) + y * cos( angle )
x * std::cos( angle ) - y * std::sin( angle ),
x * std::sin( angle ) + y * std::cos( angle )
);
}

Expand Down Expand Up @@ -754,8 +754,8 @@ void calc_ray_end( int angle, const int range, const tripoint &p, tripoint &out
const double rad = DEGREES( angle );
out.z = p.z;
if( trigdist ) {
out.x = p.x + range * cos( rad );
out.y = p.y + range * sin( rad );
out.x = p.x + range * std::cos( rad );
out.y = p.y + range * std::sin( rad );
} else {
int mult = 0;
if( angle >= 135 && angle <= 315 ) {
Expand All @@ -766,9 +766,9 @@ void calc_ray_end( int angle, const int range, const tripoint &p, tripoint &out

if( angle <= 45 || ( 135 <= angle && angle <= 215 ) || 315 < angle ) {
out.x = p.x + range * mult;
out.y = p.y + range * tan( rad ) * mult;
out.y = p.y + range * std::tan( rad ) * mult;
} else {
out.x = p.x + range * 1 / tan( rad ) * mult;
out.x = p.x + range * 1 / std::tan( rad ) * mult;
out.y = p.y + range * mult;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/line.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ constexpr double ARCMIN( double v )
inline double iso_tangent( double distance, double vertex )
{
// we can use the cosine formula (a² = b² + c² - 2bc⋅cosθ) to calculate the tangent
return std::sqrt( 2 * std::pow( distance, 2 ) * ( 1 - cos( ARCMIN( vertex ) ) ) );
return std::sqrt( 2 * std::pow( distance, 2 ) * ( 1 - std::cos( ARCMIN( vertex ) ) ) );
}

//! This compile-time usable function combines the sign of each (x, y, z) component into a single integer
Expand Down
2 changes: 1 addition & 1 deletion src/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ vehicle *map::move_vehicle( vehicle &veh, const tripoint &dp, const tileray &fac
int coll_turn = 0;
if( impulse > 0 ) {
coll_turn = shake_vehicle( veh, velocity_before, facing.dir() );
const int volume = std::min<int>( 100, sqrtf( impulse ) );
const int volume = std::min<int>( 100, std::sqrt( impulse ) );
// TODO: Center the sound at weighted (by impulse) average of collisions
sounds::sound( veh.global_pos3(), volume, sounds::sound_t::combat, _( "crash!" ),
false, "smash_success", "hit_vehicle" );
Expand Down
2 changes: 1 addition & 1 deletion src/melee.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2216,7 +2216,7 @@ double player::melee_value( const item &weap ) const

float reach = weap.reach_range( *this );
if( reach > 1.0f ) {
my_value *= 1.0f + 0.5f * ( sqrtf( reach ) - 1.0f );
my_value *= 1.0f + 0.5f * ( std::sqrt( reach ) - 1.0f );
}

add_msg( m_debug, "%s as melee: %.1f", weap.type->get_id(), my_value );
Expand Down
4 changes: 2 additions & 2 deletions src/npc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1368,8 +1368,8 @@ float npc::vehicle_danger( int radius ) const

int ax = wrapped_veh.v->global_pos3().x;
int ay = wrapped_veh.v->global_pos3().y;
int bx = int( ax + cos( facing * M_PI / 180.0 ) * radius );
int by = int( ay + sin( facing * M_PI / 180.0 ) * radius );
int bx = int( ax + std::cos( facing * M_PI / 180.0 ) * radius );
int by = int( ay + std::sin( facing * M_PI / 180.0 ) * radius );

// fake size
/* This will almost certainly give the wrong size/location on customized
Expand Down
8 changes: 4 additions & 4 deletions src/overmap_noise.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ float om_noise_layer_forest::noise_at( const point &local_omt_pos ) const
{
const point p = global_omt_pos( local_omt_pos );
float r = scaled_octave_noise_3d( 8, 0.5, 0.03, 0, 1, p.x, p.y, get_seed() );
r = powf( r, 2 );
r = std::pow( r, 2.0f );

float d = scaled_octave_noise_3d( 12, 0.5, 0.07, 0, 1, p.x, p.y, get_seed() );
d = powf( d, 3 );
d = std::pow( d, 3.0f );

return std::max( 0.0f, r - d * 0.5f );
}
Expand All @@ -23,15 +23,15 @@ float om_noise_layer_floodplain::noise_at( const point &local_omt_pos ) const
{
const point p = global_omt_pos( local_omt_pos );
float r = scaled_octave_noise_3d( 8, 0.5, 0.05, 0, 1, p.x, p.y, get_seed() );
r = powf( r, 2 );
r = std::pow( r, 2.0f );
return r;
}

float om_noise_layer_lake::noise_at( const point &local_omt_pos ) const
{
const point p = global_omt_pos( local_omt_pos );
float r = scaled_octave_noise_3d( 16, 0.5, 0.002, 0, 1, p.x, p.y, get_seed() );
r = powf( r, 4 );
r = std::pow( r, 4.0f );
return r;
}

Expand Down
8 changes: 4 additions & 4 deletions src/panels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ void overmap_ui::draw_overmap_chunk( const catacurses::window &w_minimap, const
double slope = ( cursx != targ.x ) ? static_cast<double>( targ.y - cursy ) / static_cast<double>
( targ.x - cursx ) : 4;

if( cursx == targ.x || fabs( slope ) > 3.5 ) { // Vertical slope
if( cursx == targ.x || std::fabs( slope ) > 3.5 ) { // Vertical slope
if( targ.y > cursy ) {
mvwputch( w_minimap, point( 3 + start_x, 6 + start_y ), c_red, '*' );
} else {
Expand All @@ -358,7 +358,7 @@ void overmap_ui::draw_overmap_chunk( const catacurses::window &w_minimap, const
} else {
int arrowx = -1;
int arrowy = -1;
if( fabs( slope ) >= 1. ) { // y diff is bigger!
if( std::fabs( slope ) >= 1. ) { // y diff is bigger!
arrowy = ( targ.y > cursy ? 6 : 0 );
arrowx = static_cast<int>( 3 + 3 * ( targ.y > cursy ? slope : ( 0 - slope ) ) );
if( arrowx < 0 ) {
Expand Down Expand Up @@ -850,9 +850,9 @@ static int get_int_digits( const int &digits )
{
int temp = std::abs( digits );
if( digits > 0 ) {
return static_cast<int>( log10( static_cast<double>( temp ) ) ) + 1;
return static_cast<int>( std::log10( static_cast<double>( temp ) ) ) + 1;
} else if( digits < 0 ) {
return static_cast<int>( log10( static_cast<double>( temp ) ) ) + 2;
return static_cast<int>( std::log10( static_cast<double>( temp ) ) ) + 2;
}
return 1;
}
Expand Down
2 changes: 1 addition & 1 deletion src/player_display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ static void draw_stats_tab( const catacurses::window &w_stats, const catacurses:
string_format( _( "Melee to-hit bonus: <color_white>%+.1lf</color>" ), you.get_melee_hit_base() ) );
print_colored_text( w_info, point( 1, 4 ), col_temp, c_light_gray,
string_format( _( "Ranged penalty: <color_white>%+d</color>" ),
-abs( you.ranged_dex_mod() ) ) );
-std::abs( you.ranged_dex_mod() ) ) );
print_colored_text( w_info, point( 1, 5 ), col_temp, c_light_gray,
string_format( _( "Throwing penalty per target's dodge: <color_white>%+d</color>" ),
you.throw_dispersion_per_dodge( false ) ) );
Expand Down
Loading

0 comments on commit 30960c2

Please sign in to comment.