Ver código fonte

Everywhere: Don't promote float to double where not needed

The `float => double => float` round trip seen in a couple of places
might pessimize the code. Even if it's truncated to an int in the end,
it's weird not to use the functions with the `f` suffixes when working
with single precision floats.
Daniel Bertalan 4 anos atrás
pai
commit
f14a4994b0

+ 1 - 1
Userland/Applets/ResourceGraph/main.cpp

@@ -94,7 +94,7 @@ private:
             if (value >= 0) {
                 painter.draw_line(
                     { rect.x() + i, rect.bottom() },
-                    { rect.x() + i, rect.top() + (int)(round(rect.height() - (value * rect.height()))) },
+                    { rect.x() + i, rect.top() + (int)(roundf(rect.height() - (value * rect.height()))) },
                     m_graph_color);
             } else {
                 painter.draw_line(

+ 1 - 1
Userland/Libraries/LibGfx/AffineTransform.cpp

@@ -18,7 +18,7 @@ bool AffineTransform::is_identity() const
 static float hypotenuse(float x, float y)
 {
     // FIXME: This won't handle overflow :(
-    return sqrt(x * x + y * y);
+    return sqrtf(x * x + y * y);
 }
 
 float AffineTransform::x_scale() const

+ 4 - 4
Userland/Libraries/LibGfx/Bitmap.cpp

@@ -420,8 +420,8 @@ RefPtr<Gfx::Bitmap> Bitmap::scaled(float sx, float sy) const
             auto p = static_cast<float>(x) * static_cast<float>(old_width - 1) / static_cast<float>(new_width - 1);
             auto q = static_cast<float>(y) * static_cast<float>(old_height - 1) / static_cast<float>(new_height - 1);
 
-            int i = floor(p);
-            int j = floor(q);
+            int i = floorf(p);
+            int j = floorf(q);
             float u = p - static_cast<float>(i);
             float v = q - static_cast<float>(j);
 
@@ -443,7 +443,7 @@ RefPtr<Gfx::Bitmap> Bitmap::scaled(float sx, float sy) const
     for (int x = 0; x < new_width - 1; x++) {
         auto p = static_cast<float>(x) * static_cast<float>(old_width - 1) / static_cast<float>(new_width - 1);
 
-        int i = floor(p);
+        int i = floorf(p);
         float u = p - static_cast<float>(i);
 
         auto a = get_pixel(i, old_bottom_y);
@@ -458,7 +458,7 @@ RefPtr<Gfx::Bitmap> Bitmap::scaled(float sx, float sy) const
     for (int y = 0; y < new_height - 1; y++) {
         auto q = static_cast<float>(y) * static_cast<float>(old_height - 1) / static_cast<float>(new_height - 1);
 
-        int j = floor(q);
+        int j = floorf(q);
         float v = q - static_cast<float>(j);
 
         auto c = get_pixel(old_right_x, j);

+ 1 - 1
Userland/Libraries/LibGfx/Painter.cpp

@@ -1902,7 +1902,7 @@ void Painter::for_each_line_segment_on_elliptical_arc(const FloatPoint& p1, cons
     if (theta_delta < 0) {
         swap(start, end);
         theta_1 = theta_1 + theta_delta;
-        theta_delta = fabs(theta_delta);
+        theta_delta = fabsf(theta_delta);
     }
 
     auto relative_start = start - center;

+ 7 - 7
Userland/Libraries/LibTTF/Glyf.cpp

@@ -270,8 +270,8 @@ void Rasterizer::draw_line(Gfx::FloatPoint p0, Gfx::FloatPoint p1)
     }
 
     float dxdy = (p1.x() - p0.x()) / (p1.y() - p0.y());
-    u32 y0 = floor(p0.y());
-    u32 y1 = ceil(p1.y());
+    u32 y0 = floorf(p0.y());
+    u32 y1 = ceilf(p1.y());
     float x_cur = p0.x();
 
     for (u32 y = y0; y < y1; y++) {
@@ -289,8 +289,8 @@ void Rasterizer::draw_line(Gfx::FloatPoint p0, Gfx::FloatPoint p1)
             x1 = x_cur;
             x0 = x_next;
         }
-        float x0_floor = floor(x0);
-        float x1_ceil = ceil(x1);
+        float x0_floor = floorf(x0);
+        float x1_ceil = ceilf(x1);
         u32 x0i = x0_floor;
 
         if (x1_ceil <= x0_floor + 1.0f) {
@@ -304,7 +304,7 @@ void Rasterizer::draw_line(Gfx::FloatPoint p0, Gfx::FloatPoint p1)
                 dydx = -dydx;
 
             float x0_right = 1.0f - (x0 - x0_floor);
-            u32 x1_floor_i = floor(x1);
+            u32 x1_floor_i = floorf(x1);
             float area_upto_here = 0.5f * x0_right * x0_right * dydx;
             m_data[line_offset + x0i] += direction * area_upto_here;
             for (u32 x = x0i + 1; x < x1_floor_i; x++) {
@@ -478,8 +478,8 @@ void Glyf::Glyph::raster_inner(Rasterizer& rasterizer, Gfx::AffineTransform& aff
 
 RefPtr<Gfx::Bitmap> Glyf::Glyph::raster_simple(float x_scale, float y_scale) const
 {
-    u32 width = (u32)(ceil((m_xmax - m_xmin) * x_scale)) + 2;
-    u32 height = (u32)(ceil((m_ymax - m_ymin) * y_scale)) + 2;
+    u32 width = (u32)(ceilf((m_xmax - m_xmin) * x_scale)) + 2;
+    u32 height = (u32)(ceilf((m_ymax - m_ymin) * y_scale)) + 2;
     Rasterizer rasterizer(Gfx::IntSize(width, height));
     auto affine = Gfx::AffineTransform().scale(x_scale, -y_scale).translate(-m_xmin, -m_ymax);
     raster_inner(rasterizer, affine);

+ 2 - 2
Userland/Libraries/LibTTF/Glyf.h

@@ -106,8 +106,8 @@ public:
         template<typename GlyphCb>
         RefPtr<Gfx::Bitmap> raster_composite(float x_scale, float y_scale, GlyphCb glyph_callback) const
         {
-            u32 width = (u32)(ceil((m_xmax - m_xmin) * x_scale)) + 1;
-            u32 height = (u32)(ceil((m_ymax - m_ymin) * y_scale)) + 1;
+            u32 width = (u32)(ceilf((m_xmax - m_xmin) * x_scale)) + 1;
+            u32 height = (u32)(ceilf((m_ymax - m_ymin) * y_scale)) + 1;
             Rasterizer rasterizer(Gfx::IntSize(width, height));
             auto affine = Gfx::AffineTransform().scale(x_scale, -y_scale).translate(-m_xmin, -m_ymax);
             ComponentIterator component_iterator(m_slice);