diff options
Diffstat (limited to 'Userland/Libraries')
-rw-r--r-- | Userland/Libraries/LibGfx/Gamma.h | 10 | ||||
-rw-r--r-- | Userland/Libraries/LibGfx/Painter.cpp | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibGfx/Path.cpp | 8 | ||||
-rw-r--r-- | Userland/Libraries/LibGfx/Rect.cpp | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibM/math.cpp | 16 | ||||
-rw-r--r-- | Userland/Libraries/LibTTF/Glyf.cpp | 40 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/Length.h | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/Dump.cpp | 4 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.cpp | 12 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/SVG/SVGPathElement.cpp | 2 |
10 files changed, 49 insertions, 49 deletions
diff --git a/Userland/Libraries/LibGfx/Gamma.h b/Userland/Libraries/LibGfx/Gamma.h index f0f3b86f25..345e30bff5 100644 --- a/Userland/Libraries/LibGfx/Gamma.h +++ b/Userland/Libraries/LibGfx/Gamma.h @@ -95,7 +95,7 @@ inline f32x4 gamma_accurate_lerp4(f32x4 v1, f32x4 v2, float mix) // Assumes x is in range [0, 1] constexpr float gamma_to_linear(float x) { - return (0.8 + 0.2 * x) * x * x; + return (0.8f + 0.2f * x) * x * x; } // Transform scalar from linear space to gamma2.2 space @@ -105,7 +105,7 @@ inline float linear_to_gamma(float x) // Source for approximation: https://mimosa-pudica.net/fast-gamma/ constexpr float a = 0.00279491; constexpr float b = 1.15907984; - float c = (b / sqrt(1 + a)) - 1; + float c = (b / sqrtf(1 + a)) - 1; return ((b / __builtin_sqrtf(x + a)) - c) * x; } @@ -135,9 +135,9 @@ inline Color gamma_accurate_blend(Color a, Color b, float mix) return Color(out[0], out[1], out[2]); # else return { - static_cast<u8>(255. * gamma_accurate_lerp(a.red() / 255., b.red() / 255., mix)), - static_cast<u8>(255. * gamma_accurate_lerp(a.green() / 255., b.green() / 255., mix)), - static_cast<u8>(255. * gamma_accurate_lerp(a.blue() / 255., b.blue() / 255., mix)), + static_cast<u8>(255.f * gamma_accurate_lerp(a.red() / 255.f, b.red() / 255.f, mix)), + static_cast<u8>(255.f * gamma_accurate_lerp(a.green() / 255.f, b.green() / 255.f, mix)), + static_cast<u8>(255.f * gamma_accurate_lerp(a.blue() / 255.f, b.blue() / 255.f, mix)), }; # endif } diff --git a/Userland/Libraries/LibGfx/Painter.cpp b/Userland/Libraries/LibGfx/Painter.cpp index e16792f716..2ad3624c7a 100644 --- a/Userland/Libraries/LibGfx/Painter.cpp +++ b/Userland/Libraries/LibGfx/Painter.cpp @@ -299,7 +299,7 @@ void Painter::draw_ellipse_intersecting(const IntRect& rect, Color color, int th return (sin(theta) * rect.height() / sqrt(2)) + rect.center().y(); }; - for (float theta = 0; theta < 2 * M_PI; theta += increment) { + for (auto theta = 0.0; theta < 2 * M_PI; theta += increment) { draw_line({ ellipse_x(theta), ellipse_y(theta) }, { ellipse_x(theta + increment), ellipse_y(theta + increment) }, color, thickness); } } diff --git a/Userland/Libraries/LibGfx/Path.cpp b/Userland/Libraries/LibGfx/Path.cpp index 9bb4e7fa53..18378d3be8 100644 --- a/Userland/Libraries/LibGfx/Path.cpp +++ b/Userland/Libraries/LibGfx/Path.cpp @@ -75,8 +75,8 @@ void Path::elliptical_arc_to(const FloatPoint& point, const FloatPoint& radii, d // Find (cx, cy), theta_1, theta_delta // Step 1: Compute (x1', y1') - auto x_avg = (last_point.x() - next_point.x()) / 2.0f; - auto y_avg = (last_point.y() - next_point.y()) / 2.0f; + auto x_avg = static_cast<double>(last_point.x() - next_point.x()) / 2.0; + auto y_avg = static_cast<double>(last_point.y() - next_point.y()) / 2.0; auto x1p = x_axis_rotation_c * x_avg + x_axis_rotation_s * y_avg; auto y1p = -x_axis_rotation_s * x_avg + x_axis_rotation_c * y_avg; @@ -118,7 +118,7 @@ void Path::elliptical_arc_to(const FloatPoint& point, const FloatPoint& radii, d auto theta_delta = theta_2 - theta_1; - if (!sweep && theta_delta > 0.0f) { + if (!sweep && theta_delta > 0.0) { theta_delta -= 2 * M_PI; } else if (sweep && theta_delta < 0) { theta_delta += 2 * M_PI; @@ -226,7 +226,7 @@ String Path::to_string() const break; case Segment::Type::EllipticalArcTo: { auto& arc = static_cast<const EllipticalArcSegment&>(segment); - builder.appendf(", %s, %s, %f, %f, %f", + builder.appendff(", {}, {}, {}, {}, {}", arc.radii().to_string().characters(), arc.center().to_string().characters(), arc.x_axis_rotation(), diff --git a/Userland/Libraries/LibGfx/Rect.cpp b/Userland/Libraries/LibGfx/Rect.cpp index 0a9ce4fc3b..ff135e6afd 100644 --- a/Userland/Libraries/LibGfx/Rect.cpp +++ b/Userland/Libraries/LibGfx/Rect.cpp @@ -160,7 +160,7 @@ String IntRect::to_string() const template<> String FloatRect::to_string() const { - return String::format("[%f,%f %fx%f]", x(), y(), width(), height()); + return String::formatted("[{},{} {}x{}]", x(), y(), width(), height()); } } diff --git a/Userland/Libraries/LibM/math.cpp b/Userland/Libraries/LibM/math.cpp index dc162a5873..12facc0850 100644 --- a/Userland/Libraries/LibM/math.cpp +++ b/Userland/Libraries/LibM/math.cpp @@ -172,9 +172,9 @@ static FloatType internal_to_integer(FloatType x, RoundingMode rounding_mode) // We could do this ourselves, but this saves us from manually // handling overflow. if (extractor.sign) - extractor.d -= 1.0; + extractor.d -= static_cast<FloatType>(1.0); else - extractor.d += 1.0; + extractor.d += static_cast<FloatType>(1.0); } return extractor.d; @@ -339,7 +339,7 @@ static FloatT internal_gamma(FloatT x) NOEXCEPT } // Stirling approximation - return sqrtl(2.0 * M_PI / x) * powl(x / M_E, x); + return sqrtl(2.0 * M_PI / static_cast<long double>(x)) * powl(static_cast<long double>(x) / M_E, static_cast<long double>(x)); } extern "C" { @@ -386,7 +386,7 @@ double cos(double angle) NOEXCEPT float cosf(float angle) NOEXCEPT { - return sinf(angle + M_PI_2); + return sinf(angle + static_cast<float>(M_PI_2)); } long double sinl(long double angle) NOEXCEPT @@ -636,7 +636,7 @@ double fmod(double index, double period) NOEXCEPT float fmodf(float index, float period) NOEXCEPT { - return index - trunc(index / period) * period; + return index - truncf(index / period) * period; } // FIXME: These aren't exactly like fmod, but these definitions are probably good enough for now @@ -818,7 +818,7 @@ double acos(double x) NOEXCEPT float acosf(float x) NOEXCEPT { - return M_PI_2 - asinf(x); + return static_cast<float>(M_PI_2) - asinf(x); } long double fabsl(long double value) NOEXCEPT @@ -1104,9 +1104,9 @@ double lgamma_r(double value, int* sign) NOEXCEPT float lgammaf_r(float value, int* sign) NOEXCEPT { - if (value == 1.0 || value == 2.0) + if (value == 1.0f || value == 2.0f) return 0.0; - if (isinf(value) || value == 0.0) + if (isinf(value) || value == 0.0f) return INFINITY; float result = logf(internal_gamma(value)); *sign = signbit(result) ? -1 : 1; diff --git a/Userland/Libraries/LibTTF/Glyf.cpp b/Userland/Libraries/LibTTF/Glyf.cpp index de1b5a292c..8c07ed5030 100644 --- a/Userland/Libraries/LibTTF/Glyf.cpp +++ b/Userland/Libraries/LibTTF/Glyf.cpp @@ -214,7 +214,7 @@ Rasterizer::Rasterizer(Gfx::IntSize size) { m_data.resize(m_size.width() * m_size.height()); for (int i = 0; i < m_size.width() * m_size.height(); i++) { - m_data[i] = 0.0; + m_data[i] = 0.0f; } } @@ -234,13 +234,13 @@ RefPtr<Gfx::Bitmap> Rasterizer::accumulate() for (int x = 0; x < m_size.width(); x++) { accumulator += m_data[y * m_size.width() + x]; float value = accumulator; - if (value < 0.0) { + if (value < 0.0f) { value = -value; } - if (value > 1.0) { + if (value > 1.0f) { value = 1.0; } - u8 alpha = value * 255.0; + u8 alpha = value * 255.0f; bitmap->set_pixel(x, y, base_color.with_alpha(alpha)); } } @@ -250,31 +250,31 @@ RefPtr<Gfx::Bitmap> Rasterizer::accumulate() void Rasterizer::draw_line(Gfx::FloatPoint p0, Gfx::FloatPoint p1) { // FIXME: Shift x and y according to dy/dx - if (p0.x() < 0.0) { + if (p0.x() < 0.0f) { p0.set_x(roundf(p0.x())); } - if (p0.y() < 0.0) { + if (p0.y() < 0.0f) { p0.set_y(roundf(p0.y())); } - if (p1.x() < 0.0) { + if (p1.x() < 0.0f) { p1.set_x(roundf(p1.x())); } - if (p1.y() < 0.0) { + if (p1.y() < 0.0f) { p1.set_y(roundf(p1.y())); } - if (!(p0.x() >= 0.0 && p0.y() >= 0.0 && p0.x() <= m_size.width() && p0.y() <= m_size.height())) { + if (!(p0.x() >= 0.0f && p0.y() >= 0.0f && p0.x() <= m_size.width() && p0.y() <= m_size.height())) { dbgln("!P0({},{})", p0.x(), p0.y()); return; } - if (!(p1.x() >= 0.0 && p1.y() >= 0.0 && p1.x() <= m_size.width() && p1.y() <= m_size.height())) { + if (!(p1.x() >= 0.0f && p1.y() >= 0.0f && p1.x() <= m_size.width() && p1.y() <= m_size.height())) { dbgln("!P1({},{})", p1.x(), p1.y()); return; } - VERIFY(p0.x() >= 0.0 && p0.y() >= 0.0 && p0.x() <= m_size.width() && p0.y() <= m_size.height()); - VERIFY(p1.x() >= 0.0 && p1.y() >= 0.0 && p1.x() <= m_size.width() && p1.y() <= m_size.height()); + VERIFY(p0.x() >= 0.0f && p0.y() >= 0.0f && p0.x() <= m_size.width() && p0.y() <= m_size.height()); + VERIFY(p1.x() >= 0.0f && p1.y() >= 0.0f && p1.x() <= m_size.width() && p1.y() <= m_size.height()); // If we're on the same Y, there's no need to draw if (p0.y() == p1.y()) { @@ -300,8 +300,8 @@ void Rasterizer::draw_line(Gfx::FloatPoint p0, Gfx::FloatPoint p1) float dy = min(y + 1.0f, p1.y()) - max((float)y, p0.y()); float directed_dy = dy * direction; float x_next = x_cur + dy * dxdy; - if (x_next < 0.0) { - x_next = 0.0; + if (x_next < 0.0f) { + x_next = 0.0f; } float x0 = x_cur; float x1 = x_next; @@ -313,19 +313,19 @@ void Rasterizer::draw_line(Gfx::FloatPoint p0, Gfx::FloatPoint p1) float x1_ceil = ceil(x1); u32 x0i = x0_floor; - if (x1_ceil <= x0_floor + 1.0) { + if (x1_ceil <= x0_floor + 1.0f) { // If x0 and x1 are within the same pixel, then area to the right is (1 - (mid(x0, x1) - x0_floor)) * dy - float area = ((x0 + x1) * 0.5) - x0_floor; - m_data[line_offset + x0i] += directed_dy * (1.0 - area); + float area = ((x0 + x1) * 0.5f) - x0_floor; + m_data[line_offset + x0i] += directed_dy * (1.0f - area); m_data[line_offset + x0i + 1] += directed_dy * area; } else { - float dydx = 1.0 / dxdy; + float dydx = 1.0f / dxdy; if (dydx < 0) dydx = -dydx; - float x0_right = 1.0 - (x0 - x0_floor); + float x0_right = 1.0f - (x0 - x0_floor); u32 x1_floor_i = floor(x1); - float area_upto_here = 0.5 * x0_right * x0_right * dydx; + 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++) { m_data[line_offset + x] += direction * dydx; diff --git a/Userland/Libraries/LibWeb/CSS/Length.h b/Userland/Libraries/LibWeb/CSS/Length.h index 322d741227..c7ca87bbf3 100644 --- a/Userland/Libraries/LibWeb/CSS/Length.h +++ b/Userland/Libraries/LibWeb/CSS/Length.h @@ -73,7 +73,7 @@ public: if (is_undefined()) return fallback_for_undefined; if (is_percentage()) - return make_px(raw_value() / 100.0 * reference_for_percent); + return make_px(raw_value() / 100.0f * reference_for_percent); if (is_relative()) return make_px(to_px(layout_node)); return *this; diff --git a/Userland/Libraries/LibWeb/Dump.cpp b/Userland/Libraries/LibWeb/Dump.cpp index a9f721dfef..e0353009bd 100644 --- a/Userland/Libraries/LibWeb/Dump.cpp +++ b/Userland/Libraries/LibWeb/Dump.cpp @@ -189,7 +189,7 @@ void dump_tree(StringBuilder& builder, const Layout::Node& layout_node, bool sho if (show_box_model) { // Dump the horizontal box properties - builder.appendf(" [%g+%g+%g %g %g+%g+%g]", + builder.appendff(" [{}+{}+{} {} {}+{}+{}]", box.box_model().margin.left, box.box_model().border.left, box.box_model().padding.left, @@ -199,7 +199,7 @@ void dump_tree(StringBuilder& builder, const Layout::Node& layout_node, bool sho box.box_model().margin.right); // And the vertical box properties - builder.appendf(" [%g+%g+%g %g %g+%g+%g]", + builder.appendff(" [{}+{}+{} {} {}+{}+{}]", box.box_model().margin.top, box.box_model().border.top, box.box_model().padding.top, diff --git a/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.cpp b/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.cpp index da74eb1f50..db4c3052f8 100644 --- a/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.cpp +++ b/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.cpp @@ -219,13 +219,13 @@ DOM::ExceptionOr<void> CanvasRenderingContext2D::ellipse(float x, float y, float if (radius_y < 0) return DOM::IndexSizeError::create(String::formatted("The minor-axis radius provided ({}) is negative.", radius_y)); - if ((!counter_clockwise && (end_angle - start_angle) >= M_TAU) - || (counter_clockwise && (start_angle - end_angle) >= M_TAU)) { + if (constexpr float tau = M_TAU; (!counter_clockwise && (end_angle - start_angle) >= tau) + || (counter_clockwise && (start_angle - end_angle) >= tau)) { start_angle = 0; - end_angle = M_TAU; + end_angle = tau; } else { - start_angle = fmodf(start_angle, M_TAU); - end_angle = fmodf(end_angle, M_TAU); + start_angle = fmodf(start_angle, tau); + end_angle = fmodf(end_angle, tau); } // Then, figure out where the ends of the arc are. @@ -263,7 +263,7 @@ DOM::ExceptionOr<void> CanvasRenderingContext2D::ellipse(float x, float y, float m_path.move_to(start_point); - auto delta_theta = end_angle - start_angle; + double delta_theta = end_angle - start_angle; // FIXME: This is still goofy for some values. m_path.elliptical_arc_to(end_point, { radius_x, radius_y }, rotation, delta_theta > M_PI, !counter_clockwise); diff --git a/Userland/Libraries/LibWeb/SVG/SVGPathElement.cpp b/Userland/Libraries/LibWeb/SVG/SVGPathElement.cpp index a6a718aa8d..d97bc13852 100644 --- a/Userland/Libraries/LibWeb/SVG/SVGPathElement.cpp +++ b/Userland/Libraries/LibWeb/SVG/SVGPathElement.cpp @@ -516,7 +516,7 @@ Gfx::Path& SVGPathElement::get_path() case PathInstructionType::EllipticalArc: { double rx = data[0]; double ry = data[1]; - double x_axis_rotation = data[2] * M_DEG2RAD; + double x_axis_rotation = double { data[2] } * M_DEG2RAD; double large_arc_flag = data[3]; double sweep_flag = data[4]; auto& last_point = path.segments().last().point(); |