Replace all kinds of the constant pi representations.
Replaces every appearance of the circle constant pi I could find with the representation from boost/math/constants/constants.hpp.
This commit is contained in:
parent
66ee6c4857
commit
f5e673e644
4 changed files with 17 additions and 16 deletions
|
@ -22,6 +22,8 @@
|
|||
#include "log.hpp"
|
||||
|
||||
#include <boost/foreach.hpp>
|
||||
#include <boost/math/constants/constants.hpp>
|
||||
using namespace boost::math::constants;
|
||||
|
||||
#ifdef HAVE_VISUAL_LEAK_DETECTOR
|
||||
#include "vld.h"
|
||||
|
@ -37,8 +39,6 @@ static lg::log_domain log_scripting_formula("scripting/formula");
|
|||
|
||||
namespace game_logic {
|
||||
|
||||
static const double pi = 4. * atan(1.);
|
||||
|
||||
std::string function_expression::str() const
|
||||
{
|
||||
std::stringstream s;
|
||||
|
@ -473,7 +473,7 @@ private:
|
|||
args()[0]->evaluate(variables,fdb).as_decimal() / 1000.;
|
||||
|
||||
return variant(
|
||||
static_cast<int>(1000. * sin(angle * pi / 180.))
|
||||
static_cast<int>(1000. * sin(angle * pi<double>() / 180.))
|
||||
, variant::DECIMAL_VARIANT);
|
||||
}
|
||||
};
|
||||
|
@ -493,7 +493,7 @@ private:
|
|||
args()[0]->evaluate(variables,fdb).as_decimal() / 1000.;
|
||||
|
||||
return variant(
|
||||
static_cast<int>(1000. * cos(angle * pi / 180.))
|
||||
static_cast<int>(1000. * cos(angle * pi<double>() / 180.))
|
||||
, variant::DECIMAL_VARIANT);
|
||||
}
|
||||
};
|
||||
|
@ -571,7 +571,7 @@ public:
|
|||
private:
|
||||
variant execute(const formula_callable& variables, formula_debugger *fdb) const {
|
||||
const int value = args()[0]->evaluate(variables,fdb).as_int()%1000;
|
||||
const double angle = 2.0 * pi * (static_cast<double>(value) / 1000.0);
|
||||
const double angle = 2.0 * pi<double>() * (static_cast<double>(value) / 1000.0);
|
||||
return variant(static_cast<int>(sin(angle)*1000.0));
|
||||
}
|
||||
};
|
||||
|
|
|
@ -15,8 +15,8 @@
|
|||
#include "joystick.hpp"
|
||||
#include "preferences.hpp"
|
||||
#include "log.hpp"
|
||||
|
||||
#define PI 3.14159265
|
||||
#include <boost/math/constants/constants.hpp>
|
||||
using namespace boost::math::constants;
|
||||
|
||||
static lg::log_domain log_joystick("joystick");
|
||||
#define ERR_JOY LOG_STREAM(err, log_joystick)
|
||||
|
@ -233,7 +233,7 @@ std::pair<double, double> joystick_manager::get_polar_coordinates(int joystick_x
|
|||
const double radius = (sqrt(pow(values.first, 2.0f) + pow(values.second, 2.0f))) / 32768.0;
|
||||
const double angle = (atan2(
|
||||
static_cast<double>(values.second)
|
||||
, static_cast<double>(values.first))) * 180.0 / PI;
|
||||
, static_cast<double>(values.first))) * 180.0 / pi<double>();
|
||||
|
||||
return std::make_pair(radius, angle);
|
||||
}
|
||||
|
@ -392,7 +392,7 @@ double joystick_manager::get_angle() {
|
|||
|
||||
const double angle = (atan2(
|
||||
static_cast<double>(y_axis)
|
||||
, static_cast<double>(x_axis))) * 180.0 / PI;
|
||||
, static_cast<double>(x_axis))) * 180.0 / pi<double>();
|
||||
|
||||
return angle;
|
||||
}
|
||||
|
@ -406,7 +406,7 @@ const map_location joystick_manager::get_next_hex(int x_axis, int y_axis, map_lo
|
|||
if (y_axis == 0) return (x_axis > 0) ? get_direction(loc, EAST) : get_direction(loc, WEST);
|
||||
const double angle = (atan2(
|
||||
static_cast<double>(y_axis)
|
||||
, static_cast<double>(x_axis))) * 180.0 / PI;
|
||||
, static_cast<double>(x_axis))) * 180.0 / pi<double>();
|
||||
|
||||
if (angle < -112.5 && angle > -157.5)
|
||||
new_loc = get_direction(loc, NORTH_WEST);
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include <boost/math/constants/constants.hpp>
|
||||
|
||||
#define lmathlib_c
|
||||
#define LUA_LIB
|
||||
|
@ -16,9 +17,7 @@
|
|||
#include "lualib.h"
|
||||
|
||||
|
||||
#undef PI
|
||||
#define PI (3.14159265358979323846)
|
||||
#define RADIANS_PER_DEGREE (PI/180.0)
|
||||
#define RADIANS_PER_DEGREE ( boost::math::constants::pi<double>() / 180.0)
|
||||
|
||||
|
||||
/* macro 'l_tg' allows the addition of an 'l' or 'f' to all math operations */
|
||||
|
@ -273,7 +272,7 @@ static const luaL_Reg mathlib[] = {
|
|||
*/
|
||||
LUAMOD_API int luaopen_math (lua_State *L) {
|
||||
luaL_newlib(L, mathlib);
|
||||
lua_pushnumber(L, PI);
|
||||
lua_pushnumber(L, boost::math::constants::pi<double>());
|
||||
lua_setfield(L, -2, "pi");
|
||||
lua_pushnumber(L, HUGE_VAL);
|
||||
lua_setfield(L, -2, "huge");
|
||||
|
|
|
@ -30,6 +30,8 @@
|
|||
#include <cstring>
|
||||
#include <iostream>
|
||||
|
||||
#include <boost/math/constants/constants.hpp>
|
||||
|
||||
surface_lock::surface_lock(surface &surf) : surface_(surf), locked_(false)
|
||||
{
|
||||
if (SDL_MUSTLOCK(surface_))
|
||||
|
@ -1636,8 +1638,8 @@ surface rotate_any_surface(const surface& surf, float angle, int zoom, int offse
|
|||
int src_w, src_h, dst_w, dst_h;
|
||||
float min_x, max_x, min_y, max_y, sine, cosine;
|
||||
{
|
||||
// convert angle to radiant (angle * 2 * M_PI) / 360
|
||||
const float radians = angle * M_PI / 180;
|
||||
// convert angle to radiant (angle * 2 * PI) / 360
|
||||
const float radians = angle * boost::math::constants::pi<float>() / 180;
|
||||
cosine = static_cast<float>(cos(radians));
|
||||
sine = static_cast<float>(sin(radians));
|
||||
// calculate the size of the dst image
|
||||
|
|
Loading…
Add table
Reference in a new issue