mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 17:47:45 +00:00
Everywhere: Use AK/Math.h if applicable
AK's version should see better inlining behaviors, than the LibM one. We avoid mixed usage for now though. Also clean up some stale math includes and improper floatingpoint usage.
This commit is contained in:
parent
c5f6ba6e71
commit
ed46d52252
40 changed files with 116 additions and 156 deletions
|
@ -9,11 +9,11 @@
|
|||
#include <AK/Debug.h>
|
||||
#include <AK/LexicalPath.h>
|
||||
#include <AK/MappedFile.h>
|
||||
#include <AK/Math.h>
|
||||
#include <AK/Memory.h>
|
||||
#include <AK/MemoryStream.h>
|
||||
#include <AK/NonnullOwnPtrVector.h>
|
||||
#include <LibGfx/GIFLoader.h>
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
|
@ -138,7 +138,7 @@ public:
|
|||
: m_lzw_bytes(lzw_bytes)
|
||||
, m_code_size(min_code_size)
|
||||
, m_original_code_size(min_code_size)
|
||||
, m_table_capacity(pow(2, min_code_size))
|
||||
, m_table_capacity(AK::exp2<u32>(min_code_size))
|
||||
{
|
||||
init_code_table();
|
||||
}
|
||||
|
@ -162,7 +162,7 @@ public:
|
|||
m_code_table.clear();
|
||||
m_code_table.extend(m_original_code_table);
|
||||
m_code_size = m_original_code_size;
|
||||
m_table_capacity = pow(2, m_code_size);
|
||||
m_table_capacity = AK::exp2<u32>(m_code_size);
|
||||
m_output.clear();
|
||||
}
|
||||
|
||||
|
@ -563,7 +563,7 @@ static bool load_gif_frame_descriptors(GIFLoadingContext& context)
|
|||
image.interlaced = (packed_fields & 0x40) != 0;
|
||||
|
||||
if (!image.use_global_color_map) {
|
||||
size_t local_color_table_size = pow(2, (packed_fields & 7) + 1);
|
||||
size_t local_color_table_size = AK::exp2<size_t>((packed_fields & 7) + 1);
|
||||
|
||||
for (size_t i = 0; i < local_color_table_size; ++i) {
|
||||
u8 r = 0;
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "Color.h"
|
||||
#include <math.h>
|
||||
#include <AK/Math.h>
|
||||
#include <xmmintrin.h>
|
||||
|
||||
#include <AK/SIMD.h>
|
||||
|
@ -58,7 +58,7 @@ inline f32x4 linear_to_gamma4(f32x4 x)
|
|||
// Source for approximation: https://mimosa-pudica.net/fast-gamma/
|
||||
constexpr float a = 0.00279491f;
|
||||
constexpr float b = 1.15907984f;
|
||||
float c = (b / sqrtf(1.0f + a)) - 1;
|
||||
float c = (b / AK::sqrt(1.0f + a)) - 1;
|
||||
return ((b * __builtin_ia32_rsqrtps(x + a)) - c) * x;
|
||||
}
|
||||
|
||||
|
@ -85,8 +85,8 @@ 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 / sqrtf(1 + a)) - 1;
|
||||
return ((b / __builtin_sqrtf(x + a)) - c) * x;
|
||||
float c = (b / AK::sqrt(1 + a)) - 1;
|
||||
return ((b / AK::sqrt(x + a)) - c) * x;
|
||||
}
|
||||
|
||||
// Linearize v1 and v2, lerp them by mix factor, then convert back.
|
||||
|
|
|
@ -13,7 +13,6 @@
|
|||
#include <AK/Types.h>
|
||||
#include <LibGfx/ICOLoader.h>
|
||||
#include <LibGfx/PNGLoader.h>
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
|
|
|
@ -10,12 +10,12 @@
|
|||
#include <AK/HashMap.h>
|
||||
#include <AK/LexicalPath.h>
|
||||
#include <AK/MappedFile.h>
|
||||
#include <AK/Math.h>
|
||||
#include <AK/MemoryStream.h>
|
||||
#include <AK/String.h>
|
||||
#include <AK/Vector.h>
|
||||
#include <LibGfx/Bitmap.h>
|
||||
#include <LibGfx/JPGLoader.h>
|
||||
#include <math.h>
|
||||
|
||||
#define JPG_INVALID 0X0000
|
||||
|
||||
|
@ -864,20 +864,20 @@ static void dequantize(JPGLoadingContext& context, Vector<Macroblock>& macrobloc
|
|||
|
||||
static void inverse_dct(const JPGLoadingContext& context, Vector<Macroblock>& macroblocks)
|
||||
{
|
||||
static const float m0 = 2.0 * cos(1.0 / 16.0 * 2.0 * M_PI);
|
||||
static const float m1 = 2.0 * cos(2.0 / 16.0 * 2.0 * M_PI);
|
||||
static const float m3 = 2.0 * cos(2.0 / 16.0 * 2.0 * M_PI);
|
||||
static const float m5 = 2.0 * cos(3.0 / 16.0 * 2.0 * M_PI);
|
||||
static const float m0 = 2.0 * AK::cos(1.0 / 16.0 * 2.0 * AK::Pi<double>);
|
||||
static const float m1 = 2.0 * AK::cos(2.0 / 16.0 * 2.0 * AK::Pi<double>);
|
||||
static const float m3 = 2.0 * AK::cos(2.0 / 16.0 * 2.0 * AK::Pi<double>);
|
||||
static const float m5 = 2.0 * AK::cos(3.0 / 16.0 * 2.0 * AK::Pi<double>);
|
||||
static const float m2 = m0 - m5;
|
||||
static const float m4 = m0 + m5;
|
||||
static const float s0 = cos(0.0 / 16.0 * M_PI) / sqrt(8);
|
||||
static const float s1 = cos(1.0 / 16.0 * M_PI) / 2.0;
|
||||
static const float s2 = cos(2.0 / 16.0 * M_PI) / 2.0;
|
||||
static const float s3 = cos(3.0 / 16.0 * M_PI) / 2.0;
|
||||
static const float s4 = cos(4.0 / 16.0 * M_PI) / 2.0;
|
||||
static const float s5 = cos(5.0 / 16.0 * M_PI) / 2.0;
|
||||
static const float s6 = cos(6.0 / 16.0 * M_PI) / 2.0;
|
||||
static const float s7 = cos(7.0 / 16.0 * M_PI) / 2.0;
|
||||
static const float s0 = AK::cos(0.0 / 16.0 * AK::Pi<double>) / sqrt(8);
|
||||
static const float s1 = AK::cos(1.0 / 16.0 * AK::Pi<double>) / 2.0;
|
||||
static const float s2 = AK::cos(2.0 / 16.0 * AK::Pi<double>) / 2.0;
|
||||
static const float s3 = AK::cos(3.0 / 16.0 * AK::Pi<double>) / 2.0;
|
||||
static const float s4 = AK::cos(4.0 / 16.0 * AK::Pi<double>) / 2.0;
|
||||
static const float s5 = AK::cos(5.0 / 16.0 * AK::Pi<double>) / 2.0;
|
||||
static const float s6 = AK::cos(6.0 / 16.0 * AK::Pi<double>) / 2.0;
|
||||
static const float s7 = AK::cos(7.0 / 16.0 * AK::Pi<double>) / 2.0;
|
||||
|
||||
for (u32 vcursor = 0; vcursor < context.mblock_meta.vcount; vcursor += context.vsample_factor) {
|
||||
for (u32 hcursor = 0; hcursor < context.mblock_meta.hcount; hcursor += context.hsample_factor) {
|
||||
|
|
|
@ -11,7 +11,6 @@
|
|||
#include <LibGfx/Forward.h>
|
||||
#include <LibGfx/Point.h>
|
||||
#include <LibGfx/Rect.h>
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
namespace Gfx {
|
||||
|
|
|
@ -6,10 +6,10 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <AK/Math.h>
|
||||
#include <LibGfx/Matrix.h>
|
||||
#include <LibGfx/Vector3.h>
|
||||
#include <LibGfx/Vector4.h>
|
||||
#include <math.h>
|
||||
|
||||
namespace Gfx {
|
||||
|
||||
|
@ -70,8 +70,8 @@ constexpr static Matrix4x4<T> scale_matrix(const Vector3<T>& s)
|
|||
template<typename T>
|
||||
constexpr static Matrix4x4<T> rotation_matrix(const Vector3<T>& axis, T angle)
|
||||
{
|
||||
T c = cos(angle);
|
||||
T s = sin(angle);
|
||||
T c = AK::cos(angle);
|
||||
T s = AK::sin(angle);
|
||||
T t = 1 - c;
|
||||
T x = axis.x();
|
||||
T y = axis.y();
|
||||
|
|
|
@ -11,7 +11,6 @@
|
|||
#include <LibCompress/Zlib.h>
|
||||
#include <LibGfx/PNGLoader.h>
|
||||
#include <fcntl.h>
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/mman.h>
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include <AK/Assertions.h>
|
||||
#include <AK/Debug.h>
|
||||
#include <AK/Function.h>
|
||||
#include <AK/Math.h>
|
||||
#include <AK/Memory.h>
|
||||
#include <AK/Queue.h>
|
||||
#include <AK/QuickSort.h>
|
||||
|
@ -25,7 +26,6 @@
|
|||
#include <LibGfx/Palette.h>
|
||||
#include <LibGfx/Path.h>
|
||||
#include <LibGfx/TextDirection.h>
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#if defined(__GNUC__) && !defined(__clang__)
|
||||
|
@ -492,11 +492,11 @@ void Painter::draw_ellipse_intersecting(const IntRect& rect, Color color, int th
|
|||
double increment = M_PI / number_samples;
|
||||
|
||||
auto ellipse_x = [&](double theta) -> int {
|
||||
return (cos(theta) * rect.width() / sqrt(2)) + rect.center().x();
|
||||
return (AK::cos(theta) * rect.width() / AK::sqrt(2.)) + rect.center().x();
|
||||
};
|
||||
|
||||
auto ellipse_y = [&](double theta) -> int {
|
||||
return (sin(theta) * rect.height() / sqrt(2)) + rect.center().y();
|
||||
return (AK::sin(theta) * rect.height() / AK::sqrt(2.)) + rect.center().y();
|
||||
};
|
||||
|
||||
for (auto theta = 0.0; theta < 2 * M_PI; theta += increment) {
|
||||
|
@ -1920,8 +1920,8 @@ void Painter::for_each_line_segment_on_elliptical_arc(const FloatPoint& p1, cons
|
|||
FloatPoint current_point = relative_start;
|
||||
FloatPoint next_point = { 0, 0 };
|
||||
|
||||
auto sin_x_axis = sinf(x_axis_rotation);
|
||||
auto cos_x_axis = cosf(x_axis_rotation);
|
||||
auto sin_x_axis = AK::sin(x_axis_rotation);
|
||||
auto cos_x_axis = AK::cos(x_axis_rotation);
|
||||
auto rotate_point = [sin_x_axis, cos_x_axis](FloatPoint& p) {
|
||||
auto original_x = p.x();
|
||||
auto original_y = p.y();
|
||||
|
@ -1931,8 +1931,8 @@ void Painter::for_each_line_segment_on_elliptical_arc(const FloatPoint& p1, cons
|
|||
};
|
||||
|
||||
for (double theta = theta_1; theta <= ((double)theta_1 + (double)theta_delta); theta += theta_step) {
|
||||
next_point.set_x(a * cosf(theta));
|
||||
next_point.set_y(b * sinf(theta));
|
||||
next_point.set_x(a * AK::cos<float>(theta));
|
||||
next_point.set_y(b * AK::sin<float>(theta));
|
||||
rotate_point(next_point);
|
||||
|
||||
callback(current_point + center, next_point + center);
|
||||
|
|
|
@ -6,11 +6,11 @@
|
|||
|
||||
#include <AK/Function.h>
|
||||
#include <AK/HashTable.h>
|
||||
#include <AK/Math.h>
|
||||
#include <AK/QuickSort.h>
|
||||
#include <AK/StringBuilder.h>
|
||||
#include <LibGfx/Painter.h>
|
||||
#include <LibGfx/Path.h>
|
||||
#include <math.h>
|
||||
|
||||
namespace Gfx {
|
||||
|
||||
|
@ -21,8 +21,8 @@ void Path::elliptical_arc_to(const FloatPoint& point, const FloatPoint& radii, d
|
|||
double rx = radii.x();
|
||||
double ry = radii.y();
|
||||
|
||||
double x_axis_rotation_c = cos(x_axis_rotation);
|
||||
double x_axis_rotation_s = sin(x_axis_rotation);
|
||||
double x_axis_rotation_c = AK::cos(x_axis_rotation);
|
||||
double x_axis_rotation_s = AK::sin(x_axis_rotation);
|
||||
|
||||
// Find the last point
|
||||
FloatPoint last_point { 0, 0 };
|
||||
|
@ -61,24 +61,24 @@ void Path::elliptical_arc_to(const FloatPoint& point, const FloatPoint& radii, d
|
|||
auto y1p = -x_axis_rotation_s * x_avg + x_axis_rotation_c * y_avg;
|
||||
|
||||
// Step 2: Compute (cx', cy')
|
||||
double x1p_sq = pow(x1p, 2.0);
|
||||
double y1p_sq = pow(y1p, 2.0);
|
||||
double rx_sq = pow(rx, 2.0);
|
||||
double ry_sq = pow(ry, 2.0);
|
||||
double x1p_sq = x1p * x1p;
|
||||
double y1p_sq = y1p * y1p;
|
||||
double rx_sq = rx * rx;
|
||||
double ry_sq = ry * ry;
|
||||
|
||||
// Step 3 of out-of-range radii correction
|
||||
double lambda = x1p_sq / rx_sq + y1p_sq / ry_sq;
|
||||
double multiplier;
|
||||
|
||||
if (lambda > 1.0) {
|
||||
auto lambda_sqrt = sqrt(lambda);
|
||||
auto lambda_sqrt = AK::sqrt(lambda);
|
||||
rx *= lambda_sqrt;
|
||||
ry *= lambda_sqrt;
|
||||
multiplier = 0.0;
|
||||
} else {
|
||||
double numerator = rx_sq * ry_sq - rx_sq * y1p_sq - ry_sq * x1p_sq;
|
||||
double denominator = rx_sq * y1p_sq + ry_sq * x1p_sq;
|
||||
multiplier = sqrt(numerator / denominator);
|
||||
multiplier = AK::sqrt(numerator / denominator);
|
||||
}
|
||||
|
||||
if (large_arc == sweep)
|
||||
|
@ -93,8 +93,8 @@ void Path::elliptical_arc_to(const FloatPoint& point, const FloatPoint& radii, d
|
|||
double cx = x_axis_rotation_c * cxp - x_axis_rotation_s * cyp + x_avg;
|
||||
double cy = x_axis_rotation_s * cxp + x_axis_rotation_c * cyp + y_avg;
|
||||
|
||||
double theta_1 = atan2((y1p - cyp) / ry, (x1p - cxp) / rx);
|
||||
double theta_2 = atan2((-y1p - cyp) / ry, (-x1p - cxp) / rx);
|
||||
double theta_1 = AK::atan2((y1p - cyp) / ry, (x1p - cxp) / rx);
|
||||
double theta_2 = AK::atan2((-y1p - cyp) / ry, (-x1p - cxp) / rx);
|
||||
|
||||
auto theta_delta = theta_2 - theta_1;
|
||||
|
||||
|
|
|
@ -7,12 +7,12 @@
|
|||
#pragma once
|
||||
|
||||
#include <AK/Format.h>
|
||||
#include <AK/Math.h>
|
||||
#include <AK/StdLibExtras.h>
|
||||
#include <LibGfx/AffineTransform.h>
|
||||
#include <LibGfx/Forward.h>
|
||||
#include <LibGfx/Orientation.h>
|
||||
#include <LibIPC/Forward.h>
|
||||
#include <math.h>
|
||||
|
||||
namespace Gfx {
|
||||
|
||||
|
@ -223,7 +223,7 @@ public:
|
|||
{
|
||||
if (*this == other)
|
||||
return 0;
|
||||
return sqrtf(powf(m_x - other.m_x, 2.0f) + powf(m_y - other.m_y, 2.0f));
|
||||
return AK::hypot<float>(m_x - other.m_x, m_y - other.m_y);
|
||||
}
|
||||
|
||||
[[nodiscard]] Point absolute_relative_distance_to(Point const& other) const
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <AK/Math.h>
|
||||
#include <AK/String.h>
|
||||
#include <math.h>
|
||||
|
||||
namespace Gfx {
|
||||
template<typename T>
|
||||
|
@ -105,7 +105,7 @@ public:
|
|||
|
||||
constexpr T length() const
|
||||
{
|
||||
return sqrt(m_x * m_x + m_y * m_y);
|
||||
return AK::hypot(m_x, m_y);
|
||||
}
|
||||
|
||||
String to_string() const
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <AK/Math.h>
|
||||
#include <AK/String.h>
|
||||
#include <math.h>
|
||||
|
||||
namespace Gfx {
|
||||
template<typename T>
|
||||
|
@ -121,7 +121,7 @@ public:
|
|||
|
||||
constexpr T length() const
|
||||
{
|
||||
return sqrt(m_x * m_x + m_y * m_y + m_z * m_z);
|
||||
return AK::sqrt(m_x * m_x + m_y * m_y + m_z * m_z);
|
||||
}
|
||||
|
||||
String to_string() const
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <AK/Math.h>
|
||||
#include <AK/String.h>
|
||||
#include <math.h>
|
||||
|
||||
namespace Gfx {
|
||||
template<typename T>
|
||||
|
@ -121,7 +121,7 @@ public:
|
|||
|
||||
constexpr T length() const
|
||||
{
|
||||
return sqrt(m_x * m_x + m_y * m_y + m_z * m_z + m_w * m_w);
|
||||
return AK::sqrt(m_x * m_x + m_y * m_y + m_z * m_z + m_w * m_w);
|
||||
}
|
||||
|
||||
String to_string() const
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue