From f84191204ee98b8a09141709f111119f35fa1888 Mon Sep 17 00:00:00 2001 From: Mickey Rose Date: Fri, 13 Jul 2018 17:03:54 +0200 Subject: [PATCH] eradicate M_PI --- include/mapnik/global.hpp | 8 ------- include/mapnik/markers_placements/basic.hpp | 21 +++++++++++-------- include/mapnik/offset_converter.hpp | 17 +++++++-------- src/text/placement_finder.cpp | 8 ++++--- src/vertex_cache.cpp | 4 ++-- test/unit/vertex_adapter/line_offset_test.cpp | 8 +++---- test/unit/vertex_adapter/offset_converter.cpp | 7 ++++--- 7 files changed, 35 insertions(+), 38 deletions(-) diff --git a/include/mapnik/global.hpp b/include/mapnik/global.hpp index 39a7996f1..cb36e878e 100644 --- a/include/mapnik/global.hpp +++ b/include/mapnik/global.hpp @@ -123,14 +123,6 @@ inline double round(double val) } #endif -#if defined(_MSC_VER) -#define _USE_MATH_DEFINES -#ifndef M_PI -#define M_PI 3.14159265358979323846 -#endif - -#endif - } diff --git a/include/mapnik/markers_placements/basic.hpp b/include/mapnik/markers_placements/basic.hpp index 9ffcd6fb5..84520d12d 100644 --- a/include/mapnik/markers_placements/basic.hpp +++ b/include/mapnik/markers_placements/basic.hpp @@ -75,24 +75,27 @@ protected: angle = 0; return true; case DIRECTION_DOWN: - angle = M_PI; + angle = util::pi; return true; case DIRECTION_AUTO: - if (std::fabs(util::normalize_angle(angle)) > 0.5 * M_PI) - angle += M_PI; + angle = util::normalize_angle(angle); + if (std::abs(angle) > util::pi / 2) + angle += util::pi; return true; case DIRECTION_AUTO_DOWN: - if (std::fabs(util::normalize_angle(angle)) < 0.5 * M_PI) - angle += M_PI; + angle = util::normalize_angle(angle); + if (std::abs(angle) < util::pi / 2) + angle += util::pi; return true; case DIRECTION_LEFT: - angle += M_PI; + angle += util::pi; return true; case DIRECTION_LEFT_ONLY: - angle += M_PI; - return std::fabs(util::normalize_angle(angle)) < 0.5 * M_PI; + angle = util::normalize_angle(angle + util::pi); + return std::fabs(angle) < util::pi / 2; 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: default: return true; diff --git a/include/mapnik/offset_converter.hpp b/include/mapnik/offset_converter.hpp index e3a3c5f5b..3a32761d8 100644 --- a/include/mapnik/offset_converter.hpp +++ b/include/mapnik/offset_converter.hpp @@ -26,7 +26,6 @@ #ifdef MAPNIK_LOG #include #endif -#include #include #include #include @@ -185,13 +184,13 @@ private: 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 { @@ -463,12 +462,12 @@ private: double joint_angle = this->joint_angle(v_x1x0, v_y1y0, v_x1x2, v_y1y2); 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); // Bulge steps should be determined by the inverse of the joint angle. double half_turns = half_turn_segments_ * std::fabs(curve_angle); - bulge_steps = 1 + static_cast(std::floor(half_turns / M_PI)); + bulge_steps = 1 + static_cast(std::floor(half_turns / util::pi)); } if (bulge_steps == 0) @@ -557,12 +556,12 @@ private: double joint_angle = this->joint_angle(v_x1x0, v_y1y0, v_x1x2, v_y1y2); 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); // Bulge steps should be determined by the inverse of the joint angle. double half_turns = half_turn_segments_ * std::fabs(curve_angle); - bulge_steps = 1 + static_cast(std::floor(half_turns / M_PI)); + bulge_steps = 1 + static_cast(std::floor(half_turns / util::pi)); } #ifdef MAPNIK_LOG diff --git a/src/text/placement_finder.cpp b/src/text/placement_finder.cpp index b20be3612..7d0d73461 100644 --- a/src/text/placement_finder.cpp +++ b/src/text/placement_finder.cpp @@ -135,11 +135,13 @@ text_upright_e placement_finder::simplify_upright(text_upright_e upright, double { 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) { - 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) { @@ -332,7 +334,7 @@ bool placement_finder::single_line_placement(vertex_cache &pp, text_upright_e or last_cluster_angle = angle; } - if (std::abs(angle) > M_PI/2) + if (std::abs(angle) > util::tau / 4) { ++upside_down_glyph_count; } diff --git a/src/vertex_cache.cpp b/src/vertex_cache.cpp index ac4f20274..0a55d5737 100644 --- a/src/vertex_cache.cpp +++ b/src/vertex_cache.cpp @@ -20,7 +20,7 @@ * *****************************************************************************/ // mapnik -#include +#include #include #include #include @@ -75,7 +75,7 @@ double vertex_cache::angle(double width) angle_ = current_segment_angle(); } } - return width >= 0 ? angle_ : angle_ + M_PI; + return width >= 0 ? angle_ : angle_ + util::pi; } bool vertex_cache::next_subpath() diff --git a/test/unit/vertex_adapter/line_offset_test.cpp b/test/unit/vertex_adapter/line_offset_test.cpp index 75bfb0799..36e399298 100644 --- a/test/unit/vertex_adapter/line_offset_test.cpp +++ b/test/unit/vertex_adapter/line_offset_test.cpp @@ -3,8 +3,8 @@ #include "fake_path.hpp" // mapnik +#include #include -#include // stl #include @@ -55,7 +55,7 @@ void test_offset_curve(double const &offset) { std::vector pos, off_pos; const size_t max_i = 1000; 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)); 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 pos, off_pos; const size_t max_i = 1000; 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)); 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) { - 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)); off_pos.push_back(-r2 * std::cos(x) + 1); off_pos.push_back(-r2 * std::sin(x)); } diff --git a/test/unit/vertex_adapter/offset_converter.cpp b/test/unit/vertex_adapter/offset_converter.cpp index 1493127d4..0df728b3a 100644 --- a/test/unit/vertex_adapter/offset_converter.cpp +++ b/test/unit/vertex_adapter/offset_converter.cpp @@ -4,6 +4,7 @@ // mapnik #include +#include // stl #include @@ -134,7 +135,7 @@ void test_offset_curve(double const &offset) { std::vector pos, off_pos; const size_t max_i = 1000; 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)); 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 pos, off_pos; const size_t max_i = 1000; 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)); 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) { - 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)); off_pos.push_back(-r2 * std::cos(x) + 1); off_pos.push_back(-r2 * std::sin(x)); }