Skip to content

Commit

Permalink
Remove _USE_MATH_DEFINES dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
austinmhorn committed Jul 27, 2023
1 parent 6589f19 commit 5888e29
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
7 changes: 4 additions & 3 deletions src/leafy/Button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
#include <SFML/Graphics/Texture.hpp>

#include <cmath>
#include <math.h>

#define _USE_MATH_DEFINES
#ifndef _PI
#define _PI 3.14159265358979323846
#endif

Button::Button(const sf::Vector2f& radius, float pointCount)
: m_radius(radius)
Expand Down Expand Up @@ -59,7 +60,7 @@ std::size_t Button::getPointCount() const
}
sf::Vector2f Button::getPoint(std::size_t index) const
{
float angle = index * 2 * M_PI / getPointCount() - M_PI / 2;
float angle = index * 2 * _PI / getPointCount() - _PI / 2;
float x = std::cos(angle) * m_radius.x;
float y = std::sin(angle) * m_radius.y;
return sf::Vector2f(m_radius.x + x, m_radius.y + y);
Expand Down
6 changes: 4 additions & 2 deletions src/leafy/ConvexShape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@

#include <cmath>

#define _USE_MATH_DEFINES
#ifndef _PI
#define _PI 3.14159265358979323846
#endif

namespace sf
{
Expand Down Expand Up @@ -40,7 +42,7 @@ namespace sf
}
sf::Vector2f ConvexShape::getPoint(std::size_t index) const
{
float angle = index * 2 * M_PI / getPointCount() - M_PI / 2;
float angle = index * 2 * _PI / getPointCount() - _PI / 2;
float x = std::cos(angle) * m_radius.x;
float y = std::sin(angle) * m_radius.y;
return sf::Vector2f(m_radius.x + x, m_radius.y + y);
Expand Down
9 changes: 6 additions & 3 deletions src/leafy/StadiumShape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
#include <leafy/StadiumShape.hpp>

#include <cmath>
#define _USE_MATH_DEFINES

#ifndef _PI
#define _PI 3.14159265358979323846
#endif

sf::StadiumShape::StadiumShape(float radius) :
m_size(300.0f, 60.0f),
Expand Down Expand Up @@ -97,8 +100,8 @@ sf::Vector2f sf::StadiumShape::getPoint(std::size_t index) const
break;
}

return sf::Vector2f(m_radius * std::cos(delta_angle * (index - center_index) * M_PI / 180.0f) + center.x,
-m_radius * std::sin(delta_angle * (index - center_index) * M_PI / 180.0f) + center.y);
return sf::Vector2f(m_radius * std::cos(delta_angle * (index - center_index) * _PI / 180.0f) + center.x,
-m_radius * std::sin(delta_angle * (index - center_index) * _PI / 180.0f) + center.y);
}

#undef _USE_MATH_DEFINES

0 comments on commit 5888e29

Please sign in to comment.