Skip to content

Commit 30f6d82

Browse files
committed
Added degrees/radians conversions to math.h (same as what we'll have on master later). agx (v4) now uses fractional numbers internally, only the UI has percentages. Reformatted with 'if()', 'for()'. Temporarily backported some changes from deg2rad for consistency.
1 parent 168c722 commit 30f6d82

File tree

4 files changed

+275
-170
lines changed

4 files changed

+275
-170
lines changed

src/common/math.h

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* This file is part of darktable,
3-
* Copyright (C) 2018-2024 darktable developers.
3+
* Copyright (C) 2018-2025 darktable developers.
44
*
55
* darktable is free software: you can redistribute it and/or modify
66
* it under the terms of the GNU General Public License as published by
@@ -749,9 +749,32 @@ static inline void dt_vector_sin(const dt_aligned_pixel_t arg,
749749
sine[c] = scaled[c] * (p[c] * (abs_scaled[c] - one[c]) + one[c]);
750750
}
751751

752-
inline float deg2rad(const float degrees)
752+
// allows evaluating conversions involving constants at compile, e.g.:
753+
// const double right_angle = 90 * degrees;
754+
static const double degrees = M_PI / 180;
755+
756+
// conversion factor, e.g.
757+
// dt_bauhaus_slider_set_factor(slider, RAD_2_DEG);
758+
static const double RAD_2_DEG = 180 / M_PI;
759+
760+
static inline float deg2radf(const float deg)
761+
{
762+
return deg * M_PI_F / 180.f;
763+
}
764+
765+
static inline float rad2degf(const float radians)
766+
{
767+
return radians / M_PI_F * 180.f;
768+
}
769+
770+
static inline double deg2rad(const double deg)
771+
{
772+
return deg * M_PI / 180.0;
773+
}
774+
775+
static inline double rad2deg(const double radians)
753776
{
754-
return degrees * M_PI_F / 180.f;
777+
return radians / M_PI * 180.0;
755778
}
756779

757780
// clang-format off

src/dtgtk/paint.c

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@
2121
#include "gui/draw.h"
2222
#include <math.h>
2323

24-
#ifndef M_PI
25-
#define M_PI 3.141592654
26-
#endif
27-
2824
#define PREAMBLE(scaling, line_scaling, x_offset, y_offset) { \
2925
cairo_save(cr); \
3026
cairo_set_line_cap(cr, CAIRO_LINE_CAP_ROUND); \
@@ -41,8 +37,6 @@
4137

4238
static void _rounded_rectangle(cairo_t *cr) // create rounded rectangle to use in other icons
4339
{
44-
const double degrees = M_PI / 180.0;
45-
4640
cairo_new_sub_path (cr);
4741
cairo_arc (cr, 0.9, 0.1, 0.1, -90 * degrees, 0 * degrees);
4842
cairo_arc (cr, 0.9, 0.9, 0.1, 0 * degrees, 90 * degrees);
@@ -1097,8 +1091,6 @@ void dtgtk_cairo_paint_focus_peaking(cairo_t *cr, gint x, gint y, gint w, gint h
10971091
const double top = center - offset_h;
10981092
const double bottom = center + offset_h;
10991093

1100-
const double degrees = M_PI / 180.0;
1101-
11021094
/// north west
11031095
cairo_move_to(cr, left, top + tick_length);
11041096
cairo_arc (cr, left + radius, top + radius, radius, 180 * degrees, 270 * degrees);
@@ -1367,7 +1359,6 @@ void dtgtk_cairo_paint_color_harmony(cairo_t *cr, gint x, gint y, gint w, gint h
13671359
{
13681360
PREAMBLE(1, 1, 0.5, 0.5)
13691361

1370-
const double degrees = M_PI / 180.0;
13711362
typedef struct
13721363
{
13731364
const char *name;
@@ -1460,8 +1451,6 @@ void dtgtk_cairo_paint_directory(cairo_t *cr, gint x, gint y, gint w, gint h, gi
14601451
{
14611452
PREAMBLE(1, 1, 0, 0);
14621453

1463-
const double degrees = M_PI / 180.0;
1464-
14651454
cairo_new_sub_path (cr);
14661455
cairo_arc (cr, 0.85, 0.35, 0.1, -90 * degrees, 0 * degrees);
14671456
cairo_arc (cr, 0.8, 0.75, 0.1, 0 * degrees, 90 * degrees);

src/gui/gtk.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4230,7 +4230,6 @@ void dt_gui_draw_rounded_rectangle(cairo_t *cr,
42304230
const float y)
42314231
{
42324232
const float radius = height / 5.0f;
4233-
const float degrees = M_PI / 180.0;
42344233
cairo_new_sub_path(cr);
42354234
cairo_arc(cr, x + width - radius, y + radius, radius, -90 * degrees, 0 * degrees);
42364235
cairo_arc(cr, x + width - radius, y + height - radius, radius, 0 * degrees, 90 * degrees);

0 commit comments

Comments
 (0)