mirror of
https://github.com/gryf/wmaker.git
synced 2025-12-19 04:20:27 +01:00
replaced all local definitions of PI by a single one
For code maintainability, it is better to have a single definition of the constant than many ones dispatched in many places. In addition, we try to count on the constant M_PI that can be defined by the header <math.h> if possible because it may have the best accuracy for the platform. Signed-off-by: Christophe CURIS <christophe.curis@free.fr>
This commit is contained in:
committed by
Carlos R. Mafra
parent
723f217355
commit
4799df5506
@@ -265,9 +265,6 @@ enum {
|
|||||||
#define COLORWHEEL_PART 1
|
#define COLORWHEEL_PART 1
|
||||||
#define CUSTOMPALETTE_PART 2
|
#define CUSTOMPALETTE_PART 2
|
||||||
|
|
||||||
#ifndef M_PI
|
|
||||||
#define M_PI 3.14159265358979323846
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static char *generateNewFilename(const char *curName);
|
static char *generateNewFilename(const char *curName);
|
||||||
static void convertCPColor(CPColor * color);
|
static void convertCPColor(CPColor * color);
|
||||||
@@ -1951,7 +1948,7 @@ static void wheelInitMatrix(W_ColorPanel * panel)
|
|||||||
if (sat < 256) {
|
if (sat < 256) {
|
||||||
if (xcor != 0)
|
if (xcor != 0)
|
||||||
dhue[0] = rint(atan((double)ycor / (double)xcor) *
|
dhue[0] = rint(atan((double)ycor / (double)xcor) *
|
||||||
(180.0 / M_PI)) + (xcor < 0 ? 180.0 : 0.0);
|
(180.0 / WM_PI)) + (xcor < 0 ? 180.0 : 0.0);
|
||||||
else
|
else
|
||||||
dhue[0] = 270;
|
dhue[0] = 270;
|
||||||
|
|
||||||
@@ -2237,7 +2234,7 @@ static void wheelPositionSelectionOutBounds(W_ColorPanel * panel, int x, int y)
|
|||||||
panel->color.hsv.value = 255 - WMGetSliderValue(panel->wheelBrightnessS);
|
panel->color.hsv.value = 255 - WMGetSliderValue(panel->wheelBrightnessS);
|
||||||
|
|
||||||
if (xcor != 0)
|
if (xcor != 0)
|
||||||
hue = rint(atan(-(double)ycor / (double)xcor) * (180.0 / M_PI));
|
hue = rint(atan(-(double)ycor / (double)xcor) * (180.0 / WM_PI));
|
||||||
else {
|
else {
|
||||||
if (ycor < 0)
|
if (ycor < 0)
|
||||||
hue = 90;
|
hue = 90;
|
||||||
@@ -2257,9 +2254,9 @@ static void wheelPositionSelectionOutBounds(W_ColorPanel * panel, int x, int y)
|
|||||||
|
|
||||||
wheelUndrawSelection(panel);
|
wheelUndrawSelection(panel);
|
||||||
|
|
||||||
panel->colx = 2 + rint((colorWheelSize * (1.0 + cos(panel->color.hsv.hue * (M_PI / 180.0)))) / 2.0);
|
panel->colx = 2 + rint((colorWheelSize * (1.0 + cos(panel->color.hsv.hue * (WM_PI / 180.0)))) / 2.0);
|
||||||
/* "+2" because of "colorWheelSize + 4" */
|
/* "+2" because of "colorWheelSize + 4" */
|
||||||
panel->coly = 2 + rint((colorWheelSize * (1.0 + sin(-panel->color.hsv.hue * (M_PI / 180.0)))) / 2.0);
|
panel->coly = 2 + rint((colorWheelSize * (1.0 + sin(-panel->color.hsv.hue * (WM_PI / 180.0)))) / 2.0);
|
||||||
|
|
||||||
wheelUpdateSelection(panel);
|
wheelUpdateSelection(panel);
|
||||||
cpColor = panel->color;
|
cpColor = panel->color;
|
||||||
@@ -3357,10 +3354,10 @@ static void wheelInit(W_ColorPanel * panel)
|
|||||||
|
|
||||||
panel->colx = 2 + rint((colorWheelSize / 2.0) *
|
panel->colx = 2 + rint((colorWheelSize / 2.0) *
|
||||||
(1 + (panel->color.hsv.saturation / 255.0) *
|
(1 + (panel->color.hsv.saturation / 255.0) *
|
||||||
cos(panel->color.hsv.hue * M_PI / 180.0)));
|
cos(panel->color.hsv.hue * WM_PI / 180.0)));
|
||||||
panel->coly = 2 + rint((colorWheelSize / 2.0) *
|
panel->coly = 2 + rint((colorWheelSize / 2.0) *
|
||||||
(1 + (panel->color.hsv.saturation / 255.0) *
|
(1 + (panel->color.hsv.saturation / 255.0) *
|
||||||
sin(-panel->color.hsv.hue * M_PI / 180.0)));
|
sin(-panel->color.hsv.hue * WM_PI / 180.0)));
|
||||||
|
|
||||||
wheelCalculateValues(panel, panel->color.hsv.value);
|
wheelCalculateValues(panel, panel->color.hsv.value);
|
||||||
|
|
||||||
|
|||||||
@@ -30,5 +30,24 @@ AC_CHECK_FUNC(atan,
|
|||||||
[LIBM=-lm],
|
[LIBM=-lm],
|
||||||
[AC_MSG_WARN(Could not find Math library, you may experience problems)
|
[AC_MSG_WARN(Could not find Math library, you may experience problems)
|
||||||
LIBM=] )] ) dnl
|
LIBM=] )] ) dnl
|
||||||
|
AC_CACHE_CHECK([if M_PI is defined in math.h], [wm_cv_libm_pi],
|
||||||
|
[wm_cv_libm_pi="no"
|
||||||
|
wm_save_CFLAGS="$CFLAGS"
|
||||||
|
for wm_arg in dnl
|
||||||
|
"% yes" dnl natively available (Unix98 compliant?)
|
||||||
|
"-D_XOPEN_SOURCE=500" ; dnl Explicit request
|
||||||
|
do
|
||||||
|
AS_IF([wm_fn_lib_try_compile "math.h" "double val;" "val = M_PI" dnl
|
||||||
|
"`echo "$wm_arg" | sed -e 's, *%.*$,,' `"],
|
||||||
|
[wm_cv_libm_pi="`echo "$wm_arg" | sed -e 's,^.*% *,,' `" ; break])
|
||||||
|
done
|
||||||
|
CFLAGS="$wm_save_CFLAGS"])
|
||||||
|
AS_IF([test "x$wm_cv_libm_pi" = "xno"],
|
||||||
|
[AC_DEFINE([WM_PI], [(3.14159265358979323846)],
|
||||||
|
[Defines how to access the value of Pi])],
|
||||||
|
[AC_DEFINE([WM_PI], [(M_PI)],
|
||||||
|
[Defines how to access the value of Pi])
|
||||||
|
AS_IF([test "x$wm_cv_libm_pi" != "xyes"],
|
||||||
|
[CFLAGS="$CFLAGS $wm_cv_libm_pi"]) ])
|
||||||
AC_SUBST(LIBM) dnl
|
AC_SUBST(LIBM) dnl
|
||||||
])
|
])
|
||||||
|
|||||||
@@ -334,7 +334,6 @@
|
|||||||
|
|
||||||
/* number of window shortcuts */
|
/* number of window shortcuts */
|
||||||
#define MAX_WINDOW_SHORTCUTS 10
|
#define MAX_WINDOW_SHORTCUTS 10
|
||||||
#define WM_PI 3.14159265358979323846
|
|
||||||
#define MIN_TITLEFONT_HEIGHT(h) ((h)>14 ? (h) : 14)
|
#define MIN_TITLEFONT_HEIGHT(h) ((h)>14 ? (h) : 14)
|
||||||
#define TITLEBAR_HEIGHT 18 /* window's titlebar height */
|
#define TITLEBAR_HEIGHT 18 /* window's titlebar height */
|
||||||
#define RESIZEBAR_HEIGHT 8 /* height of the resizebar */
|
#define RESIZEBAR_HEIGHT 8 /* height of the resizebar */
|
||||||
|
|||||||
@@ -33,9 +33,6 @@
|
|||||||
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
#ifndef PI
|
|
||||||
#define PI 3.14159265358979323846
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static RImage *rotate_image_90(RImage *source);
|
static RImage *rotate_image_90(RImage *source);
|
||||||
static RImage *rotate_image_270(RImage *source);
|
static RImage *rotate_image_270(RImage *source);
|
||||||
@@ -347,13 +344,13 @@ static RImage *rotate_image_any(RImage *source, float angle)
|
|||||||
if (angle > 180.0)
|
if (angle > 180.0)
|
||||||
angle -= 180.0;
|
angle -= 180.0;
|
||||||
|
|
||||||
angle = (angle * PI) / 180.0;
|
angle = (angle * WM_PI) / 180.0;
|
||||||
|
|
||||||
nwidth = ceil(abs(cos(angle) * image->width))
|
nwidth = ceil(abs(cos(angle) * image->width))
|
||||||
+ ceil(abs(cos(PI / 2 - angle) * image->width));
|
+ ceil(abs(cos(WM_PI / 2 - angle) * image->width));
|
||||||
|
|
||||||
nheight = ceil(abs(sin(angle) * image->height))
|
nheight = ceil(abs(sin(angle) * image->height))
|
||||||
+ ceil(abs(cos(PI / 2 - angle) * image->height));
|
+ ceil(abs(cos(WM_PI / 2 - angle) * image->height));
|
||||||
|
|
||||||
img = RCreateImage(nwidth, nheight, True);
|
img = RCreateImage(nwidth, nheight, True);
|
||||||
if (!img)
|
if (!img)
|
||||||
@@ -362,16 +359,16 @@ static RImage *rotate_image_any(RImage *source, float angle)
|
|||||||
src = image->data;
|
src = image->data;
|
||||||
dst = img->data;
|
dst = img->data;
|
||||||
|
|
||||||
x1 = floor(abs(cos(PI / 2 - angle) * image->width));
|
x1 = floor(abs(cos(WM_PI / 2 - angle) * image->width));
|
||||||
y1 = 0;
|
y1 = 0;
|
||||||
|
|
||||||
x2 = 0;
|
x2 = 0;
|
||||||
y2 = floor(abs(sin(PI / 2 - angle) * image->width));
|
y2 = floor(abs(sin(WM_PI / 2 - angle) * image->width));
|
||||||
|
|
||||||
xx = floor(abs(cos(angle) * image->height)) - 1;
|
xx = floor(abs(cos(angle) * image->height)) - 1;
|
||||||
yy = nheight - 1;
|
yy = nheight - 1;
|
||||||
|
|
||||||
printf("%ix%i, %i %i %i %i %i\n", nwidth, nheight, x1, y1, x2, y2, (int)((angle * 180.0) / PI));
|
printf("%ix%i, %i %i %i %i %i\n", nwidth, nheight, x1, y1, x2, y2, (int)((angle * 180.0) / WM_PI));
|
||||||
|
|
||||||
dx = abs(x2 - x1);
|
dx = abs(x2 - x1);
|
||||||
dy = abs(y2 - y1);
|
dy = abs(y2 - y1);
|
||||||
@@ -414,8 +411,8 @@ static RImage *rotate_image_any(RImage *source, float angle)
|
|||||||
p = dpr - dy;
|
p = dpr - dy;
|
||||||
|
|
||||||
while (dy-- >= 0) {
|
while (dy-- >= 0) {
|
||||||
xx = abs(x1 * sin(angle * PI / 180.0));
|
xx = abs(x1 * sin(angle * WM_PI / 180.0));
|
||||||
yy = abs(y1 * cos(angle * PI / 180.0));
|
yy = abs(y1 * cos(angle * WM_PI / 180.0));
|
||||||
|
|
||||||
copyLine(x1, y1, xx, yy, nwidth, image->format, dst, &src);
|
copyLine(x1, y1, xx, yy, nwidth, image->format, dst, &src);
|
||||||
|
|
||||||
|
|||||||
@@ -27,11 +27,6 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <X11/Xlib.h>
|
#include <X11/Xlib.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
#ifndef PI
|
|
||||||
#define PI 3.14159265358979323846
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
#include "wraster.h"
|
#include "wraster.h"
|
||||||
@@ -200,7 +195,7 @@ static double sinc(double x)
|
|||||||
* The goal was to avoid a Divide-by-0 error, now we also
|
* The goal was to avoid a Divide-by-0 error, now we also
|
||||||
* avoid a +/-inf result too
|
* avoid a +/-inf result too
|
||||||
*/
|
*/
|
||||||
x *= PI;
|
x *= WM_PI;
|
||||||
if (x > 1.0E-9)
|
if (x > 1.0E-9)
|
||||||
return (sin(x) / x);
|
return (sin(x) / x);
|
||||||
return (1.0);
|
return (1.0);
|
||||||
|
|||||||
Reference in New Issue
Block a user