1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 02:27:35 +00:00

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.
This commit is contained in:
Nicholas-Baron 2021-04-15 00:36:14 -07:00 committed by Andreas Kling
parent 6606d70826
commit 73dd293ec4
26 changed files with 105 additions and 98 deletions

View file

@ -36,15 +36,15 @@ namespace PixelPaint {
static Gfx::IntPoint constrain_line_angle(const Gfx::IntPoint& start_pos, const Gfx::IntPoint& end_pos, float angle_increment)
{
float current_angle = atan2(end_pos.y() - start_pos.y(), end_pos.x() - start_pos.x()) + M_PI * 2.;
float current_angle = atan2f(end_pos.y() - start_pos.y(), end_pos.x() - start_pos.x()) + float { M_PI * 2 };
float constrained_angle = ((int)((current_angle + angle_increment / 2.) / angle_increment)) * angle_increment;
float constrained_angle = ((int)((current_angle + angle_increment / 2) / angle_increment)) * angle_increment;
auto diff = end_pos - start_pos;
float line_length = sqrt(diff.x() * diff.x() + diff.y() * diff.y());
return { start_pos.x() + (int)(cos(constrained_angle) * line_length),
start_pos.y() + (int)(sin(constrained_angle) * line_length) };
return { start_pos.x() + (int)(cosf(constrained_angle) * line_length),
start_pos.y() + (int)(sinf(constrained_angle) * line_length) };
}
LineTool::LineTool()
@ -90,7 +90,7 @@ void LineTool::on_mousemove(Layer&, GUI::MouseEvent& layer_event, GUI::MouseEven
if (!m_constrain_angle) {
m_line_end_position = layer_event.position();
} else {
const float ANGLE_STEP = M_PI / 8.0f;
constexpr auto ANGLE_STEP = M_PI / 8;
m_line_end_position = constrain_line_angle(m_line_start_position, layer_event.position(), ANGLE_STEP);
}
m_editor->update();