1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 04:37:44 +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

@ -68,7 +68,7 @@ MouseSettingsWindow::MouseSettingsWindow()
m_speed_slider->on_change = [&](const int value) {
m_speed_label->set_text(String::formatted("{} %", value));
};
const int slider_value = speed_slider_scale * GUI::WindowServerConnection::the().send_sync<Messages::WindowServer::GetMouseAcceleration>()->factor();
const int slider_value = float { speed_slider_scale } * GUI::WindowServerConnection::the().send_sync<Messages::WindowServer::GetMouseAcceleration>()->factor();
m_speed_slider->set_value(slider_value);
m_scroll_length_spinbox = *main_widget.find_descendant_of_type_named<GUI::SpinBox>("scroll_length_spinbox");

View file

@ -82,7 +82,7 @@ void BrushTool::draw_point(Gfx::Bitmap& bitmap, const Gfx::Color& color, const G
if (distance >= m_size)
continue;
auto falloff = (1.0 - (distance / (float)m_size)) * (1.0f / (100 - m_hardness));
auto falloff = (1.0 - double { distance / m_size }) * (1.0 / (100 - m_hardness));
auto pixel_color = color;
pixel_color.set_alpha(falloff * 255);
bitmap.set_pixel(x, y, bitmap.get_pixel(x, y).blend(pixel_color));

View file

@ -127,8 +127,8 @@ struct FilterParameters<Gfx::SpatialGaussianBlurFilter<N>> {
for (auto x = -offset; x <= offset; x++) {
for (auto y = -offset; y <= offset; y++) {
auto r = sqrt(x * x + y * y);
kernel.elements()[x + offset][y + offset] = (exp(-(r * r) / s)) / (M_PI * s);
auto r = sqrtf(x * x + y * y);
kernel.elements()[x + offset][y + offset] = (expf(-(r * r) / s)) / (float { M_PI } * s);
}
}

View file

@ -380,9 +380,10 @@ void ImageEditor::scale_centered_on_position(const Gfx::IntPoint& position, floa
if (m_scale > 100.0f)
m_scale = 100.0f;
auto focus_point = Gfx::FloatPoint(
m_pan_origin.x() - ((float)position.x() - (float)width() / 2.0) / old_scale,
m_pan_origin.y() - ((float)position.y() - (float)height() / 2.0) / old_scale);
Gfx::FloatPoint focus_point {
m_pan_origin.x() - (position.x() - width() / 2.0f) / old_scale,
m_pan_origin.y() - (position.y() - height() / 2.0f) / old_scale
};
m_pan_origin = Gfx::FloatPoint(
focus_point.x() - m_scale / old_scale * (focus_point.x() - m_pan_origin.x()),

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();

View file

@ -70,7 +70,7 @@ void SprayTool::paint_it()
m_editor->update();
const double minimal_radius = 2;
const double base_radius = minimal_radius * m_thickness;
for (int i = 0; i < M_PI * base_radius * base_radius * (m_density / 100.0f); i++) {
for (int i = 0; i < M_PI * base_radius * base_radius * (m_density / 100.0); i++) {
double radius = base_radius * nrand();
double angle = 2 * M_PI * nrand();
const int xpos = m_last_pos.x() + radius * cos(angle);

View file

@ -235,9 +235,10 @@ void QSWidget::mousewheel_event(GUI::MouseEvent& event)
// We want the image after scaling to be panned in such a way that the cursor
// will still point to the same image pixel. Basically, we need to solve
// (m_pan_origin + focus_point) / old_scale_factor = (new_m_pan_origin + focus_point) / new_scale_factor.
auto focus_point = Gfx::FloatPoint(
(float)event.x() - (float)width() / 2.0,
(float)event.y() - (float)height() / 2.0);
Gfx::FloatPoint focus_point {
event.x() - width() / 2.0f,
event.y() - height() / 2.0f
};
// A little algebra shows that new m_pan_origin equals to:
m_pan_origin = (m_pan_origin + focus_point) * (new_scale_factor / old_scale_factor) - focus_point;