Commit 933b8661 authored by Tor Lillqvist's avatar Tor Lillqvist

Define ROUND(), RINT(), SQR(), G_PI and G_PI_4. The latter two will

	* app/appenv.h: Define ROUND(), RINT(), SQR(), G_PI and
	G_PI_4. The latter two will presumably eventually be in
	GLib. RINT() calls rint() if we have it, otherwise adds 0.5 and
	calls floor().

	* app/*.c: Remove the multiple identical definitions of M_PI. Use
	G_PI instead of M_PI. Remove ROUND() and rint() definitions. Use
	RINT() instead of rint().
parent b41809f8
1999-08-05 Tor Lillqvist <tml@iki.fi>
* app/appenv.h: Define ROUND(), RINT(), SQR(), G_PI and
G_PI_4. The latter two will presumably eventually be in
GLib. RINT() calls rint() if we have it, otherwise adds 0.5 and
calls floor().
* app/*.c: Remove the multiple identical definitions of M_PI. Use
G_PI instead of M_PI. Remove ROUND() and rint() definitions. Use
RINT() instead of rint().
Tue Aug 3 22:16:57 MEST 1999 Sven Neumann <sven@gimp.org>
* app/interface.c: My last change to the dnd code did fix the bug
......
......@@ -42,6 +42,24 @@
#define MINIMUM(x,y) MIN(x,y)
#define MAXIMUM(x,y) MAX(x,y)
#ifndef G_PI /* G_PI will be in GLib eventually */
#define G_PI 3.14159265358979323846
#endif
#ifndef G_PI_4 /* As will G_PI_4 */
#define G_PI_4 0.78539816339744830962
#endif
#ifdef HAVE_RINT
#define RINT(x) rint(x)
#else
#define RINT(x) floor ((x)+0.5)
#endif
#define ROUND(x) ((int) ((x)+0.5))
/* Square */
#define SQR(x) ((x)*(x))
/* limit a (0->511) int to 255 */
#define MAX255(a) ((a) | (((a) & 256) - (((a) & 256) >> 8)))
......
......@@ -33,8 +33,6 @@
#include "libgimp/gimpintl.h"
#define ROUND(x) ((int) ((x) + 0.5))
#define GRAPH 0x1
#define XRANGE_TOP 0x2
#define XRANGE_BOTTOM 0x4
......
......@@ -18,15 +18,13 @@
#include "config.h"
#include "gimplut.h"
#include "gimphistogram.h"
#include <stdio.h>
#include <math.h>
#include <stdio.h>
#include <glib.h>
#ifndef HAVE_RINT
#define rint(x) floor (x + 0.5)
#endif
#include "appenv.h"
#include "gimplut.h"
#include "gimphistogram.h"
/* ---------- Brightness/Contrast -----------*/
......@@ -329,7 +327,7 @@ posterize_lut_func(int *ilevels,
else
levels = *ilevels;
value = rint(value * (levels - 1.0)) / (levels - 1.0);
value = RINT(value * (levels - 1.0)) / (levels - 1.0);
return value;
}
......
......@@ -35,10 +35,6 @@
#include "libgimp/gimpintl.h"
#ifndef HAVE_RINT
#define rint(x) floor (x + 0.5)
#endif
/* Bezier extensions made by Raphael FRANCOIS (fraph@ibm.net)
BEZIER_EXTENDS VER 1.0
......@@ -67,8 +63,6 @@
#define NO 0
#define YES 1
#define ROUND(x) ((int) ((x) + 0.5))
/* the bezier select structures */
typedef double BezierMatrix[4][4];
......@@ -1946,8 +1940,6 @@ bezier_draw_segment (BezierSelect *bezier_sel,
BezierPointsFunc points_func,
gpointer udata)
{
#define ROUND(x) ((int) ((x) + 0.5))
static GdkPoint gdk_points[256];
static int npoints = 256;
......@@ -2621,8 +2613,8 @@ test_add_point_on_segment (BezierSelect *bezier_sel,
geometry[i][1] = points->y;
break;
case AA_IMAGE_COORDS:
geometry[i][0] = rint(points->x * SUPERSAMPLE);
geometry[i][1] = rint(points->y * SUPERSAMPLE);
geometry[i][0] = RINT(points->x * SUPERSAMPLE);
geometry[i][1] = RINT(points->y * SUPERSAMPLE);
break;
case SCREEN_COORDS:
geometry[i][0] = points->sx;
......@@ -3289,8 +3281,8 @@ bezier_draw_segment_for_distance (BezierSelect *bezier_sel,
bdist->curdist += sqrt((dx*dx)+(dy*dy));
if(bdist->curdist >= bdist->dist)
{
*(bdist->x) = (gint)ROUND((rx + dx/2));
*(bdist->y) = (gint)ROUND((ry + dy/2));
*(bdist->x) = ROUND((rx + dx/2));
*(bdist->y) = ROUND((ry + dy/2));
if(dx == 0.0)
*(bdist->gradient) = G_MAXDOUBLE;
else
......
......@@ -45,12 +45,6 @@
#define TARGET_HEIGHT 15
#define TARGET_WIDTH 15
#define SQR(x) ((x) * (x))
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif /* M_PI */
#define STATUSBAR_SIZE 128
/* the blend structures */
......@@ -869,7 +863,7 @@ gradient_calc_conical_sym_factor (double dist,
/* This cool idea is courtesy Josh MacDonald,
* Ali Rahimi --- two more XCF losers. */
rat = acos(rat) / M_PI;
rat = acos(rat) / G_PI;
rat = pow(rat, (offset / 10) + 1);
rat = BOUNDS(rat, 0.0, 1.0);
......@@ -900,15 +894,15 @@ gradient_calc_conical_asym_factor (double dist,
{
if ((x != 0) || (y != 0))
{
ang0 = atan2(axis[0], axis[1]) + M_PI;
ang1 = atan2(x, y) + M_PI;
ang0 = atan2(axis[0], axis[1]) + G_PI;
ang1 = atan2(x, y) + G_PI;
ang = ang1 - ang0;
if (ang < 0.0)
ang += (2.0 * M_PI);
ang += (2.0 * G_PI);
rat = ang / (2.0 * M_PI);
rat = ang / (2.0 * G_PI);
rat = pow(rat, (offset / 10) + 1);
rat = BOUNDS(rat, 0.0, 1.0);
......@@ -1064,18 +1058,18 @@ gradient_calc_spiral_factor (double dist,
{
if (x != 0.0 || y != 0.0)
{
ang0 = atan2 (axis[0], axis[1]) + M_PI;
ang1 = atan2 (x, y) + M_PI;
ang0 = atan2 (axis[0], axis[1]) + G_PI;
ang1 = atan2 (x, y) + G_PI;
if(!cwise)
ang = ang0 - ang1;
else
ang = ang1 - ang0;
if (ang < 0.0)
ang += (2.0 * M_PI);
ang += (2.0 * G_PI);
r = sqrt (x * x + y * y) / dist;
rat = ang / (2.0 * M_PI) + r + offset;
rat = ang / (2.0 * G_PI) + r + offset;
rat = fmod (rat, 1.0);
}
else
......@@ -1115,7 +1109,7 @@ gradient_calc_shapeburst_spherical_factor (double x,
iy = (int) BOUNDS (y, 0, distR.h);
tile = tile_manager_get_tile (distR.tiles, ix, iy, TRUE, FALSE);
value = *((float *) tile_data_pointer (tile, ix % TILE_WIDTH, iy % TILE_HEIGHT));
value = 1.0 - sin (0.5 * M_PI * value);
value = 1.0 - sin (0.5 * G_PI * value);
tile_release (tile, FALSE);
return value;
......@@ -1134,7 +1128,7 @@ gradient_calc_shapeburst_dimpled_factor (double x,
iy = (int) BOUNDS (y, 0, distR.h);
tile = tile_manager_get_tile (distR.tiles, ix, iy, TRUE, FALSE);
value = *((float *) tile_data_pointer (tile, ix % TILE_WIDTH, iy % TILE_HEIGHT));
value = cos (0.5 * M_PI * value);
value = cos (0.5 * G_PI * value);
tile_release (tile, FALSE);
return value;
......
......@@ -29,11 +29,7 @@
#include <stdlib.h>
#include <string.h>
#define ROUND(A) floor((A)+0.5)
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif /* M_PI */
#include "appenv.h"
static Blob *
blob_new (int y, int height)
......@@ -621,7 +617,7 @@ blob_ellipse (double xc, double yc, double xp, double yp, double xq, double yq)
{
trig_initialized = 1;
for (i=0; i<256; i++)
trig_table[i] = 0.5 + sin(i * (M_PI / 128.)) * (1 << TABLE_SHIFT);
trig_table[i] = 0.5 + sin(i * (G_PI / 128.)) * (1 << TABLE_SHIFT);
}
/* Make sure we traverse ellipse in ccw direction */
......
......@@ -101,8 +101,6 @@ gimp_channel_init (GimpChannel *channel)
{
}
#define ROUND(x) ((int) (x + 0.5))
/*
* Static variables
*/
......
......@@ -24,14 +24,6 @@
#include <stdio.h>
#include <string.h>
#ifndef HAVE_RINT
#define rint(x) floor (x + 0.5)
#endif
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#include "appenv.h"
#include "gimpbrushgenerated.h"
#include "paint_core.h"
......@@ -260,8 +252,8 @@ gimp_brush_generated_generate(GimpBrushGenerated *brush)
temp_buf_free(gbrush->mask);
}
/* compute the range of the brush. should do a better job than this? */
s = sin(brush->angle*M_PI/180.0);
c = cos(brush->angle*M_PI/180.0);
s = sin(brush->angle*G_PI/180.0);
c = cos(brush->angle*G_PI/180.0);
tx = MAXIMUM(fabs(c*ceil(brush->radius) - s*ceil(brush->radius)
/brush->aspect_ratio),
fabs(c*ceil(brush->radius) + s*ceil(brush->radius)
......@@ -316,7 +308,7 @@ gimp_brush_generated_generate(GimpBrushGenerated *brush)
/* buffer[x%OVERSAMPLING] = (1.0 - pow(d/brush->radius, exponent));*/
buffer[x%OVERSAMPLING] = gauss(pow(d/brush->radius, exponent));
sum += buffer[x%OVERSAMPLING];
lookup[x++] = rint(sum*(255.0/OVERSAMPLING));
lookup[x++] = RINT(sum*(255.0/OVERSAMPLING));
}
while (x < length)
{
......@@ -332,7 +324,7 @@ gimp_brush_generated_generate(GimpBrushGenerated *brush)
ty *= brush->aspect_ratio;
d = sqrt(tx*tx + ty*ty);
if (d < brush->radius+1)
a = lookup[(int)rint(d*OVERSAMPLING)];
a = lookup[(int)RINT(d*OVERSAMPLING)];
else
a = 0;
centerp[ y*gbrush->mask->width + x] = a;
......
......@@ -24,14 +24,6 @@
#include <stdio.h>
#include <string.h>
#ifndef HAVE_RINT
#define rint(x) floor (x + 0.5)
#endif
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#include "appenv.h"
#include "gimpbrushgenerated.h"
#include "paint_core.h"
......@@ -260,8 +252,8 @@ gimp_brush_generated_generate(GimpBrushGenerated *brush)
temp_buf_free(gbrush->mask);
}
/* compute the range of the brush. should do a better job than this? */
s = sin(brush->angle*M_PI/180.0);
c = cos(brush->angle*M_PI/180.0);
s = sin(brush->angle*G_PI/180.0);
c = cos(brush->angle*G_PI/180.0);
tx = MAXIMUM(fabs(c*ceil(brush->radius) - s*ceil(brush->radius)
/brush->aspect_ratio),
fabs(c*ceil(brush->radius) + s*ceil(brush->radius)
......@@ -316,7 +308,7 @@ gimp_brush_generated_generate(GimpBrushGenerated *brush)
/* buffer[x%OVERSAMPLING] = (1.0 - pow(d/brush->radius, exponent));*/
buffer[x%OVERSAMPLING] = gauss(pow(d/brush->radius, exponent));
sum += buffer[x%OVERSAMPLING];
lookup[x++] = rint(sum*(255.0/OVERSAMPLING));
lookup[x++] = RINT(sum*(255.0/OVERSAMPLING));
}
while (x < length)
{
......@@ -332,7 +324,7 @@ gimp_brush_generated_generate(GimpBrushGenerated *brush)
ty *= brush->aspect_ratio;
d = sqrt(tx*tx + ty*ty);
if (d < brush->radius+1)
a = lookup[(int)rint(d*OVERSAMPLING)];
a = lookup[(int)RINT(d*OVERSAMPLING)];
else
a = 0;
centerp[ y*gbrush->mask->width + x] = a;
......
......@@ -24,14 +24,6 @@
#include <stdio.h>
#include <string.h>
#ifndef HAVE_RINT
#define rint(x) floor (x + 0.5)
#endif
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#include "appenv.h"
#include "gimpbrushgenerated.h"
#include "paint_core.h"
......@@ -260,8 +252,8 @@ gimp_brush_generated_generate(GimpBrushGenerated *brush)
temp_buf_free(gbrush->mask);
}
/* compute the range of the brush. should do a better job than this? */
s = sin(brush->angle*M_PI/180.0);
c = cos(brush->angle*M_PI/180.0);
s = sin(brush->angle*G_PI/180.0);
c = cos(brush->angle*G_PI/180.0);
tx = MAXIMUM(fabs(c*ceil(brush->radius) - s*ceil(brush->radius)
/brush->aspect_ratio),
fabs(c*ceil(brush->radius) + s*ceil(brush->radius)
......@@ -316,7 +308,7 @@ gimp_brush_generated_generate(GimpBrushGenerated *brush)
/* buffer[x%OVERSAMPLING] = (1.0 - pow(d/brush->radius, exponent));*/
buffer[x%OVERSAMPLING] = gauss(pow(d/brush->radius, exponent));
sum += buffer[x%OVERSAMPLING];
lookup[x++] = rint(sum*(255.0/OVERSAMPLING));
lookup[x++] = RINT(sum*(255.0/OVERSAMPLING));
}
while (x < length)
{
......@@ -332,7 +324,7 @@ gimp_brush_generated_generate(GimpBrushGenerated *brush)
ty *= brush->aspect_ratio;
d = sqrt(tx*tx + ty*ty);
if (d < brush->radius+1)
a = lookup[(int)rint(d*OVERSAMPLING)];
a = lookup[(int)RINT(d*OVERSAMPLING)];
else
a = 0;
centerp[ y*gbrush->mask->width + x] = a;
......
......@@ -101,8 +101,6 @@ gimp_channel_init (GimpChannel *channel)
{
}
#define ROUND(x) ((int) (x + 0.5))
/*
* Static variables
*/
......
......@@ -101,8 +101,6 @@ gimp_channel_init (GimpChannel *channel)
{
}
#define ROUND(x) ((int) (x + 0.5))
/*
* Static variables
*/
......
......@@ -45,12 +45,6 @@
#define TARGET_HEIGHT 15
#define TARGET_WIDTH 15
#define SQR(x) ((x) * (x))
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif /* M_PI */
#define STATUSBAR_SIZE 128
/* the blend structures */
......@@ -869,7 +863,7 @@ gradient_calc_conical_sym_factor (double dist,
/* This cool idea is courtesy Josh MacDonald,
* Ali Rahimi --- two more XCF losers. */
rat = acos(rat) / M_PI;
rat = acos(rat) / G_PI;
rat = pow(rat, (offset / 10) + 1);
rat = BOUNDS(rat, 0.0, 1.0);
......@@ -900,15 +894,15 @@ gradient_calc_conical_asym_factor (double dist,
{
if ((x != 0) || (y != 0))
{
ang0 = atan2(axis[0], axis[1]) + M_PI;
ang1 = atan2(x, y) + M_PI;
ang0 = atan2(axis[0], axis[1]) + G_PI;
ang1 = atan2(x, y) + G_PI;
ang = ang1 - ang0;
if (ang < 0.0)
ang += (2.0 * M_PI);
ang += (2.0 * G_PI);
rat = ang / (2.0 * M_PI);
rat = ang / (2.0 * G_PI);
rat = pow(rat, (offset / 10) + 1);
rat = BOUNDS(rat, 0.0, 1.0);
......@@ -1064,18 +1058,18 @@ gradient_calc_spiral_factor (double dist,
{
if (x != 0.0 || y != 0.0)
{
ang0 = atan2 (axis[0], axis[1]) + M_PI;
ang1 = atan2 (x, y) + M_PI;
ang0 = atan2 (axis[0], axis[1]) + G_PI;
ang1 = atan2 (x, y) + G_PI;
if(!cwise)
ang = ang0 - ang1;
else
ang = ang1 - ang0;
if (ang < 0.0)
ang += (2.0 * M_PI);
ang += (2.0 * G_PI);
r = sqrt (x * x + y * y) / dist;
rat = ang / (2.0 * M_PI) + r + offset;
rat = ang / (2.0 * G_PI) + r + offset;
rat = fmod (rat, 1.0);
}
else
......@@ -1115,7 +1109,7 @@ gradient_calc_shapeburst_spherical_factor (double x,
iy = (int) BOUNDS (y, 0, distR.h);
tile = tile_manager_get_tile (distR.tiles, ix, iy, TRUE, FALSE);
value = *((float *) tile_data_pointer (tile, ix % TILE_WIDTH, iy % TILE_HEIGHT));
value = 1.0 - sin (0.5 * M_PI * value);
value = 1.0 - sin (0.5 * G_PI * value);
tile_release (tile, FALSE);
return value;
......@@ -1134,7 +1128,7 @@ gradient_calc_shapeburst_dimpled_factor (double x,
iy = (int) BOUNDS (y, 0, distR.h);
tile = tile_manager_get_tile (distR.tiles, ix, iy, TRUE, FALSE);
value = *((float *) tile_data_pointer (tile, ix % TILE_WIDTH, iy % TILE_HEIGHT));
value = cos (0.5 * M_PI * value);
value = cos (0.5 * G_PI * value);
tile_release (tile, FALSE);
return value;
......
......@@ -33,8 +33,6 @@
#include "libgimp/gimpintl.h"
#define ROUND(x) ((int) ((x) + 0.5))
#define GRAPH 0x1
#define XRANGE_TOP 0x2
#define XRANGE_BOTTOM 0x4
......
......@@ -30,7 +30,6 @@
#include "libgimp/gimpintl.h"
#define DEFAULT_MAX_INC 1024
#define ROUND(x) ((int) (x + 0.5))
#define SUPERSAMPLE 3
#define SUPERSAMPLE2 9
......
......@@ -24,14 +24,6 @@
#include <stdio.h>
#include <string.h>
#ifndef HAVE_RINT
#define rint(x) floor (x + 0.5)
#endif
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#include "appenv.h"
#include "gimpbrushgenerated.h"
#include "paint_core.h"
......@@ -260,8 +252,8 @@ gimp_brush_generated_generate(GimpBrushGenerated *brush)
temp_buf_free(gbrush->mask);
}
/* compute the range of the brush. should do a better job than this? */
s = sin(brush->angle*M_PI/180.0);
c = cos(brush->angle*M_PI/180.0);
s = sin(brush->angle*G_PI/180.0);
c = cos(brush->angle*G_PI/180.0);
tx = MAXIMUM(fabs(c*ceil(brush->radius) - s*ceil(brush->radius)
/brush->aspect_ratio),
fabs(c*ceil(brush->radius) + s*ceil(brush->radius)
......@@ -316,7 +308,7 @@ gimp_brush_generated_generate(GimpBrushGenerated *brush)
/* buffer[x%OVERSAMPLING] = (1.0 - pow(d/brush->radius, exponent));*/
buffer[x%OVERSAMPLING] = gauss(pow(d/brush->radius, exponent));
sum += buffer[x%OVERSAMPLING];
lookup[x++] = rint(sum*(255.0/OVERSAMPLING));
lookup[x++] = RINT(sum*(255.0/OVERSAMPLING));
}
while (x < length)
{
......@@ -332,7 +324,7 @@ gimp_brush_generated_generate(GimpBrushGenerated *brush)
ty *= brush->aspect_ratio;
d = sqrt(tx*tx + ty*ty);
if (d < brush->radius+1)
a = lookup[(int)rint(d*OVERSAMPLING)];
a = lookup[(int)RINT(d*OVERSAMPLING)];
else
a = 0;
centerp[ y*gbrush->mask->width + x] = a;
......
......@@ -101,8 +101,6 @@ gimp_channel_init (GimpChannel *channel)
{
}
#define ROUND(x) ((int) (x + 0.5))
/*
* Static variables
*/
......
......@@ -172,10 +172,6 @@
/***** Magic numbers *****/
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif /* M_PI */
#define EPSILON 1e-10
......@@ -5945,7 +5941,7 @@ calc_sine_factor(double middle, double pos)
{
pos = calc_linear_factor(middle, pos);
return (sin((-M_PI / 2.0) + M_PI * pos) + 1.0) / 2.0;
return (sin((-G_PI / 2.0) + G_PI * pos) + 1.0) / 2.0;
} /* calc_sine_factor */
......
......@@ -172,10 +172,6 @@
/***** Magic numbers *****/
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif /* M_PI */
#define EPSILON 1e-10
......@@ -5945,7 +5941,7 @@ calc_sine_factor(double middle, double pos)
{
pos = calc_linear_factor(middle, pos);
return (sin((-M_PI / 2.0) + M_PI * pos) + 1.0) / 2.0;
return (sin((-G_PI / 2.0) + G_PI * pos) + 1.0) / 2.0;
} /* calc_sine_factor */
......
......@@ -172,10 +172,6 @@
/***** Magic numbers *****/
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif /* M_PI */
#define EPSILON 1e-10
......@@ -5945,7 +5941,7 @@ calc_sine_factor(double middle, double pos)
{
pos = calc_linear_factor(middle, pos);
return (sin((-M_PI / 2.0) + M_PI * pos) + 1.0) / 2.0;
return (sin((-G_PI / 2.0) + G_PI * pos) + 1.0) / 2.0;
} /* calc_sine_factor */