summaryrefslogtreecommitdiff
path: root/Userland/Games
diff options
context:
space:
mode:
authorNicholas-Baron <nicholas.baron.ten@gmail.com>2021-04-15 00:36:14 -0700
committerAndreas Kling <kling@serenityos.org>2021-04-16 19:01:54 +0200
commit73dd293ec4ffcfefae9db8e10eaaa84d4a4be4a8 (patch)
tree835bd47b8c14f8af6b070f1adbeef630db28d5a9 /Userland/Games
parent6606d70826b21c803742ed2b971d061b7f3497e3 (diff)
downloadserenity-73dd293ec4ffcfefae9db8e10eaaa84d4a4be4a8.zip
Everywhere: Add `-Wdouble-promotion` warning
This warning informs of float-to-double conversions. The best solution seems to be to do math *either* in 32-bit *or* in 64-bit, and only to cross over when absolutely necessary.
Diffstat (limited to 'Userland/Games')
-rw-r--r--Userland/Games/Chess/ChessWidget.cpp15
-rw-r--r--Userland/Games/Solitaire/SolitaireWidget.cpp2
2 files changed, 10 insertions, 7 deletions
diff --git a/Userland/Games/Chess/ChessWidget.cpp b/Userland/Games/Chess/ChessWidget.cpp
index e3b31b33e3..c96ef0715c 100644
--- a/Userland/Games/Chess/ChessWidget.cpp
+++ b/Userland/Games/Chess/ChessWidget.cpp
@@ -111,15 +111,18 @@ void ChessWidget::paint_event(GUI::PaintEvent& event)
float dx = B.x() - A.x();
float dy = A.y() - B.y();
float phi = atan2f(dy, dx);
- float hdx = h * cos(phi);
- float hdy = h * sin(phi);
+ float hdx = h * cosf(phi);
+ float hdy = h * sinf(phi);
- Gfx::FloatPoint A1(A.x() - (w1 / 2) * cos(M_PI_2 - phi), A.y() - (w1 / 2) * sin(M_PI_2 - phi));
- Gfx::FloatPoint B3(A.x() + (w1 / 2) * cos(M_PI_2 - phi), A.y() + (w1 / 2) * sin(M_PI_2 - phi));
+ const auto cos_pi_2_phi = cosf(float { M_PI_2 } - phi);
+ const auto sin_pi_2_phi = sinf(float { M_PI_2 } - phi);
+
+ Gfx::FloatPoint A1(A.x() - (w1 / 2) * cos_pi_2_phi, A.y() - (w1 / 2) * sin_pi_2_phi);
+ Gfx::FloatPoint B3(A.x() + (w1 / 2) * cos_pi_2_phi, A.y() + (w1 / 2) * sin_pi_2_phi);
Gfx::FloatPoint A2(A1.x() + (dx - hdx), A1.y() - (dy - hdy));
Gfx::FloatPoint B2(B3.x() + (dx - hdx), B3.y() - (dy - hdy));
- Gfx::FloatPoint A3(A2.x() - w2 * cos(M_PI_2 - phi), A2.y() - w2 * sin(M_PI_2 - phi));
- Gfx::FloatPoint B1(B2.x() + w2 * cos(M_PI_2 - phi), B2.y() + w2 * sin(M_PI_2 - phi));
+ Gfx::FloatPoint A3(A2.x() - w2 * cos_pi_2_phi, A2.y() - w2 * sin_pi_2_phi);
+ Gfx::FloatPoint B1(B2.x() + w2 * cos_pi_2_phi, B2.y() + w2 * sin_pi_2_phi);
auto path = Gfx::Path();
path.move_to(A);
diff --git a/Userland/Games/Solitaire/SolitaireWidget.cpp b/Userland/Games/Solitaire/SolitaireWidget.cpp
index fbf1cc7eb1..0a2e04c643 100644
--- a/Userland/Games/Solitaire/SolitaireWidget.cpp
+++ b/Userland/Games/Solitaire/SolitaireWidget.cpp
@@ -92,7 +92,7 @@ void SolitaireWidget::create_new_animation_card()
card->set_position({ rand() % (SolitaireWidget::width - Card::width), rand() % (SolitaireWidget::height / 8) });
int x_sgn = card->position().x() > (SolitaireWidget::width / 2) ? -1 : 1;
- m_animation = Animation(card, rand_float() + .4, x_sgn * ((rand() % 3) + 2), .6 + rand_float() * .4);
+ m_animation = Animation(card, rand_float() + .4f, x_sgn * ((rand() % 3) + 2), .6f + rand_float() * .4f);
}
void SolitaireWidget::start_game_over_animation()