mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 08:57:47 +00:00
AK: Add to_radians and to_degrees math functions
This commit is contained in:
parent
9b7aa8f6b6
commit
494a8cb816
15 changed files with 40 additions and 40 deletions
|
@ -5,6 +5,7 @@
|
|||
*/
|
||||
|
||||
#include <AK/Format.h>
|
||||
#include <AK/Math.h>
|
||||
#include <LibGfx/DeltaE.h>
|
||||
#include <math.h>
|
||||
|
||||
|
@ -39,7 +40,7 @@ float DeltaE(CIELAB const& c1, CIELAB const& c2)
|
|||
float h_prime = atan2(b, a_prime);
|
||||
if (h_prime < 0)
|
||||
h_prime += 2 * static_cast<float>(M_PI);
|
||||
return h_prime * 180 / static_cast<float>(M_PI);
|
||||
return AK::to_degrees(h_prime);
|
||||
};
|
||||
float h1_prime = h_prime(c1.b, a1_prime);
|
||||
float h2_prime = h_prime(c2.b, a2_prime);
|
||||
|
@ -54,8 +55,8 @@ float DeltaE(CIELAB const& c1, CIELAB const& c2)
|
|||
else
|
||||
delta_h_prime = h2_prime - h1_prime - 360;
|
||||
|
||||
auto sin_degrees = [](float x) { return sinf(x * static_cast<float>(M_PI) / 180); };
|
||||
auto cos_degrees = [](float x) { return cosf(x * static_cast<float>(M_PI) / 180); };
|
||||
auto sin_degrees = [](float x) { return sinf(AK::to_radians(x)); };
|
||||
auto cos_degrees = [](float x) { return cosf(AK::to_radians(x)); };
|
||||
|
||||
float delta_H_prime = 2 * sqrtf(C1_prime * C2_prime) * sin_degrees(delta_h_prime / 2);
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ public:
|
|||
private:
|
||||
static FloatMatrix3x3 calculate_hue_rotate_matrix(float angle_degrees)
|
||||
{
|
||||
float angle_rads = angle_degrees * (AK::Pi<float> / 180);
|
||||
float angle_rads = AK::to_radians(angle_degrees);
|
||||
float cos_angle = 0;
|
||||
float sin_angle = 0;
|
||||
AK::sincos(angle_rads, sin_angle, cos_angle);
|
||||
|
|
|
@ -241,7 +241,7 @@ static auto create_conic_gradient(ReadonlySpan<ColorStop> color_stops, FloatPoin
|
|||
[=](int x, int y) {
|
||||
auto point = FloatPoint { x, y } - center_point;
|
||||
// FIXME: We could probably get away with some approximation here:
|
||||
auto loc = fmod((AK::atan2(point.y(), point.x()) * 180.0f / AK::Pi<float> + 360.0f + normalized_start_angle), 360.0f);
|
||||
auto loc = fmod((AK::to_degrees(AK::atan2(point.y(), point.x())) + 360.0f + normalized_start_angle), 360.0f);
|
||||
return should_floor_angles ? floor(loc) : loc;
|
||||
}
|
||||
};
|
||||
|
@ -256,7 +256,7 @@ static auto create_radial_gradient(IntRect const& physical_rect, ReadonlySpan<Co
|
|||
auto center_point = FloatPoint { center }.translated(0.5, 0.5);
|
||||
AffineTransform rotation_transform;
|
||||
if (rotation_angle.has_value()) {
|
||||
auto angle_as_radians = rotation_angle.value() * (AK::Pi<float> / 180);
|
||||
auto angle_as_radians = AK::to_radians(rotation_angle.value());
|
||||
rotation_transform.rotate_radians(angle_as_radians);
|
||||
}
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ inline float normalized_gradient_angle_radians(float gradient_angle)
|
|||
{
|
||||
// Adjust angle so 0 degrees is bottom
|
||||
float real_angle = 90 - gradient_angle;
|
||||
return real_angle * (AK::Pi<float> / 180);
|
||||
return AK::to_radians(real_angle);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue