Skip to content

Commit

Permalink
Use std::numbers::pi instead of M_PI
Browse files Browse the repository at this point in the history
  • Loading branch information
jhasse committed Oct 29, 2024
1 parent 5605e2d commit 948f552
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 13 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ else() # Windows
endif()
option(JNGL_SDL2 "Use SDL2 instead of WinAPI" ${JNGL_SDL2_DEFAULT})

target_compile_definitions(jngl PRIVATE _WIN32_WINNT=0x602 _USE_MATH_DEFINES _SILENCE_ALL_CXX20_DEPRECATION_WARNINGS UNICODE)
target_compile_definitions(jngl PRIVATE _WIN32_WINNT=0x602 _SILENCE_ALL_CXX20_DEPRECATION_WARNINGS UNICODE)
if(JNGL_SDL2)
file(GLOB SRC src/sdl/*.cpp)
if(WINDOWS_STORE)
Expand Down
2 changes: 1 addition & 1 deletion src/jngl/effects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ float linear(float t) {
}

float elastic(float t) {
const float c4 = (2 * M_PI) / 3;
const float c4 = (2 * std::numbers::pi) / 3;

return t <= 0 ? 0 : t >= 1 ? 1 : pow(2, -10 * t) * sin((t * 10 - 0.75) * c4) + 1;
}
Expand Down
2 changes: 1 addition & 1 deletion src/jngl/shapes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ void drawEllipse(Mat3 modelview, float width, float height, float startAngle) {
std::vector<float> vertexes;
vertexes.push_back(0.f);
vertexes.push_back(0.f);
for (float t = startAngle; t < 2.f * M_PI; t += 0.1f) {
for (float t = startAngle; t < 2.f * std::numbers::pi; t += 0.1f) {
vertexes.push_back(width * std::sin(t));
vertexes.push_back(-height * std::cos(t));
}
Expand Down
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ void reset() {
}

void rotate(const double degree) {
boost::qvm::rotate_z(opengl::modelview, degree * M_PI / 180.);
boost::qvm::rotate_z(opengl::modelview, degree * std::numbers::pi / 180.);
}

void translate(const double x, const double y) {
Expand Down
15 changes: 9 additions & 6 deletions src/test/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class Test : public jngl::Work {
if (rotate > 360) {
rotate = 0;
}
factor = std::sin(rotate / 360 * M_PI);
factor = std::sin(rotate / 360 * std::numbers::pi);
logoWebp.setPos(-logoWebp.getWidth() * factor, -logoWebp.getHeight() * factor);
volume += static_cast<float>(jngl::getMouseWheel()) / 100.0f;
if (jngl::keyPressed('p') || jngl::keyPressed('P')) {
Expand Down Expand Up @@ -121,15 +121,16 @@ class Test : public jngl::Work {
}
}
drawBackground();
jngl::setColor(0,0,0,255);
jngl::setColor(0, 0, 0, 255);
jngl::drawLine(jngl::modelview()
.translate({ 650, 450 })
.rotate(rotate / 360 * M_PI)
.rotate(rotate / 360 * std::numbers::pi)
.translate({ -50, -50 }),
{ 100, 100 });
jngl::setSpriteAlpha(200);
auto rotatedMv =
jngl::modelview().translate(jngl::getScreenSize() / 2).rotate(rotate / 180 * M_PI);
auto rotatedMv = jngl::modelview()
.translate(jngl::getScreenSize() / 2)
.rotate(rotate / 180 * std::numbers::pi);
jngl::popMatrix();
jngl::setSpriteAlpha(static_cast<unsigned char>(std::abs(factor * 255)));
if (useShader) {
Expand Down Expand Up @@ -308,7 +309,9 @@ void Test::drawBackground() const {
void drawMouse(const jngl::Vec2 mouse) {
jngl::setFontSize(30);
jngl::setFontColor(10, 10, 200, 200);
jngl::print(jngl::modelview().translate(mouse).rotate(-M_PI / 4).translate({ -8, -2 }), "");
jngl::print(
jngl::modelview().translate(mouse).rotate(-std::numbers::pi / 4).translate({ -8, -2 }),
"");
jngl::setFontSize(12);
jngl::reset();
}
Expand Down
6 changes: 3 additions & 3 deletions src/unittest/Vec2Test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ boost::ut::suite _ = [] {
expect(eq(std::format("{}", a), std::string("[x=1, y=0]")));
#endif

a.rotate(M_PI / 2);
a.rotate(std::numbers::pi / 2);
//
// o
// |
Expand All @@ -28,7 +28,7 @@ boost::ut::suite _ = [] {
expect(approx(a.x, 0., 1e-6));
expect(approx(a.y, 1., 1e-6)); // JNGL uses negative y for up and positive for down.

a.rotate(-M_PI / 4);
a.rotate(-std::numbers::pi / 4);
//
// o
//
Expand All @@ -39,7 +39,7 @@ boost::ut::suite _ = [] {
a.rotate(0);
expect(approx(a.x, sqrt(2) / 2., 1e-6));
expect(approx(a.y, sqrt(2) / 2., 1e-6));
a.rotate(M_PI * 8);
a.rotate(std::numbers::pi * 8);
expect(approx(a.x, sqrt(2) / 2., 1e-6));
expect(approx(a.y, sqrt(2) / 2., 1e-6));
};
Expand Down

0 comments on commit 948f552

Please sign in to comment.