1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 04:07:46 +00:00

AK: Add to_radians and to_degrees math functions

This commit is contained in:
Bastiaan van der Plaat 2023-09-09 14:43:39 +02:00 committed by Sam Atkins
parent 9b7aa8f6b6
commit 494a8cb816
15 changed files with 40 additions and 40 deletions

View file

@ -11,16 +11,6 @@
#include <LibProtocol/Request.h>
// Math helpers
static double radians(double degrees)
{
return degrees * M_PI / 180.0;
}
static double degrees(double radians)
{
return radians * 180.0 / M_PI;
}
// https://wiki.openstreetmap.org/wiki/Slippy_map_tilenames#Pseudo-code
static double longitude_to_tile_x(double longitude, int zoom)
{
@ -29,7 +19,7 @@ static double longitude_to_tile_x(double longitude, int zoom)
static double latitude_to_tile_y(double latitude, int zoom)
{
return pow(2, zoom) * (1.0 - (log(tan(radians(latitude)) + (1.0 / cos(radians(latitude)))) / M_PI)) / 2.0;
return pow(2, zoom) * (1.0 - (log(tan(AK::to_radians(latitude)) + (1.0 / cos(AK::to_radians(latitude)))) / M_PI)) / 2.0;
}
static double tile_x_to_longitude(double x, int zoom)
@ -39,7 +29,7 @@ static double tile_x_to_longitude(double x, int zoom)
static double tile_y_to_latitude(double y, int zoom)
{
return degrees(atan(sinh(M_PI * (1.0 - 2.0 * y / pow(2, zoom)))));
return AK::to_degrees(atan(sinh(M_PI * (1.0 - 2.0 * y / pow(2, zoom)))));
}
static double nice_round_number(double number)
@ -52,7 +42,7 @@ static double nice_round_number(double number)
double MapWidget::LatLng::distance_to(LatLng const& other) const
{
double const earth_radius = 6371000.0;
return earth_radius * 2.0 * asin(sqrt(pow(sin((radians(other.latitude) - radians(latitude)) / 2.0), 2.0) + cos(radians(latitude)) * cos(radians(other.latitude)) * pow(sin((radians(other.longitude) - radians(longitude)) / 2.0), 2.0)));
return earth_radius * 2.0 * asin(sqrt(pow(sin((AK::to_radians(other.latitude) - AK::to_radians(latitude)) / 2.0), 2.0) + cos(AK::to_radians(latitude)) * cos(AK::to_radians(other.latitude)) * pow(sin((AK::to_radians(other.longitude) - AK::to_radians(longitude)) / 2.0), 2.0)));
}
// MapWidget class

View file

@ -312,7 +312,7 @@ void ColorWheelWidget::paint_event(GUI::PaintEvent&)
auto wedge_edge = Gfx::FloatPoint(0, -height() / 2);
float deg_as_radians = 10.0f * (AK::Pi<float> / 180);
float deg_as_radians = AK::to_radians(10.0f);
Gfx::AffineTransform transform;
transform.rotate_radians(deg_as_radians);
@ -339,12 +339,12 @@ void ColorWheelWidget::paint_event(GUI::PaintEvent&)
}
transform.rotate_radians(-deg_as_radians);
deg_as_radians = static_cast<float>(hue()) * (AK::Pi<float> / 180);
deg_as_radians = AK::to_radians(static_cast<float>(hue()));
transform.rotate_radians(deg_as_radians);
auto selected_color = Gfx::FloatPoint(0, -height() / 2);
selected_color.transform_by(transform);
deg_as_radians = static_cast<float>(color_range()) * (AK::Pi<float> / 180);
deg_as_radians = AK::to_radians(static_cast<float>(color_range()));
auto selected_color_edge_1 = Gfx::FloatPoint(0, -height() / 2);
transform.rotate_radians(deg_as_radians);
@ -356,7 +356,7 @@ void ColorWheelWidget::paint_event(GUI::PaintEvent&)
selected_color_edge_2.transform_by(transform);
transform.rotate_radians(deg_as_radians);
deg_as_radians = static_cast<float>(color_range() * static_cast<double>(hardness()) / 100.0) * (AK::Pi<float> / 180);
deg_as_radians = AK::to_radians(static_cast<float>(color_range() * static_cast<double>(hardness()) / 100.0));
auto hardness_edge_1 = Gfx::FloatPoint(0, -height() / 2);
transform.rotate_radians(deg_as_radians);
@ -438,7 +438,7 @@ void ColorWheelWidget::calc_hue(Gfx::IntPoint const& position)
{
auto center = Gfx::IntPoint(width() / 2, height() / 2);
auto angle = AK::atan2(static_cast<float>(position.y() - center.y()), static_cast<float>(position.x() - center.x())) * 180 / AK::Pi<float>;
auto angle = AK::atan2(static_cast<float>(position.y() - center.y()), AK::to_degrees(static_cast<float>(position.x() - center.x())));
set_hue(angle + 90);
}

View file

@ -354,7 +354,7 @@ void GradientTool::draw_gradient(GUI::Painter& painter, bool with_guidelines, co
int height = m_editor->active_layer()->rect().height() * scale;
float rotation_radians = atan2f(t_gradient_begin_line.a().y() - t_gradient_end_line.a().y(), t_gradient_begin_line.a().x() - t_gradient_end_line.a().x());
float rotation_degrees = (rotation_radians * 180) / AK::Pi<float>;
float rotation_degrees = AK::to_degrees(rotation_radians);
auto determine_required_side_length = [&](int center, int side_length) {
if (center < 0)