eradicate M_PI

This commit is contained in:
Mickey Rose 2018-07-13 17:03:54 +02:00
parent 32e7202223
commit f84191204e
7 changed files with 35 additions and 38 deletions

View file

@ -123,14 +123,6 @@ inline double round(double val)
} }
#endif #endif
#if defined(_MSC_VER)
#define _USE_MATH_DEFINES
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#endif
} }

View file

@ -75,24 +75,27 @@ protected:
angle = 0; angle = 0;
return true; return true;
case DIRECTION_DOWN: case DIRECTION_DOWN:
angle = M_PI; angle = util::pi;
return true; return true;
case DIRECTION_AUTO: case DIRECTION_AUTO:
if (std::fabs(util::normalize_angle(angle)) > 0.5 * M_PI) angle = util::normalize_angle(angle);
angle += M_PI; if (std::abs(angle) > util::pi / 2)
angle += util::pi;
return true; return true;
case DIRECTION_AUTO_DOWN: case DIRECTION_AUTO_DOWN:
if (std::fabs(util::normalize_angle(angle)) < 0.5 * M_PI) angle = util::normalize_angle(angle);
angle += M_PI; if (std::abs(angle) < util::pi / 2)
angle += util::pi;
return true; return true;
case DIRECTION_LEFT: case DIRECTION_LEFT:
angle += M_PI; angle += util::pi;
return true; return true;
case DIRECTION_LEFT_ONLY: case DIRECTION_LEFT_ONLY:
angle += M_PI; angle = util::normalize_angle(angle + util::pi);
return std::fabs(util::normalize_angle(angle)) < 0.5 * M_PI; return std::fabs(angle) < util::pi / 2;
case DIRECTION_RIGHT_ONLY: case DIRECTION_RIGHT_ONLY:
return std::fabs(util::normalize_angle(angle)) < 0.5 * M_PI; angle = util::normalize_angle(angle);
return std::fabs(angle) < util::pi / 2;
case DIRECTION_RIGHT: case DIRECTION_RIGHT:
default: default:
return true; return true;

View file

@ -26,7 +26,6 @@
#ifdef MAPNIK_LOG #ifdef MAPNIK_LOG
#include <mapnik/debug.hpp> #include <mapnik/debug.hpp>
#endif #endif
#include <mapnik/global.hpp>
#include <mapnik/config.hpp> #include <mapnik/config.hpp>
#include <mapnik/util/math.hpp> #include <mapnik/util/math.hpp>
#include <mapnik/vertex.hpp> #include <mapnik/vertex.hpp>
@ -185,13 +184,13 @@ private:
static double explement_reflex_angle(double angle) static double explement_reflex_angle(double angle)
{ {
if (angle > M_PI) if (angle > util::pi)
{ {
return angle - 2 * M_PI; return angle - util::tau;
} }
else if (angle < -M_PI) else if (angle < -util::pi)
{ {
return angle + 2 * M_PI; return angle + util::tau;
} }
else else
{ {
@ -463,12 +462,12 @@ private:
double joint_angle = this->joint_angle(v_x1x0, v_y1y0, v_x1x2, v_y1y2); double joint_angle = this->joint_angle(v_x1x0, v_y1y0, v_x1x2, v_y1y2);
int bulge_steps = 0; int bulge_steps = 0;
if (std::abs(joint_angle) > M_PI) if (std::abs(joint_angle) > util::pi)
{ {
curve_angle = explement_reflex_angle(angle_b - angle_a); curve_angle = explement_reflex_angle(angle_b - angle_a);
// Bulge steps should be determined by the inverse of the joint angle. // Bulge steps should be determined by the inverse of the joint angle.
double half_turns = half_turn_segments_ * std::fabs(curve_angle); double half_turns = half_turn_segments_ * std::fabs(curve_angle);
bulge_steps = 1 + static_cast<int>(std::floor(half_turns / M_PI)); bulge_steps = 1 + static_cast<int>(std::floor(half_turns / util::pi));
} }
if (bulge_steps == 0) if (bulge_steps == 0)
@ -557,12 +556,12 @@ private:
double joint_angle = this->joint_angle(v_x1x0, v_y1y0, v_x1x2, v_y1y2); double joint_angle = this->joint_angle(v_x1x0, v_y1y0, v_x1x2, v_y1y2);
int bulge_steps = 0; int bulge_steps = 0;
if (std::abs(joint_angle) > M_PI) if (std::abs(joint_angle) > util::pi)
{ {
curve_angle = explement_reflex_angle(angle_b - angle_a); curve_angle = explement_reflex_angle(angle_b - angle_a);
// Bulge steps should be determined by the inverse of the joint angle. // Bulge steps should be determined by the inverse of the joint angle.
double half_turns = half_turn_segments_ * std::fabs(curve_angle); double half_turns = half_turn_segments_ * std::fabs(curve_angle);
bulge_steps = 1 + static_cast<int>(std::floor(half_turns / M_PI)); bulge_steps = 1 + static_cast<int>(std::floor(half_turns / util::pi));
} }
#ifdef MAPNIK_LOG #ifdef MAPNIK_LOG

View file

@ -135,11 +135,13 @@ text_upright_e placement_finder::simplify_upright(text_upright_e upright, double
{ {
if (upright == UPRIGHT_AUTO) if (upright == UPRIGHT_AUTO)
{ {
return (std::fabs(util::normalize_angle(angle)) > 0.5*M_PI) ? UPRIGHT_LEFT : UPRIGHT_RIGHT; angle = util::normalize_angle(angle);
return std::abs(angle) > util::tau / 4 ? UPRIGHT_LEFT : UPRIGHT_RIGHT;
} }
if (upright == UPRIGHT_AUTO_DOWN) if (upright == UPRIGHT_AUTO_DOWN)
{ {
return (std::fabs(util::normalize_angle(angle)) < 0.5*M_PI) ? UPRIGHT_LEFT : UPRIGHT_RIGHT; angle = util::normalize_angle(angle);
return std::abs(angle) < util::tau / 4 ? UPRIGHT_LEFT : UPRIGHT_RIGHT;
} }
if (upright == UPRIGHT_LEFT_ONLY) if (upright == UPRIGHT_LEFT_ONLY)
{ {
@ -332,7 +334,7 @@ bool placement_finder::single_line_placement(vertex_cache &pp, text_upright_e or
last_cluster_angle = angle; last_cluster_angle = angle;
} }
if (std::abs(angle) > M_PI/2) if (std::abs(angle) > util::tau / 4)
{ {
++upside_down_glyph_count; ++upside_down_glyph_count;
} }

View file

@ -20,7 +20,7 @@
* *
*****************************************************************************/ *****************************************************************************/
// mapnik // mapnik
#include <mapnik/global.hpp> #include <mapnik/util/math.hpp>
#include <mapnik/vertex_cache.hpp> #include <mapnik/vertex_cache.hpp>
#include <mapnik/offset_converter.hpp> #include <mapnik/offset_converter.hpp>
#include <mapnik/make_unique.hpp> #include <mapnik/make_unique.hpp>
@ -75,7 +75,7 @@ double vertex_cache::angle(double width)
angle_ = current_segment_angle(); angle_ = current_segment_angle();
} }
} }
return width >= 0 ? angle_ : angle_ + M_PI; return width >= 0 ? angle_ : angle_ + util::pi;
} }
bool vertex_cache::next_subpath() bool vertex_cache::next_subpath()

View file

@ -3,8 +3,8 @@
#include "fake_path.hpp" #include "fake_path.hpp"
// mapnik // mapnik
#include <mapnik/util/math.hpp>
#include <mapnik/vertex_cache.hpp> #include <mapnik/vertex_cache.hpp>
#include <mapnik/global.hpp>
// stl // stl
#include <iostream> #include <iostream>
@ -55,7 +55,7 @@ void test_offset_curve(double const &offset) {
std::vector<double> pos, off_pos; std::vector<double> pos, off_pos;
const size_t max_i = 1000; const size_t max_i = 1000;
for (size_t i = 0; i <= max_i; ++i) { for (size_t i = 0; i <= max_i; ++i) {
double x = M_PI * double(i) / max_i; double x = mapnik::util::pi * double(i) / max_i;
pos.push_back(-std::cos(x)); pos.push_back(std::sin(x)); pos.push_back(-std::cos(x)); pos.push_back(std::sin(x));
off_pos.push_back(-r * std::cos(x)); off_pos.push_back(r * std::sin(x)); off_pos.push_back(-r * std::cos(x)); off_pos.push_back(r * std::sin(x));
} }
@ -88,12 +88,12 @@ void test_s_shaped_curve(double const &offset) {
std::vector<double> pos, off_pos; std::vector<double> pos, off_pos;
const size_t max_i = 1000; const size_t max_i = 1000;
for (size_t i = 0; i <= max_i; ++i) { for (size_t i = 0; i <= max_i; ++i) {
double x = M_PI * double(i) / max_i; double x = mapnik::util::pi * double(i) / max_i;
pos.push_back(-std::cos(x) - 1); pos.push_back(std::sin(x)); pos.push_back(-std::cos(x) - 1); pos.push_back(std::sin(x));
off_pos.push_back(-r * std::cos(x) - 1); off_pos.push_back(r * std::sin(x)); off_pos.push_back(-r * std::cos(x) - 1); off_pos.push_back(r * std::sin(x));
} }
for (size_t i = 0; i <= max_i; ++i) { for (size_t i = 0; i <= max_i; ++i) {
double x = M_PI * double(i) / max_i; double x = mapnik::util::pi * double(i) / max_i;
pos.push_back(-std::cos(x) + 1); pos.push_back(-std::sin(x)); pos.push_back(-std::cos(x) + 1); pos.push_back(-std::sin(x));
off_pos.push_back(-r2 * std::cos(x) + 1); off_pos.push_back(-r2 * std::sin(x)); off_pos.push_back(-r2 * std::cos(x) + 1); off_pos.push_back(-r2 * std::sin(x));
} }

View file

@ -4,6 +4,7 @@
// mapnik // mapnik
#include <mapnik/offset_converter.hpp> #include <mapnik/offset_converter.hpp>
#include <mapnik/util/math.hpp>
// stl // stl
#include <iostream> #include <iostream>
@ -134,7 +135,7 @@ void test_offset_curve(double const &offset) {
std::vector<double> pos, off_pos; std::vector<double> pos, off_pos;
const size_t max_i = 1000; const size_t max_i = 1000;
for (size_t i = 0; i <= max_i; ++i) { for (size_t i = 0; i <= max_i; ++i) {
double x = M_PI * double(i) / max_i; double x = mapnik::util::pi * double(i) / max_i;
pos.push_back(-std::cos(x)); pos.push_back(std::sin(x)); pos.push_back(-std::cos(x)); pos.push_back(std::sin(x));
off_pos.push_back(-r * std::cos(x)); off_pos.push_back(r * std::sin(x)); off_pos.push_back(-r * std::cos(x)); off_pos.push_back(r * std::sin(x));
} }
@ -185,12 +186,12 @@ void test_s_shaped_curve(double const &offset) {
std::vector<double> pos, off_pos; std::vector<double> pos, off_pos;
const size_t max_i = 1000; const size_t max_i = 1000;
for (size_t i = 0; i <= max_i; ++i) { for (size_t i = 0; i <= max_i; ++i) {
double x = M_PI * double(i) / max_i; double x = mapnik::util::pi * double(i) / max_i;
pos.push_back(-std::cos(x) - 1); pos.push_back(std::sin(x)); pos.push_back(-std::cos(x) - 1); pos.push_back(std::sin(x));
off_pos.push_back(-r * std::cos(x) - 1); off_pos.push_back(r * std::sin(x)); off_pos.push_back(-r * std::cos(x) - 1); off_pos.push_back(r * std::sin(x));
} }
for (size_t i = 0; i <= max_i; ++i) { for (size_t i = 0; i <= max_i; ++i) {
double x = M_PI * double(i) / max_i; double x = mapnik::util::pi * double(i) / max_i;
pos.push_back(-std::cos(x) + 1); pos.push_back(-std::sin(x)); pos.push_back(-std::cos(x) + 1); pos.push_back(-std::sin(x));
off_pos.push_back(-r2 * std::cos(x) + 1); off_pos.push_back(-r2 * std::sin(x)); off_pos.push_back(-r2 * std::cos(x) + 1); off_pos.push_back(-r2 * std::sin(x));
} }