mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 20:17:44 +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
44
AK/Complex.h
44
AK/Complex.h
|
@ -7,10 +7,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <AK/Concepts.h>
|
#include <AK/Concepts.h>
|
||||||
#if __has_include(<math.h>)
|
#include <AK/Math.h>
|
||||||
# define AKCOMPLEX_CAN_USE_MATH_H
|
|
||||||
# include <math.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
# if __cplusplus >= 201103L
|
# if __cplusplus >= 201103L
|
||||||
|
@ -45,18 +42,9 @@ public:
|
||||||
|
|
||||||
constexpr T magnitude_squared() const COMPLEX_NOEXCEPT { return m_real * m_real + m_imag * m_imag; }
|
constexpr T magnitude_squared() const COMPLEX_NOEXCEPT { return m_real * m_real + m_imag * m_imag; }
|
||||||
|
|
||||||
# ifdef AKCOMPLEX_CAN_USE_MATH_H
|
|
||||||
constexpr T magnitude() const COMPLEX_NOEXCEPT
|
constexpr T magnitude() const COMPLEX_NOEXCEPT
|
||||||
{
|
{
|
||||||
// for numbers 32 or under bit long we don't need the extra precision of sqrt
|
return hypot(m_real, m_imag);
|
||||||
// although it may return values with a considerable error if real and imag are too big?
|
|
||||||
if constexpr (sizeof(T) <= sizeof(float)) {
|
|
||||||
return sqrtf(m_real * m_real + m_imag * m_imag);
|
|
||||||
} else if constexpr (sizeof(T) <= sizeof(double)) {
|
|
||||||
return sqrt(m_real * m_real + m_imag * m_imag);
|
|
||||||
} else {
|
|
||||||
return sqrtl(m_real * m_real + m_imag * m_imag);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr T phase() const COMPLEX_NOEXCEPT
|
constexpr T phase() const COMPLEX_NOEXCEPT
|
||||||
|
@ -67,15 +55,8 @@ public:
|
||||||
template<AK::Concepts::Arithmetic U, AK::Concepts::Arithmetic V>
|
template<AK::Concepts::Arithmetic U, AK::Concepts::Arithmetic V>
|
||||||
static constexpr Complex<T> from_polar(U magnitude, V phase)
|
static constexpr Complex<T> from_polar(U magnitude, V phase)
|
||||||
{
|
{
|
||||||
if constexpr (sizeof(T) <= sizeof(float)) {
|
return Complex<T>(magnitude * cos(phase), magnitude * sin(phase));
|
||||||
return Complex<T>(magnitude * cosf(phase), magnitude * sinf(phase));
|
|
||||||
} else if constexpr (sizeof(T) <= sizeof(double)) {
|
|
||||||
return Complex<T>(magnitude * cos(phase), magnitude * sin(phase));
|
|
||||||
} else {
|
|
||||||
return Complex<T>(magnitude * cosl(phase), magnitude * sinl(phase));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
# endif
|
|
||||||
|
|
||||||
template<AK::Concepts::Arithmetic U>
|
template<AK::Concepts::Arithmetic U>
|
||||||
constexpr Complex<T>& operator=(const Complex<U>& other)
|
constexpr Complex<T>& operator=(const Complex<U>& other)
|
||||||
|
@ -288,7 +269,6 @@ static constinit Complex<T> complex_real_unit = Complex<T>((T)1, (T)0);
|
||||||
template<AK::Concepts::Arithmetic T>
|
template<AK::Concepts::Arithmetic T>
|
||||||
static constinit Complex<T> complex_imag_unit = Complex<T>((T)0, (T)1);
|
static constinit Complex<T> complex_imag_unit = Complex<T>((T)0, (T)1);
|
||||||
|
|
||||||
# ifdef AKCOMPLEX_CAN_USE_MATH_H
|
|
||||||
template<AK::Concepts::Arithmetic T, AK::Concepts::Arithmetic U>
|
template<AK::Concepts::Arithmetic T, AK::Concepts::Arithmetic U>
|
||||||
static constexpr bool approx_eq(const Complex<T>& a, const Complex<U>& b, const double margin = 0.000001)
|
static constexpr bool approx_eq(const Complex<T>& a, const Complex<U>& b, const double margin = 0.000001)
|
||||||
{
|
{
|
||||||
|
@ -300,23 +280,15 @@ static constexpr bool approx_eq(const Complex<T>& a, const Complex<U>& b, const
|
||||||
template<AK::Concepts::Arithmetic T>
|
template<AK::Concepts::Arithmetic T>
|
||||||
static constexpr Complex<T> cexp(const Complex<T>& a)
|
static constexpr Complex<T> cexp(const Complex<T>& a)
|
||||||
{
|
{
|
||||||
// FIXME: this can probably be faster and not use so many expensive trigonometric functions
|
// FIXME: this can probably be faster and not use so many "expensive" trigonometric functions
|
||||||
if constexpr (sizeof(T) <= sizeof(float)) {
|
return exp(a.real()) * Complex<T>(cos(a.imag()), sin(a.imag()));
|
||||||
return expf(a.real()) * Complex<T>(cosf(a.imag()), sinf(a.imag()));
|
|
||||||
} else if constexpr (sizeof(T) <= sizeof(double)) {
|
|
||||||
return exp(a.real()) * Complex<T>(cos(a.imag()), sin(a.imag()));
|
|
||||||
} else {
|
|
||||||
return expl(a.real()) * Complex<T>(cosl(a.imag()), sinl(a.imag()));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
# endif
|
|
||||||
|
|
||||||
|
using AK::approx_eq;
|
||||||
|
using AK::cexp;
|
||||||
using AK::Complex;
|
using AK::Complex;
|
||||||
using AK::complex_imag_unit;
|
using AK::complex_imag_unit;
|
||||||
using AK::complex_real_unit;
|
using AK::complex_real_unit;
|
||||||
# ifdef AKCOMPLEX_CAN_USE_MATH_H
|
|
||||||
using AK::approx_eq;
|
|
||||||
using AK::cexp;
|
|
||||||
# endif
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -22,7 +22,6 @@
|
||||||
#include <LibGUI/Window.h>
|
#include <LibGUI/Window.h>
|
||||||
#include <LibProtocol/RequestClient.h>
|
#include <LibProtocol/RequestClient.h>
|
||||||
#include <LibWeb/Loader/ResourceLoader.h>
|
#include <LibWeb/Loader/ResourceLoader.h>
|
||||||
#include <math.h>
|
|
||||||
|
|
||||||
namespace Browser {
|
namespace Browser {
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
#include "Calculator.h"
|
#include "Calculator.h"
|
||||||
#include <AK/Assertions.h>
|
#include <AK/Assertions.h>
|
||||||
#include <math.h>
|
#include <AK/Math.h>
|
||||||
|
|
||||||
Calculator::Calculator()
|
Calculator::Calculator()
|
||||||
{
|
{
|
||||||
|
@ -37,7 +37,7 @@ double Calculator::begin_operation(Operation operation, double argument)
|
||||||
m_has_error = true;
|
m_has_error = true;
|
||||||
return argument;
|
return argument;
|
||||||
}
|
}
|
||||||
res = sqrt(argument);
|
res = AK::sqrt(argument);
|
||||||
clear_operation();
|
clear_operation();
|
||||||
break;
|
break;
|
||||||
case Operation::Inverse:
|
case Operation::Inverse:
|
||||||
|
|
|
@ -8,11 +8,11 @@
|
||||||
|
|
||||||
#include "RollWidget.h"
|
#include "RollWidget.h"
|
||||||
#include "TrackManager.h"
|
#include "TrackManager.h"
|
||||||
|
#include <AK/Math.h>
|
||||||
#include <LibGUI/Painter.h>
|
#include <LibGUI/Painter.h>
|
||||||
#include <LibGUI/Scrollbar.h>
|
#include <LibGUI/Scrollbar.h>
|
||||||
#include <LibGfx/Font.h>
|
#include <LibGfx/Font.h>
|
||||||
#include <LibGfx/FontDatabase.h>
|
#include <LibGfx/FontDatabase.h>
|
||||||
#include <math.h>
|
|
||||||
|
|
||||||
constexpr int note_height = 20;
|
constexpr int note_height = 20;
|
||||||
constexpr int max_note_width = note_height * 2;
|
constexpr int max_note_width = note_height * 2;
|
||||||
|
@ -47,7 +47,7 @@ void RollWidget::paint_event(GUI::PaintEvent& event)
|
||||||
if (m_num_notes < time_signature_notes)
|
if (m_num_notes < time_signature_notes)
|
||||||
m_num_notes = time_signature_notes;
|
m_num_notes = time_signature_notes;
|
||||||
else
|
else
|
||||||
m_num_notes = time_signature_notes * pow(2, static_cast<int>(log2(m_num_notes / time_signature_notes)));
|
m_num_notes = time_signature_notes * AK::exp2(AK::log2(m_num_notes / time_signature_notes));
|
||||||
m_note_width = static_cast<double>(m_roll_width) / m_num_notes;
|
m_note_width = static_cast<double>(m_roll_width) / m_num_notes;
|
||||||
|
|
||||||
// This calculates the minimum number of rows needed. We account for a
|
// This calculates the minimum number of rows needed. We account for a
|
||||||
|
@ -62,9 +62,9 @@ void RollWidget::paint_event(GUI::PaintEvent& event)
|
||||||
int key_pattern_index = (notes_per_octave - 1) - (note_offset % notes_per_octave);
|
int key_pattern_index = (notes_per_octave - 1) - (note_offset % notes_per_octave);
|
||||||
|
|
||||||
int x_offset = horizontal_scrollbar().value();
|
int x_offset = horizontal_scrollbar().value();
|
||||||
int horizontal_note_offset_remainder = fmod(x_offset, m_note_width);
|
int horizontal_note_offset_remainder = static_cast<int>(AK::fmod((double)x_offset, m_note_width));
|
||||||
int horizontal_paint_area = widget_inner_rect().width() + horizontal_note_offset_remainder;
|
int horizontal_paint_area = widget_inner_rect().width() + horizontal_note_offset_remainder;
|
||||||
if (fmod(horizontal_paint_area, m_note_width) != 0)
|
if (AK::fmod((double)horizontal_paint_area, m_note_width) != 0.)
|
||||||
horizontal_paint_area += m_note_width;
|
horizontal_paint_area += m_note_width;
|
||||||
int horizontal_notes_to_paint = horizontal_paint_area / m_note_width;
|
int horizontal_notes_to_paint = horizontal_paint_area / m_note_width;
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "Track.h"
|
#include "Track.h"
|
||||||
|
#include <AK/Math.h>
|
||||||
#include <AK/NumericLimits.h>
|
#include <AK/NumericLimits.h>
|
||||||
#include <LibAudio/Loader.h>
|
#include <LibAudio/Loader.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
@ -176,7 +177,7 @@ Audio::Frame Track::square(size_t note)
|
||||||
{
|
{
|
||||||
double pos = note_frequencies[note] / sample_rate;
|
double pos = note_frequencies[note] / sample_rate;
|
||||||
double square_step = pos * 2 * M_PI;
|
double square_step = pos * 2 * M_PI;
|
||||||
double w = sin(m_pos[note]) >= 0 ? 1 : -1;
|
double w = AK::sin(m_pos[note]) >= 0 ? 1 : -1;
|
||||||
m_pos[note] += square_step;
|
m_pos[note] += square_step;
|
||||||
return w;
|
return w;
|
||||||
}
|
}
|
||||||
|
@ -185,7 +186,7 @@ Audio::Frame Track::triangle(size_t note)
|
||||||
{
|
{
|
||||||
double triangle_step = note_frequencies[note] / sample_rate;
|
double triangle_step = note_frequencies[note] / sample_rate;
|
||||||
double t = m_pos[note];
|
double t = m_pos[note];
|
||||||
double w = fabs(fmod((4 * t) + 1, 4) - 2) - 1;
|
double w = AK::fabs(AK::fmod((4 * t) + 1, 4.) - 2) - 1.;
|
||||||
m_pos[note] += triangle_step;
|
m_pos[note] += triangle_step;
|
||||||
return w;
|
return w;
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,6 @@
|
||||||
#include <LibGUI/Menu.h>
|
#include <LibGUI/Menu.h>
|
||||||
#include <LibGUI/Painter.h>
|
#include <LibGUI/Painter.h>
|
||||||
#include <LibGfx/Rect.h>
|
#include <LibGfx/Rect.h>
|
||||||
#include <math.h>
|
|
||||||
|
|
||||||
namespace PixelPaint {
|
namespace PixelPaint {
|
||||||
|
|
||||||
|
|
|
@ -7,24 +7,24 @@
|
||||||
#include "LineTool.h"
|
#include "LineTool.h"
|
||||||
#include "ImageEditor.h"
|
#include "ImageEditor.h"
|
||||||
#include "Layer.h"
|
#include "Layer.h"
|
||||||
|
#include <AK/Math.h>
|
||||||
#include <LibGUI/Action.h>
|
#include <LibGUI/Action.h>
|
||||||
#include <LibGUI/Menu.h>
|
#include <LibGUI/Menu.h>
|
||||||
#include <LibGUI/Painter.h>
|
#include <LibGUI/Painter.h>
|
||||||
#include <math.h>
|
|
||||||
|
|
||||||
namespace PixelPaint {
|
namespace PixelPaint {
|
||||||
|
|
||||||
static Gfx::IntPoint constrain_line_angle(Gfx::IntPoint const& start_pos, Gfx::IntPoint const& end_pos, float angle_increment)
|
static Gfx::IntPoint constrain_line_angle(Gfx::IntPoint const& start_pos, Gfx::IntPoint const& end_pos, float angle_increment)
|
||||||
{
|
{
|
||||||
float current_angle = atan2f(end_pos.y() - start_pos.y(), end_pos.x() - start_pos.x()) + float { M_PI * 2 };
|
float current_angle = AK::atan2<float>(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;
|
auto diff = end_pos - start_pos;
|
||||||
float line_length = sqrt(diff.x() * diff.x() + diff.y() * diff.y());
|
float line_length = AK::hypot<float>(diff.x(), diff.y());
|
||||||
|
|
||||||
return { start_pos.x() + (int)(cosf(constrained_angle) * line_length),
|
return { start_pos.x() + (int)(AK::cos(constrained_angle) * line_length),
|
||||||
start_pos.y() + (int)(sinf(constrained_angle) * line_length) };
|
start_pos.y() + (int)(AK::sin(constrained_angle) * line_length) };
|
||||||
}
|
}
|
||||||
|
|
||||||
LineTool::LineTool()
|
LineTool::LineTool()
|
||||||
|
|
|
@ -11,7 +11,6 @@
|
||||||
#include <LibGUI/Menu.h>
|
#include <LibGUI/Menu.h>
|
||||||
#include <LibGUI/Painter.h>
|
#include <LibGUI/Painter.h>
|
||||||
#include <LibGfx/Rect.h>
|
#include <LibGfx/Rect.h>
|
||||||
#include <math.h>
|
|
||||||
|
|
||||||
namespace PixelPaint {
|
namespace PixelPaint {
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#include "SprayTool.h"
|
#include "SprayTool.h"
|
||||||
#include "ImageEditor.h"
|
#include "ImageEditor.h"
|
||||||
#include "Layer.h"
|
#include "Layer.h"
|
||||||
|
#include <AK/Math.h>
|
||||||
#include <AK/Queue.h>
|
#include <AK/Queue.h>
|
||||||
#include <LibGUI/Action.h>
|
#include <LibGUI/Action.h>
|
||||||
#include <LibGUI/BoxLayout.h>
|
#include <LibGUI/BoxLayout.h>
|
||||||
|
@ -15,7 +16,6 @@
|
||||||
#include <LibGUI/Painter.h>
|
#include <LibGUI/Painter.h>
|
||||||
#include <LibGUI/Slider.h>
|
#include <LibGUI/Slider.h>
|
||||||
#include <LibGfx/Bitmap.h>
|
#include <LibGfx/Bitmap.h>
|
||||||
#include <math.h>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
namespace PixelPaint {
|
namespace PixelPaint {
|
||||||
|
@ -52,8 +52,8 @@ void SprayTool::paint_it()
|
||||||
for (int i = 0; i < M_PI * base_radius * base_radius * (m_density / 100.0); i++) {
|
for (int i = 0; i < M_PI * base_radius * base_radius * (m_density / 100.0); i++) {
|
||||||
double radius = base_radius * nrand();
|
double radius = base_radius * nrand();
|
||||||
double angle = 2 * M_PI * nrand();
|
double angle = 2 * M_PI * nrand();
|
||||||
const int xpos = m_last_pos.x() + radius * cos(angle);
|
const int xpos = m_last_pos.x() + radius * AK::cos(angle);
|
||||||
const int ypos = m_last_pos.y() - radius * sin(angle);
|
const int ypos = m_last_pos.y() - radius * AK::sin(angle);
|
||||||
if (xpos < 0 || xpos >= bitmap.width())
|
if (xpos < 0 || xpos >= bitmap.width())
|
||||||
continue;
|
continue;
|
||||||
if (ypos < 0 || ypos >= bitmap.height())
|
if (ypos < 0 || ypos >= bitmap.height())
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
#include "AudioAlgorithms.h"
|
#include "AudioAlgorithms.h"
|
||||||
#include <AK/Complex.h>
|
#include <AK/Complex.h>
|
||||||
#include <math.h>
|
#include <AK/Math.h>
|
||||||
|
|
||||||
// This function uses the input vector as output too. therefore, if you wish to
|
// This function uses the input vector as output too. therefore, if you wish to
|
||||||
// leave it intact, pass a copy to this function
|
// leave it intact, pass a copy to this function
|
||||||
|
@ -38,8 +38,8 @@ void fft(Vector<Complex<double>>& sample_data, bool invert)
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int len = 2; len <= n; len <<= 1) {
|
for (int len = 2; len <= n; len <<= 1) {
|
||||||
double ang = 2 * M_PI / len * (invert ? -1 : 1);
|
double ang = 2 * AK::Pi<double> / len * (invert ? -1 : 1);
|
||||||
Complex<double> wlen(cos(ang), sin(ang));
|
Complex<double> wlen(AK::cos(ang), AK::sin(ang));
|
||||||
for (int i = 0; i < n; i += len) {
|
for (int i = 0; i < n; i += len) {
|
||||||
Complex<double> w = { 1., 0. };
|
Complex<double> w = { 1., 0. };
|
||||||
for (int j = 0; j < len / 2; j++) {
|
for (int j = 0; j < len / 2; j++) {
|
||||||
|
|
|
@ -7,11 +7,11 @@
|
||||||
#include "BarsVisualizationWidget.h"
|
#include "BarsVisualizationWidget.h"
|
||||||
#include "AudioAlgorithms.h"
|
#include "AudioAlgorithms.h"
|
||||||
#include <AK/Complex.h>
|
#include <AK/Complex.h>
|
||||||
|
#include <AK/Math.h>
|
||||||
#include <LibGUI/Event.h>
|
#include <LibGUI/Event.h>
|
||||||
#include <LibGUI/Menu.h>
|
#include <LibGUI/Menu.h>
|
||||||
#include <LibGUI/Painter.h>
|
#include <LibGUI/Painter.h>
|
||||||
#include <LibGUI/Window.h>
|
#include <LibGUI/Window.h>
|
||||||
#include <math.h>
|
|
||||||
|
|
||||||
u32 round_previous_power_of_2(u32 x);
|
u32 round_previous_power_of_2(u32 x);
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ void BarsVisualizationWidget::paint_event(GUI::PaintEvent& event)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
fft(m_sample_buffer, false);
|
fft(m_sample_buffer, false);
|
||||||
double max = sqrt(m_sample_count * 2);
|
double max = AK::sqrt(m_sample_count * 2.);
|
||||||
|
|
||||||
double freq_bin = m_samplerate / m_sample_count;
|
double freq_bin = m_samplerate / m_sample_count;
|
||||||
|
|
||||||
|
@ -45,10 +45,10 @@ void BarsVisualizationWidget::paint_event(GUI::PaintEvent& event)
|
||||||
int bins_per_group = ceil_div((m_sample_count - 1) / 2, group_count) * freq_bin;
|
int bins_per_group = ceil_div((m_sample_count - 1) / 2, group_count) * freq_bin;
|
||||||
|
|
||||||
for (int i = 1; i < m_sample_count / 2; i++) {
|
for (int i = 1; i < m_sample_count / 2; i++) {
|
||||||
groups[(i * freq_bin) / bins_per_group] += fabs(m_sample_buffer.data()[i].real());
|
groups[(i * freq_bin) / bins_per_group] += AK::fabs(m_sample_buffer.data()[i].real());
|
||||||
}
|
}
|
||||||
for (int i = 0; i < group_count; i++)
|
for (int i = 0; i < group_count; i++)
|
||||||
groups[i] /= max * freq_bin / (m_adjust_frequencies ? (clamp(pow(M_E, (double)i / group_count * 3.) - 1.75, 1., 15.)) : 1.);
|
groups[i] /= max * freq_bin / (m_adjust_frequencies ? (clamp(AK::pow(AK::E<double>, (double)i / group_count * 3.) - 1.75, 1., 15.)) : 1.);
|
||||||
|
|
||||||
const int horizontal_margin = 30;
|
const int horizontal_margin = 30;
|
||||||
const int top_vertical_margin = 15;
|
const int top_vertical_margin = 15;
|
||||||
|
@ -102,7 +102,7 @@ void BarsVisualizationWidget::set_buffer(RefPtr<Audio::Buffer> buffer, int sampl
|
||||||
m_sample_count = round_previous_power_of_2(samples_to_use);
|
m_sample_count = round_previous_power_of_2(samples_to_use);
|
||||||
m_sample_buffer.resize(m_sample_count);
|
m_sample_buffer.resize(m_sample_count);
|
||||||
for (int i = 0; i < m_sample_count; i++) {
|
for (int i = 0; i < m_sample_count; i++) {
|
||||||
m_sample_buffer.data()[i] = (fabs(buffer->samples()[i].left) + fabs(buffer->samples()[i].right)) / 2.;
|
m_sample_buffer.data()[i] = (AK::fabs(buffer->samples()[i].left) + AK::fabs(buffer->samples()[i].right)) / 2.;
|
||||||
}
|
}
|
||||||
|
|
||||||
update();
|
update();
|
||||||
|
|
|
@ -5,9 +5,9 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "SampleWidget.h"
|
#include "SampleWidget.h"
|
||||||
|
#include <AK/Math.h>
|
||||||
#include <LibAudio/Buffer.h>
|
#include <LibAudio/Buffer.h>
|
||||||
#include <LibGUI/Painter.h>
|
#include <LibGUI/Painter.h>
|
||||||
#include <math.h>
|
|
||||||
|
|
||||||
SampleWidget::SampleWidget()
|
SampleWidget::SampleWidget()
|
||||||
{
|
{
|
||||||
|
@ -34,7 +34,7 @@ void SampleWidget::paint_event(GUI::PaintEvent& event)
|
||||||
if (m_buffer) {
|
if (m_buffer) {
|
||||||
int samples_per_pixel = m_buffer->sample_count() / frame_inner_rect().width();
|
int samples_per_pixel = m_buffer->sample_count() / frame_inner_rect().width();
|
||||||
for (int sample_index = 0; sample_index < m_buffer->sample_count() && (x - x_offset) < frame_inner_rect().width(); ++sample_index) {
|
for (int sample_index = 0; sample_index < m_buffer->sample_count() && (x - x_offset) < frame_inner_rect().width(); ++sample_index) {
|
||||||
float sample = fabsf((float)m_buffer->samples()[sample_index].left);
|
float sample = AK::fabs((float)m_buffer->samples()[sample_index].left);
|
||||||
|
|
||||||
sample_max = max(sample, sample_max);
|
sample_max = max(sample, sample_max);
|
||||||
++count;
|
++count;
|
||||||
|
|
|
@ -7,7 +7,6 @@
|
||||||
#include <LibCore/ElapsedTimer.h>
|
#include <LibCore/ElapsedTimer.h>
|
||||||
#include <LibGUI/Menu.h>
|
#include <LibGUI/Menu.h>
|
||||||
#include <LibGUI/Widget.h>
|
#include <LibGUI/Widget.h>
|
||||||
#include <math.h>
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
|
@ -5,12 +5,12 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "EyesWidget.h"
|
#include "EyesWidget.h"
|
||||||
|
#include <AK/Math.h>
|
||||||
#include <AK/StdLibExtraDetails.h>
|
#include <AK/StdLibExtraDetails.h>
|
||||||
#include <LibGUI/Painter.h>
|
#include <LibGUI/Painter.h>
|
||||||
#include <LibGUI/Window.h>
|
#include <LibGUI/Window.h>
|
||||||
#include <LibGUI/WindowServerConnection.h>
|
#include <LibGUI/WindowServerConnection.h>
|
||||||
#include <LibGfx/Palette.h>
|
#include <LibGfx/Palette.h>
|
||||||
#include <math.h>
|
|
||||||
|
|
||||||
EyesWidget::~EyesWidget()
|
EyesWidget::~EyesWidget()
|
||||||
{
|
{
|
||||||
|
@ -79,7 +79,7 @@ Gfx::IntPoint EyesWidget::pupil_center(Gfx::IntRect& eyeball_bounds) const
|
||||||
auto mouse_vector = m_mouse_position - eyeball_bounds.center();
|
auto mouse_vector = m_mouse_position - eyeball_bounds.center();
|
||||||
double dx = mouse_vector.x();
|
double dx = mouse_vector.x();
|
||||||
double dy = mouse_vector.y();
|
double dy = mouse_vector.y();
|
||||||
double mouse_distance = sqrt(dx * dx + dy * dy);
|
double mouse_distance = AK::hypot(dx, dy);
|
||||||
|
|
||||||
if (mouse_distance == 0.0)
|
if (mouse_distance == 0.0)
|
||||||
return eyeball_bounds.center();
|
return eyeball_bounds.center();
|
||||||
|
@ -93,14 +93,14 @@ Gfx::IntPoint EyesWidget::pupil_center(Gfx::IntRect& eyeball_bounds) const
|
||||||
if (dx != 0 && AK::abs(dx) >= AK::abs(dy)) {
|
if (dx != 0 && AK::abs(dx) >= AK::abs(dy)) {
|
||||||
double slope = dy / dx;
|
double slope = dy / dx;
|
||||||
double slope_squared = slope * slope;
|
double slope_squared = slope * slope;
|
||||||
max_distance_along_this_direction = 0.25 * sqrt(
|
max_distance_along_this_direction = 0.25 * AK::sqrt(
|
||||||
(slope_squared + 1) /
|
(slope_squared + 1) /
|
||||||
(1 / width_squared + slope_squared / height_squared)
|
(1 / width_squared + slope_squared / height_squared)
|
||||||
);
|
);
|
||||||
} else if (dy != 0 && AK::abs(dy) >= AK::abs(dx)) {
|
} else if (dy != 0 && AK::abs(dy) >= AK::abs(dx)) {
|
||||||
double slope = dx / dy;
|
double slope = dx / dy;
|
||||||
double slope_squared = slope * slope;
|
double slope_squared = slope * slope;
|
||||||
max_distance_along_this_direction = 0.25 * sqrt(
|
max_distance_along_this_direction = 0.25 * AK::sqrt(
|
||||||
(slope_squared + 1) /
|
(slope_squared + 1) /
|
||||||
(slope_squared / width_squared + 1 / height_squared)
|
(slope_squared / width_squared + 1 / height_squared)
|
||||||
);
|
);
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <AK/Math.h>
|
||||||
#include <LibGUI/Action.h>
|
#include <LibGUI/Action.h>
|
||||||
#include <LibGUI/Application.h>
|
#include <LibGUI/Application.h>
|
||||||
#include <LibGUI/BoxLayout.h>
|
#include <LibGUI/BoxLayout.h>
|
||||||
|
@ -18,8 +19,6 @@
|
||||||
#include <LibGfx/Path.h>
|
#include <LibGfx/Path.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include <math.h>
|
|
||||||
|
|
||||||
class MainFrame final : public GUI::Frame {
|
class MainFrame final : public GUI::Frame {
|
||||||
C_OBJECT(MainFrame);
|
C_OBJECT(MainFrame);
|
||||||
|
|
||||||
|
@ -100,17 +99,17 @@ public:
|
||||||
Gfx::IntPoint p3;
|
Gfx::IntPoint p3;
|
||||||
Gfx::IntPoint p4;
|
Gfx::IntPoint p4;
|
||||||
|
|
||||||
p1.set_x(radius * cos(M_PI * m_wheel_delta_acc / 18) + off_x);
|
p1.set_x(radius * AK::cos(AK::Pi<double> * m_wheel_delta_acc / 18.) + off_x);
|
||||||
p1.set_y(radius * sin(M_PI * m_wheel_delta_acc / 18) + off_y);
|
p1.set_y(radius * AK::sin(AK::Pi<double> * m_wheel_delta_acc / 18.) + off_y);
|
||||||
|
|
||||||
p2.set_x(radius * cos(M_PI * (m_wheel_delta_acc + 18) / 18) + off_x);
|
p2.set_x(radius * AK::cos(AK::Pi<double> * (m_wheel_delta_acc + 18) / 18.) + off_x);
|
||||||
p2.set_y(radius * sin(M_PI * (m_wheel_delta_acc + 18) / 18) + off_y);
|
p2.set_y(radius * AK::sin(AK::Pi<double> * (m_wheel_delta_acc + 18) / 18.) + off_y);
|
||||||
|
|
||||||
p3.set_x(radius * cos(M_PI * (m_wheel_delta_acc + 9) / 18) + off_x);
|
p3.set_x(radius * AK::cos(AK::Pi<double> * (m_wheel_delta_acc + 9) / 18.) + off_x);
|
||||||
p3.set_y(radius * sin(M_PI * (m_wheel_delta_acc + 9) / 18) + off_y);
|
p3.set_y(radius * AK::sin(AK::Pi<double> * (m_wheel_delta_acc + 9) / 18.) + off_y);
|
||||||
|
|
||||||
p4.set_x(radius * cos(M_PI * (m_wheel_delta_acc + 27) / 18) + off_x);
|
p4.set_x(radius * AK::cos(AK::Pi<double> * (m_wheel_delta_acc + 27) / 18.) + off_x);
|
||||||
p4.set_y(radius * sin(M_PI * (m_wheel_delta_acc + 27) / 18) + off_y);
|
p4.set_y(radius * AK::sin(AK::Pi<double> * (m_wheel_delta_acc + 27) / 18.) + off_y);
|
||||||
|
|
||||||
painter.draw_line(p1, p2, Color::Red, 2);
|
painter.draw_line(p1, p2, Color::Red, 2);
|
||||||
painter.draw_line(p3, p4, Color::Red, 2);
|
painter.draw_line(p3, p4, Color::Red, 2);
|
||||||
|
|
|
@ -6,17 +6,17 @@
|
||||||
|
|
||||||
#include "GameSizeDialog.h"
|
#include "GameSizeDialog.h"
|
||||||
#include "Game.h"
|
#include "Game.h"
|
||||||
|
#include <AK/Math.h>
|
||||||
#include <LibGUI/BoxLayout.h>
|
#include <LibGUI/BoxLayout.h>
|
||||||
#include <LibGUI/Button.h>
|
#include <LibGUI/Button.h>
|
||||||
#include <LibGUI/CheckBox.h>
|
#include <LibGUI/CheckBox.h>
|
||||||
#include <LibGUI/Label.h>
|
#include <LibGUI/Label.h>
|
||||||
#include <LibGUI/SpinBox.h>
|
#include <LibGUI/SpinBox.h>
|
||||||
#include <math.h>
|
|
||||||
|
|
||||||
GameSizeDialog::GameSizeDialog(GUI::Window* parent, size_t board_size, size_t target, bool evil_ai)
|
GameSizeDialog::GameSizeDialog(GUI::Window* parent, size_t board_size, size_t target, bool evil_ai)
|
||||||
: GUI::Dialog(parent)
|
: GUI::Dialog(parent)
|
||||||
, m_board_size(board_size)
|
, m_board_size(board_size)
|
||||||
, m_target_tile_power(log2(target))
|
, m_target_tile_power(AK::log2(target))
|
||||||
, m_evil_ai(evil_ai)
|
, m_evil_ai(evil_ai)
|
||||||
{
|
{
|
||||||
set_rect({ 0, 0, 250, 150 });
|
set_rect({ 0, 0, 250, 150 });
|
||||||
|
|
|
@ -10,12 +10,12 @@
|
||||||
#include <AK/Debug.h>
|
#include <AK/Debug.h>
|
||||||
#include <AK/FlyString.h>
|
#include <AK/FlyString.h>
|
||||||
#include <AK/Format.h>
|
#include <AK/Format.h>
|
||||||
|
#include <AK/Math.h>
|
||||||
#include <AK/Stream.h>
|
#include <AK/Stream.h>
|
||||||
#include <AK/String.h>
|
#include <AK/String.h>
|
||||||
#include <AK/StringBuilder.h>
|
#include <AK/StringBuilder.h>
|
||||||
#include <LibCore/File.h>
|
#include <LibCore/File.h>
|
||||||
#include <LibCore/FileStream.h>
|
#include <LibCore/FileStream.h>
|
||||||
#include <math.h>
|
|
||||||
|
|
||||||
namespace Audio {
|
namespace Audio {
|
||||||
|
|
||||||
|
@ -417,9 +417,9 @@ u32 FlacLoaderPlugin::convert_sample_count_code(u8 sample_count_code)
|
||||||
return FLAC_BLOCKSIZE_AT_END_OF_HEADER_16;
|
return FLAC_BLOCKSIZE_AT_END_OF_HEADER_16;
|
||||||
}
|
}
|
||||||
if (sample_count_code >= 2 && sample_count_code <= 5) {
|
if (sample_count_code >= 2 && sample_count_code <= 5) {
|
||||||
return 576 * pow(2, (sample_count_code - 2));
|
return 576 * AK::exp2(sample_count_code - 2);
|
||||||
}
|
}
|
||||||
return 256 * pow(2, (sample_count_code - 8));
|
return 256 * AK::exp2(sample_count_code - 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 FlacLoaderPlugin::convert_sample_rate_code(u8 sample_rate_code)
|
u32 FlacLoaderPlugin::convert_sample_rate_code(u8 sample_rate_code)
|
||||||
|
@ -797,7 +797,7 @@ u64 read_utf8_char(InputStream& input)
|
||||||
while (((start_byte << length) & 0b10000000) == 0b10000000)
|
while (((start_byte << length) & 0b10000000) == 0b10000000)
|
||||||
++length;
|
++length;
|
||||||
u8 bits_from_start_byte = 8 - (length + 1);
|
u8 bits_from_start_byte = 8 - (length + 1);
|
||||||
u8 start_byte_bitmask = pow(2, bits_from_start_byte) - 1;
|
u8 start_byte_bitmask = AK::exp2(bits_from_start_byte) - 1;
|
||||||
character = start_byte_bitmask & start_byte;
|
character = start_byte_bitmask & start_byte;
|
||||||
for (u8 i = length; i > 0; --i) {
|
for (u8 i = length; i > 0; --i) {
|
||||||
input.read(single_byte_buffer);
|
input.read(single_byte_buffer);
|
||||||
|
|
|
@ -18,7 +18,6 @@
|
||||||
#include <LibGfx/Bitmap.h>
|
#include <LibGfx/Bitmap.h>
|
||||||
#include <LibGfx/Painter.h>
|
#include <LibGfx/Painter.h>
|
||||||
#include <LibGfx/Vector4.h>
|
#include <LibGfx/Vector4.h>
|
||||||
#include <math.h>
|
|
||||||
|
|
||||||
using AK::dbgln;
|
using AK::dbgln;
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,6 @@
|
||||||
#include <LibGfx/Palette.h>
|
#include <LibGfx/Palette.h>
|
||||||
#include <LibSyntax/Highlighter.h>
|
#include <LibSyntax/Highlighter.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <math.h>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
|
|
@ -9,11 +9,11 @@
|
||||||
#include <AK/Debug.h>
|
#include <AK/Debug.h>
|
||||||
#include <AK/LexicalPath.h>
|
#include <AK/LexicalPath.h>
|
||||||
#include <AK/MappedFile.h>
|
#include <AK/MappedFile.h>
|
||||||
|
#include <AK/Math.h>
|
||||||
#include <AK/Memory.h>
|
#include <AK/Memory.h>
|
||||||
#include <AK/MemoryStream.h>
|
#include <AK/MemoryStream.h>
|
||||||
#include <AK/NonnullOwnPtrVector.h>
|
#include <AK/NonnullOwnPtrVector.h>
|
||||||
#include <LibGfx/GIFLoader.h>
|
#include <LibGfx/GIFLoader.h>
|
||||||
#include <math.h>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
@ -138,7 +138,7 @@ public:
|
||||||
: m_lzw_bytes(lzw_bytes)
|
: m_lzw_bytes(lzw_bytes)
|
||||||
, m_code_size(min_code_size)
|
, m_code_size(min_code_size)
|
||||||
, m_original_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();
|
init_code_table();
|
||||||
}
|
}
|
||||||
|
@ -162,7 +162,7 @@ public:
|
||||||
m_code_table.clear();
|
m_code_table.clear();
|
||||||
m_code_table.extend(m_original_code_table);
|
m_code_table.extend(m_original_code_table);
|
||||||
m_code_size = m_original_code_size;
|
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();
|
m_output.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -563,7 +563,7 @@ static bool load_gif_frame_descriptors(GIFLoadingContext& context)
|
||||||
image.interlaced = (packed_fields & 0x40) != 0;
|
image.interlaced = (packed_fields & 0x40) != 0;
|
||||||
|
|
||||||
if (!image.use_global_color_map) {
|
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) {
|
for (size_t i = 0; i < local_color_table_size; ++i) {
|
||||||
u8 r = 0;
|
u8 r = 0;
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "Color.h"
|
#include "Color.h"
|
||||||
#include <math.h>
|
#include <AK/Math.h>
|
||||||
#include <xmmintrin.h>
|
#include <xmmintrin.h>
|
||||||
|
|
||||||
#include <AK/SIMD.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/
|
// Source for approximation: https://mimosa-pudica.net/fast-gamma/
|
||||||
constexpr float a = 0.00279491f;
|
constexpr float a = 0.00279491f;
|
||||||
constexpr float b = 1.15907984f;
|
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;
|
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/
|
// Source for approximation: https://mimosa-pudica.net/fast-gamma/
|
||||||
constexpr float a = 0.00279491;
|
constexpr float a = 0.00279491;
|
||||||
constexpr float b = 1.15907984;
|
constexpr float b = 1.15907984;
|
||||||
float c = (b / sqrtf(1 + a)) - 1;
|
float c = (b / AK::sqrt(1 + a)) - 1;
|
||||||
return ((b / __builtin_sqrtf(x + a)) - c) * x;
|
return ((b / AK::sqrt(x + a)) - c) * x;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Linearize v1 and v2, lerp them by mix factor, then convert back.
|
// Linearize v1 and v2, lerp them by mix factor, then convert back.
|
||||||
|
|
|
@ -13,7 +13,6 @@
|
||||||
#include <AK/Types.h>
|
#include <AK/Types.h>
|
||||||
#include <LibGfx/ICOLoader.h>
|
#include <LibGfx/ICOLoader.h>
|
||||||
#include <LibGfx/PNGLoader.h>
|
#include <LibGfx/PNGLoader.h>
|
||||||
#include <math.h>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
|
|
@ -10,12 +10,12 @@
|
||||||
#include <AK/HashMap.h>
|
#include <AK/HashMap.h>
|
||||||
#include <AK/LexicalPath.h>
|
#include <AK/LexicalPath.h>
|
||||||
#include <AK/MappedFile.h>
|
#include <AK/MappedFile.h>
|
||||||
|
#include <AK/Math.h>
|
||||||
#include <AK/MemoryStream.h>
|
#include <AK/MemoryStream.h>
|
||||||
#include <AK/String.h>
|
#include <AK/String.h>
|
||||||
#include <AK/Vector.h>
|
#include <AK/Vector.h>
|
||||||
#include <LibGfx/Bitmap.h>
|
#include <LibGfx/Bitmap.h>
|
||||||
#include <LibGfx/JPGLoader.h>
|
#include <LibGfx/JPGLoader.h>
|
||||||
#include <math.h>
|
|
||||||
|
|
||||||
#define JPG_INVALID 0X0000
|
#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 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 m0 = 2.0 * AK::cos(1.0 / 16.0 * 2.0 * AK::Pi<double>);
|
||||||
static const float m1 = 2.0 * cos(2.0 / 16.0 * 2.0 * M_PI);
|
static const float m1 = 2.0 * AK::cos(2.0 / 16.0 * 2.0 * AK::Pi<double>);
|
||||||
static const float m3 = 2.0 * cos(2.0 / 16.0 * 2.0 * M_PI);
|
static const float m3 = 2.0 * AK::cos(2.0 / 16.0 * 2.0 * AK::Pi<double>);
|
||||||
static const float m5 = 2.0 * cos(3.0 / 16.0 * 2.0 * M_PI);
|
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 m2 = m0 - m5;
|
||||||
static const float m4 = m0 + m5;
|
static const float m4 = m0 + m5;
|
||||||
static const float s0 = cos(0.0 / 16.0 * M_PI) / sqrt(8);
|
static const float s0 = AK::cos(0.0 / 16.0 * AK::Pi<double>) / sqrt(8);
|
||||||
static const float s1 = cos(1.0 / 16.0 * M_PI) / 2.0;
|
static const float s1 = AK::cos(1.0 / 16.0 * AK::Pi<double>) / 2.0;
|
||||||
static const float s2 = cos(2.0 / 16.0 * M_PI) / 2.0;
|
static const float s2 = AK::cos(2.0 / 16.0 * AK::Pi<double>) / 2.0;
|
||||||
static const float s3 = cos(3.0 / 16.0 * M_PI) / 2.0;
|
static const float s3 = AK::cos(3.0 / 16.0 * AK::Pi<double>) / 2.0;
|
||||||
static const float s4 = cos(4.0 / 16.0 * M_PI) / 2.0;
|
static const float s4 = AK::cos(4.0 / 16.0 * AK::Pi<double>) / 2.0;
|
||||||
static const float s5 = cos(5.0 / 16.0 * M_PI) / 2.0;
|
static const float s5 = AK::cos(5.0 / 16.0 * AK::Pi<double>) / 2.0;
|
||||||
static const float s6 = cos(6.0 / 16.0 * M_PI) / 2.0;
|
static const float s6 = AK::cos(6.0 / 16.0 * AK::Pi<double>) / 2.0;
|
||||||
static const float s7 = cos(7.0 / 16.0 * M_PI) / 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 vcursor = 0; vcursor < context.mblock_meta.vcount; vcursor += context.vsample_factor) {
|
||||||
for (u32 hcursor = 0; hcursor < context.mblock_meta.hcount; hcursor += context.hsample_factor) {
|
for (u32 hcursor = 0; hcursor < context.mblock_meta.hcount; hcursor += context.hsample_factor) {
|
||||||
|
|
|
@ -11,7 +11,6 @@
|
||||||
#include <LibGfx/Forward.h>
|
#include <LibGfx/Forward.h>
|
||||||
#include <LibGfx/Point.h>
|
#include <LibGfx/Point.h>
|
||||||
#include <LibGfx/Rect.h>
|
#include <LibGfx/Rect.h>
|
||||||
#include <math.h>
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
namespace Gfx {
|
namespace Gfx {
|
||||||
|
|
|
@ -6,10 +6,10 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <AK/Math.h>
|
||||||
#include <LibGfx/Matrix.h>
|
#include <LibGfx/Matrix.h>
|
||||||
#include <LibGfx/Vector3.h>
|
#include <LibGfx/Vector3.h>
|
||||||
#include <LibGfx/Vector4.h>
|
#include <LibGfx/Vector4.h>
|
||||||
#include <math.h>
|
|
||||||
|
|
||||||
namespace Gfx {
|
namespace Gfx {
|
||||||
|
|
||||||
|
@ -70,8 +70,8 @@ constexpr static Matrix4x4<T> scale_matrix(const Vector3<T>& s)
|
||||||
template<typename T>
|
template<typename T>
|
||||||
constexpr static Matrix4x4<T> rotation_matrix(const Vector3<T>& axis, T angle)
|
constexpr static Matrix4x4<T> rotation_matrix(const Vector3<T>& axis, T angle)
|
||||||
{
|
{
|
||||||
T c = cos(angle);
|
T c = AK::cos(angle);
|
||||||
T s = sin(angle);
|
T s = AK::sin(angle);
|
||||||
T t = 1 - c;
|
T t = 1 - c;
|
||||||
T x = axis.x();
|
T x = axis.x();
|
||||||
T y = axis.y();
|
T y = axis.y();
|
||||||
|
|
|
@ -11,7 +11,6 @@
|
||||||
#include <LibCompress/Zlib.h>
|
#include <LibCompress/Zlib.h>
|
||||||
#include <LibGfx/PNGLoader.h>
|
#include <LibGfx/PNGLoader.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <math.h>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
#include <AK/Assertions.h>
|
#include <AK/Assertions.h>
|
||||||
#include <AK/Debug.h>
|
#include <AK/Debug.h>
|
||||||
#include <AK/Function.h>
|
#include <AK/Function.h>
|
||||||
|
#include <AK/Math.h>
|
||||||
#include <AK/Memory.h>
|
#include <AK/Memory.h>
|
||||||
#include <AK/Queue.h>
|
#include <AK/Queue.h>
|
||||||
#include <AK/QuickSort.h>
|
#include <AK/QuickSort.h>
|
||||||
|
@ -25,7 +26,6 @@
|
||||||
#include <LibGfx/Palette.h>
|
#include <LibGfx/Palette.h>
|
||||||
#include <LibGfx/Path.h>
|
#include <LibGfx/Path.h>
|
||||||
#include <LibGfx/TextDirection.h>
|
#include <LibGfx/TextDirection.h>
|
||||||
#include <math.h>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#if defined(__GNUC__) && !defined(__clang__)
|
#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;
|
double increment = M_PI / number_samples;
|
||||||
|
|
||||||
auto ellipse_x = [&](double theta) -> int {
|
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 {
|
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) {
|
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 current_point = relative_start;
|
||||||
FloatPoint next_point = { 0, 0 };
|
FloatPoint next_point = { 0, 0 };
|
||||||
|
|
||||||
auto sin_x_axis = sinf(x_axis_rotation);
|
auto sin_x_axis = AK::sin(x_axis_rotation);
|
||||||
auto cos_x_axis = cosf(x_axis_rotation);
|
auto cos_x_axis = AK::cos(x_axis_rotation);
|
||||||
auto rotate_point = [sin_x_axis, cos_x_axis](FloatPoint& p) {
|
auto rotate_point = [sin_x_axis, cos_x_axis](FloatPoint& p) {
|
||||||
auto original_x = p.x();
|
auto original_x = p.x();
|
||||||
auto original_y = p.y();
|
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) {
|
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_x(a * AK::cos<float>(theta));
|
||||||
next_point.set_y(b * sinf(theta));
|
next_point.set_y(b * AK::sin<float>(theta));
|
||||||
rotate_point(next_point);
|
rotate_point(next_point);
|
||||||
|
|
||||||
callback(current_point + center, next_point + center);
|
callback(current_point + center, next_point + center);
|
||||||
|
|
|
@ -6,11 +6,11 @@
|
||||||
|
|
||||||
#include <AK/Function.h>
|
#include <AK/Function.h>
|
||||||
#include <AK/HashTable.h>
|
#include <AK/HashTable.h>
|
||||||
|
#include <AK/Math.h>
|
||||||
#include <AK/QuickSort.h>
|
#include <AK/QuickSort.h>
|
||||||
#include <AK/StringBuilder.h>
|
#include <AK/StringBuilder.h>
|
||||||
#include <LibGfx/Painter.h>
|
#include <LibGfx/Painter.h>
|
||||||
#include <LibGfx/Path.h>
|
#include <LibGfx/Path.h>
|
||||||
#include <math.h>
|
|
||||||
|
|
||||||
namespace Gfx {
|
namespace Gfx {
|
||||||
|
|
||||||
|
@ -21,8 +21,8 @@ void Path::elliptical_arc_to(const FloatPoint& point, const FloatPoint& radii, d
|
||||||
double rx = radii.x();
|
double rx = radii.x();
|
||||||
double ry = radii.y();
|
double ry = radii.y();
|
||||||
|
|
||||||
double x_axis_rotation_c = cos(x_axis_rotation);
|
double x_axis_rotation_c = AK::cos(x_axis_rotation);
|
||||||
double x_axis_rotation_s = sin(x_axis_rotation);
|
double x_axis_rotation_s = AK::sin(x_axis_rotation);
|
||||||
|
|
||||||
// Find the last point
|
// Find the last point
|
||||||
FloatPoint last_point { 0, 0 };
|
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;
|
auto y1p = -x_axis_rotation_s * x_avg + x_axis_rotation_c * y_avg;
|
||||||
|
|
||||||
// Step 2: Compute (cx', cy')
|
// Step 2: Compute (cx', cy')
|
||||||
double x1p_sq = pow(x1p, 2.0);
|
double x1p_sq = x1p * x1p;
|
||||||
double y1p_sq = pow(y1p, 2.0);
|
double y1p_sq = y1p * y1p;
|
||||||
double rx_sq = pow(rx, 2.0);
|
double rx_sq = rx * rx;
|
||||||
double ry_sq = pow(ry, 2.0);
|
double ry_sq = ry * ry;
|
||||||
|
|
||||||
// Step 3 of out-of-range radii correction
|
// Step 3 of out-of-range radii correction
|
||||||
double lambda = x1p_sq / rx_sq + y1p_sq / ry_sq;
|
double lambda = x1p_sq / rx_sq + y1p_sq / ry_sq;
|
||||||
double multiplier;
|
double multiplier;
|
||||||
|
|
||||||
if (lambda > 1.0) {
|
if (lambda > 1.0) {
|
||||||
auto lambda_sqrt = sqrt(lambda);
|
auto lambda_sqrt = AK::sqrt(lambda);
|
||||||
rx *= lambda_sqrt;
|
rx *= lambda_sqrt;
|
||||||
ry *= lambda_sqrt;
|
ry *= lambda_sqrt;
|
||||||
multiplier = 0.0;
|
multiplier = 0.0;
|
||||||
} else {
|
} else {
|
||||||
double numerator = rx_sq * ry_sq - rx_sq * y1p_sq - ry_sq * x1p_sq;
|
double numerator = rx_sq * ry_sq - rx_sq * y1p_sq - ry_sq * x1p_sq;
|
||||||
double denominator = 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)
|
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 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 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_1 = AK::atan2((y1p - cyp) / ry, (x1p - cxp) / rx);
|
||||||
double theta_2 = 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;
|
auto theta_delta = theta_2 - theta_1;
|
||||||
|
|
||||||
|
|
|
@ -7,12 +7,12 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <AK/Format.h>
|
#include <AK/Format.h>
|
||||||
|
#include <AK/Math.h>
|
||||||
#include <AK/StdLibExtras.h>
|
#include <AK/StdLibExtras.h>
|
||||||
#include <LibGfx/AffineTransform.h>
|
#include <LibGfx/AffineTransform.h>
|
||||||
#include <LibGfx/Forward.h>
|
#include <LibGfx/Forward.h>
|
||||||
#include <LibGfx/Orientation.h>
|
#include <LibGfx/Orientation.h>
|
||||||
#include <LibIPC/Forward.h>
|
#include <LibIPC/Forward.h>
|
||||||
#include <math.h>
|
|
||||||
|
|
||||||
namespace Gfx {
|
namespace Gfx {
|
||||||
|
|
||||||
|
@ -223,7 +223,7 @@ public:
|
||||||
{
|
{
|
||||||
if (*this == other)
|
if (*this == other)
|
||||||
return 0;
|
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
|
[[nodiscard]] Point absolute_relative_distance_to(Point const& other) const
|
||||||
|
|
|
@ -6,8 +6,8 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <AK/Math.h>
|
||||||
#include <AK/String.h>
|
#include <AK/String.h>
|
||||||
#include <math.h>
|
|
||||||
|
|
||||||
namespace Gfx {
|
namespace Gfx {
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
@ -105,7 +105,7 @@ public:
|
||||||
|
|
||||||
constexpr T length() const
|
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
|
String to_string() const
|
||||||
|
|
|
@ -6,8 +6,8 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <AK/Math.h>
|
||||||
#include <AK/String.h>
|
#include <AK/String.h>
|
||||||
#include <math.h>
|
|
||||||
|
|
||||||
namespace Gfx {
|
namespace Gfx {
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
@ -121,7 +121,7 @@ public:
|
||||||
|
|
||||||
constexpr T length() const
|
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
|
String to_string() const
|
||||||
|
|
|
@ -6,8 +6,8 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <AK/Math.h>
|
||||||
#include <AK/String.h>
|
#include <AK/String.h>
|
||||||
#include <math.h>
|
|
||||||
|
|
||||||
namespace Gfx {
|
namespace Gfx {
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
@ -121,7 +121,7 @@ public:
|
||||||
|
|
||||||
constexpr T length() const
|
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
|
String to_string() const
|
||||||
|
|
|
@ -4,21 +4,21 @@
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <AK/Math.h>
|
||||||
#include <LibJS/Runtime/AbstractOperations.h>
|
#include <LibJS/Runtime/AbstractOperations.h>
|
||||||
#include <LibJS/Runtime/Error.h>
|
#include <LibJS/Runtime/Error.h>
|
||||||
#include <LibJS/Runtime/GlobalObject.h>
|
#include <LibJS/Runtime/GlobalObject.h>
|
||||||
#include <LibJS/Runtime/NumberConstructor.h>
|
#include <LibJS/Runtime/NumberConstructor.h>
|
||||||
#include <LibJS/Runtime/NumberObject.h>
|
#include <LibJS/Runtime/NumberObject.h>
|
||||||
#include <math.h>
|
|
||||||
|
|
||||||
#ifdef __clang__
|
#ifdef __clang__
|
||||||
# define EPSILON_VALUE pow(2, -52)
|
# define EPSILON_VALUE AK::exp2(-52.)
|
||||||
# define MAX_SAFE_INTEGER_VALUE pow(2, 53) - 1
|
# define MAX_SAFE_INTEGER_VALUE AK::exp2(53.) - 1
|
||||||
# define MIN_SAFE_INTEGER_VALUE -(pow(2, 53) - 1)
|
# define MIN_SAFE_INTEGER_VALUE -(AK::exp2(53.) - 1)
|
||||||
#else
|
#else
|
||||||
constexpr const double EPSILON_VALUE { __builtin_pow(2, -52) };
|
constexpr const double EPSILON_VALUE { __builtin_exp2(-52) };
|
||||||
constexpr const double MAX_SAFE_INTEGER_VALUE { __builtin_pow(2, 53) - 1 };
|
constexpr const double MAX_SAFE_INTEGER_VALUE { __builtin_exp2(53) - 1 };
|
||||||
constexpr const double MIN_SAFE_INTEGER_VALUE { -(__builtin_pow(2, 53) - 1) };
|
constexpr const double MIN_SAFE_INTEGER_VALUE { -(__builtin_exp2(53) - 1) };
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace JS {
|
namespace JS {
|
||||||
|
|
|
@ -14,7 +14,6 @@
|
||||||
#include <LibPDF/Parser.h>
|
#include <LibPDF/Parser.h>
|
||||||
#include <LibTextCodec/Decoder.h>
|
#include <LibTextCodec/Decoder.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <math.h>
|
|
||||||
|
|
||||||
namespace PDF {
|
namespace PDF {
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
|
|
||||||
#include <AK/Assertions.h>
|
#include <AK/Assertions.h>
|
||||||
#include <AK/CheckedFormatString.h>
|
#include <AK/CheckedFormatString.h>
|
||||||
|
#include <AK/Math.h>
|
||||||
#include <LibTest/CrashTest.h>
|
#include <LibTest/CrashTest.h>
|
||||||
|
|
||||||
namespace AK {
|
namespace AK {
|
||||||
|
@ -89,7 +90,7 @@ void current_test_case_did_fail();
|
||||||
auto expect_close_lhs = a; \
|
auto expect_close_lhs = a; \
|
||||||
auto expect_close_rhs = b; \
|
auto expect_close_rhs = b; \
|
||||||
auto expect_close_diff = static_cast<double>(expect_close_lhs) - static_cast<double>(expect_close_rhs); \
|
auto expect_close_diff = static_cast<double>(expect_close_lhs) - static_cast<double>(expect_close_rhs); \
|
||||||
if (fabs(expect_close_diff) > 0.0000005) { \
|
if (AK::fabs(expect_close_diff) > 0.0000005) { \
|
||||||
::AK::warnln("\033[31;1mFAIL\033[0m: {}:{}: EXPECT_APPROXIMATE({}, {})" \
|
::AK::warnln("\033[31;1mFAIL\033[0m: {}:{}: EXPECT_APPROXIMATE({}, {})" \
|
||||||
" failed with lhs={}, rhs={}, (lhs-rhs)={}", \
|
" failed with lhs={}, rhs={}, (lhs-rhs)={}", \
|
||||||
__FILE__, __LINE__, #a, #b, expect_close_lhs, expect_close_rhs, expect_close_diff); \
|
__FILE__, __LINE__, #a, #b, expect_close_lhs, expect_close_rhs, expect_close_diff); \
|
||||||
|
|
|
@ -31,7 +31,6 @@
|
||||||
#include <LibGfx/StylePainter.h>
|
#include <LibGfx/StylePainter.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <math.h>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
|
@ -8,10 +8,10 @@
|
||||||
|
|
||||||
#include "MatroskaDocument.h"
|
#include "MatroskaDocument.h"
|
||||||
#include <AK/Debug.h>
|
#include <AK/Debug.h>
|
||||||
|
#include <AK/Math.h>
|
||||||
#include <AK/NonnullOwnPtrVector.h>
|
#include <AK/NonnullOwnPtrVector.h>
|
||||||
#include <AK/Optional.h>
|
#include <AK/Optional.h>
|
||||||
#include <AK/OwnPtr.h>
|
#include <AK/OwnPtr.h>
|
||||||
#include <math.h>
|
|
||||||
|
|
||||||
namespace Video {
|
namespace Video {
|
||||||
|
|
||||||
|
@ -122,7 +122,7 @@ private:
|
||||||
u8 next_octet = read_octet();
|
u8 next_octet = read_octet();
|
||||||
result = (result << 8u) | next_octet;
|
result = (result << 8u) | next_octet;
|
||||||
}
|
}
|
||||||
result -= pow(2, length * 7 - 1) - 1;
|
result -= AK::exp2<i64>(length * 7 - 1) - 1;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
#include <LibCore/Object.h>
|
#include <LibCore/Object.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <math.h>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
#include <LibELF/Image.h>
|
#include <LibELF/Image.h>
|
||||||
#include <LibX86/Disassembler.h>
|
#include <LibX86/Disassembler.h>
|
||||||
#include <LibX86/Instruction.h>
|
#include <LibX86/Instruction.h>
|
||||||
#include <math.h>
|
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
|
@ -292,7 +292,7 @@ int main(int argc, char** argv)
|
||||||
NtpTimestamp T3 = transmit_timestamp;
|
NtpTimestamp T3 = transmit_timestamp;
|
||||||
NtpTimestamp T4 = destination_timestamp;
|
NtpTimestamp T4 = destination_timestamp;
|
||||||
auto timestamp_difference_in_seconds = [](NtpTimestamp from, NtpTimestamp to) {
|
auto timestamp_difference_in_seconds = [](NtpTimestamp from, NtpTimestamp to) {
|
||||||
return static_cast<int64_t>(to - from) / pow(2.0, 32);
|
return static_cast<i64>(to - from) >> 32;
|
||||||
};
|
};
|
||||||
|
|
||||||
// The network round-trip time of the request.
|
// The network round-trip time of the request.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue