Switched from using M_PI to a named constant uiPi.

This commit is contained in:
Pietro Gagliardi 2016-05-22 12:00:44 -04:00
parent 1d8ea79e45
commit 5a4b6aa6f0
14 changed files with 66 additions and 77 deletions

View File

@ -16,6 +16,7 @@ This README is being written.<br>
* **22 May 2016**
** Removed `uiControlVerifyDestroy()`; that is now part of `uiFreeControl()` itself.
** Added `uiPi`, a constant for π. This is provided for C and C++ programmers, where there is no standard named constant for π; bindings authors shouldn't need to worry about this.
## Runtime Requirements

View File

@ -19,14 +19,6 @@
- provide a way to get the currently selected uiTab page? set?
- add uiPi for portability; compare against:
- M_PI on all systems with different requirements
- _GNU_SOURCE on unix
- _USE_MATH_DEFINES on windows
- G_PI on GLib
- XM_PI from DirectX
- Go math.Pi
- make it so that the windows cntrols only register a resize if their new minimum size is larger than their current size to easen the effect of flicker
- it won't remove that outright, but it'll help

View File

@ -60,8 +60,8 @@ void uiDrawPathArcTo(uiDrawPath *p, double xCenter, double yCenter, double radiu
// TODO likewise
if (p->ended)
implbug("attempt to add arc to ended path in uiDrawPathArcTo()");
if (sweep > 2 * M_PI)
sweep = 2 * M_PI;
if (sweep > 2 * uiPi)
sweep = 2 * uiPi;
cw = false;
if (negative)
cw = true;

View File

@ -87,16 +87,16 @@ static void drawOriginal(uiAreaDrawParams *p)
uiDrawPathArcTo(path,
400, 100,
50,
30. * (M_PI / 180.),
300. * (M_PI / 180.),
30. * (uiPi / 180.),
300. * (uiPi / 180.),
0);
// the sweep test below doubles as a clockwise test so a checkbox isn't needed anymore
uiDrawPathLineTo(path, 400, 100);
uiDrawPathNewFigureWithArc(path,
510, 100,
50,
30. * (M_PI / 180.),
300. * (M_PI / 180.),
30. * (uiPi / 180.),
300. * (uiPi / 180.),
0);
uiDrawPathCloseFigure(path);
// and now with 330 to make sure sweeps work properly
@ -104,15 +104,15 @@ static void drawOriginal(uiAreaDrawParams *p)
uiDrawPathArcTo(path,
400, 210,
50,
30. * (M_PI / 180.),
330. * (M_PI / 180.),
30. * (uiPi / 180.),
330. * (uiPi / 180.),
0);
uiDrawPathLineTo(path, 400, 210);
uiDrawPathNewFigureWithArc(path,
510, 210,
50,
30. * (M_PI / 180.),
330. * (M_PI / 180.),
30. * (uiPi / 180.),
330. * (uiPi / 180.),
0);
uiDrawPathCloseFigure(path);
uiDrawPathEnd(path);
@ -160,7 +160,7 @@ static void drawArcs(uiAreaDrawParams *p)
path = uiDrawNewPath(uiDrawFillModeWinding);
add = (2.0 * M_PI) / 12;
add = (2.0 * uiPi) / 12;
x = start + rad;
y = start + rad;
@ -196,7 +196,7 @@ static void drawArcs(uiAreaDrawParams *p)
uiDrawPathNewFigureWithArc(path,
x, y,
rad,
(M_PI / 4), angle,
(uiPi / 4), angle,
0);
angle += add;
x += 2 * rad + step;
@ -210,7 +210,7 @@ static void drawArcs(uiAreaDrawParams *p)
uiDrawPathArcTo(path,
x, y,
rad,
(M_PI / 4), angle,
(uiPi / 4), angle,
0);
angle += add;
x += 2 * rad + step;
@ -223,7 +223,7 @@ static void drawArcs(uiAreaDrawParams *p)
uiDrawPathNewFigureWithArc(path,
x, y,
rad,
M_PI + (M_PI / 5), angle,
uiPi + (uiPi / 5), angle,
0);
angle += add;
x += 2 * rad + step;
@ -237,7 +237,7 @@ static void drawArcs(uiAreaDrawParams *p)
uiDrawPathArcTo(path,
x, y,
rad,
M_PI + (M_PI / 5), angle,
uiPi + (uiPi / 5), angle,
0);
angle += add;
x += 2 * rad + step;
@ -519,7 +519,7 @@ static void drawD2DRadialBrush(uiAreaDrawParams *p)
75, 75,
75,
0,
2 * M_PI,
2 * uiPi,
0);
uiDrawPathEnd(path);
@ -596,7 +596,7 @@ static void drawD2DPathGeometries(uiAreaDrawParams *p)
uiDrawPathNewFigureWithArc(sun,
(440.0 - 270.0) / 2 + 270.0, 255,
85,
M_PI, M_PI,
uiPi, uiPi,
0);
uiDrawPathCloseFigure(sun);
uiDrawPathEnd(sun);
@ -730,22 +730,22 @@ static void drawD2DGeometryGroup(uiAreaDrawParams *p)
uiDrawPathNewFigureWithArc(alternate,
105, 105,
25,
0, 2 * M_PI,
0, 2 * uiPi,
0);
uiDrawPathNewFigureWithArc(alternate,
105, 105,
50,
0, 2 * M_PI,
0, 2 * uiPi,
0);
uiDrawPathNewFigureWithArc(alternate,
105, 105,
75,
0, 2 * M_PI,
0, 2 * uiPi,
0);
uiDrawPathNewFigureWithArc(alternate,
105, 105,
100,
0, 2 * M_PI,
0, 2 * uiPi,
0);
uiDrawPathEnd(alternate);
@ -753,22 +753,22 @@ static void drawD2DGeometryGroup(uiAreaDrawParams *p)
uiDrawPathNewFigureWithArc(winding,
105, 105,
25,
0, 2 * M_PI,
0, 2 * uiPi,
0);
uiDrawPathNewFigureWithArc(winding,
105, 105,
50,
0, 2 * M_PI,
0, 2 * uiPi,
0);
uiDrawPathNewFigureWithArc(winding,
105, 105,
75,
0, 2 * M_PI,
0, 2 * uiPi,
0);
uiDrawPathNewFigureWithArc(winding,
105, 105,
100,
0, 2 * M_PI,
0, 2 * uiPi,
0);
uiDrawPathEnd(winding);
@ -850,7 +850,7 @@ static void drawD2DRotate(uiAreaDrawParams *p)
uiDrawMatrixSetIdentity(&m);
uiDrawMatrixRotate(&m,
468.0, 331.5,
45.0 * (M_PI / 180));
45.0 * (uiPi / 180));
uiDrawTransform(p->Context, &m);
uiDrawFill(p->Context, path, &fill);
@ -868,7 +868,7 @@ static void drawD2DRotate(uiAreaDrawParams *p)
uiDrawMatrixSetIdentity(&m);
uiDrawMatrixRotate(&m,
438.0, 301.5,
45.0 * (M_PI / 180));
45.0 * (uiPi / 180));
uiDrawTransform(p->Context, &m);
uiDrawFill(p->Context, path, &fill);
@ -993,7 +993,7 @@ void drawD2DSkew(uiAreaDrawParams *p)
uiDrawMatrixSetIdentity(&m);
uiDrawMatrixSkew(&m,
126.0, 301.5,
45.0 * (M_PI / 180), 0);
45.0 * (uiPi / 180), 0);
uiDrawTransform(p->Context, &m);
uiDrawFill(p->Context, path, &fill);
@ -1011,7 +1011,7 @@ void drawD2DSkew(uiAreaDrawParams *p)
uiDrawMatrixSetIdentity(&m);
uiDrawMatrixSkew(&m,
0, 0,
45.0 * (M_PI / 180), 0);
45.0 * (uiPi / 180), 0);
uiDrawTransform(p->Context, &m);
uiDrawFill(p->Context, path, &fill);
@ -1111,7 +1111,7 @@ static void drawD2DMultiTransforms(uiAreaDrawParams *p)
uiDrawMatrixSetIdentity(&mrotate);
uiDrawMatrixRotate(&mrotate,
330.0, 70.0,
45.0 * (M_PI / 180));
45.0 * (uiPi / 180));
// save for when we do the opposite one
uiDrawSave(p->Context);
@ -1136,7 +1136,7 @@ static void drawD2DMultiTransforms(uiAreaDrawParams *p)
uiDrawMatrixSetIdentity(&mrotate);
uiDrawMatrixRotate(&mrotate,
70.0, 70.0,
45.0 * (M_PI / 180));
45.0 * (uiPi / 180));
uiDrawStroke(p->Context, path, &original, &originalsp);
@ -1256,8 +1256,8 @@ static void drawCSArc(uiAreaDrawParams *p)
double xc = 128.0;
double yc = 128.0;
double radius = 100.0;
double angle1 = 45.0 * (M_PI / 180.0);
double angle2 = 180.0 * (M_PI / 180.0);
double angle1 = 45.0 * (uiPi / 180.0);
double angle2 = 180.0 * (uiPi / 180.0);
uiDrawBrush source;
uiDrawStrokeParams sp;
uiDrawPath *path;
@ -1289,7 +1289,7 @@ static void drawCSArc(uiAreaDrawParams *p)
uiDrawPathNewFigureWithArc(path,
xc, yc,
10.0,
0, 2 * M_PI,
0, 2 * uiPi,
0);
uiDrawPathEnd(path);
uiDrawFill(p->Context, path, &source);
@ -1319,8 +1319,8 @@ static void drawCSArcNegative(uiAreaDrawParams *p)
double xc = 128.0;
double yc = 128.0;
double radius = 100.0;
double angle1 = 45.0 * (M_PI / 180.0);
double angle2 = 180.0 * (M_PI / 180.0);
double angle1 = 45.0 * (uiPi / 180.0);
double angle2 = 180.0 * (uiPi / 180.0);
uiDrawBrush source;
uiDrawStrokeParams sp;
uiDrawPath *path;
@ -1352,7 +1352,7 @@ static void drawCSArcNegative(uiAreaDrawParams *p)
uiDrawPathNewFigureWithArc(path,
xc, yc,
10.0,
0, 2 * M_PI,
0, 2 * uiPi,
0);
uiDrawPathEnd(path);
uiDrawFill(p->Context, path, &source);
@ -1396,7 +1396,7 @@ static void drawCSClip(uiAreaDrawParams *p)
uiDrawPathNewFigureWithArc(path,
128.0, 128.0,
76.8,
0, 2 * M_PI,
0, 2 * uiPi,
0);
uiDrawPathEnd(path);
uiDrawClip(p->Context, path);
@ -1639,12 +1639,12 @@ static void drawCSFillStyle(uiAreaDrawParams *p)
uiDrawPathNewFigureWithArc(path,
64, 64,
40,
0, 2*M_PI,
0, 2*uiPi,
0);
uiDrawPathNewFigureWithArc(path,
192, 64,
40,
0, -2*M_PI,
0, -2*uiPi,
1);
uiDrawPathEnd(path);
@ -1663,12 +1663,12 @@ static void drawCSFillStyle(uiAreaDrawParams *p)
uiDrawPathNewFigureWithArc(path,
64, 64,
40,
0, 2*M_PI,
0, 2*uiPi,
0);
uiDrawPathNewFigureWithArc(path,
192, 64,
40,
0, -2*M_PI,
0, -2*uiPi,
1);
uiDrawPathEnd(path);
@ -1728,7 +1728,7 @@ static void drawCSRoundRect(uiAreaDrawParams *p)
corner_radius = height / 10.0; /* and corner curvature radius */
double radius = corner_radius / aspect;
double degrees = M_PI / 180.0;
double degrees = uiPi / 180.0;
uiDrawBrush source;
uiDrawStrokeParams sp;
@ -1748,25 +1748,25 @@ static void drawCSRoundRect(uiAreaDrawParams *p)
uiDrawPathNewFigureWithArc(path,
x + width - radius, y + radius,
radius,
-90 * degrees, M_PI / 2,
-90 * degrees, uiPi / 2,
0);
// bottom right corner
uiDrawPathArcTo(path,
x + width - radius, y + height - radius,
radius,
0 * degrees, M_PI / 2,
0 * degrees, uiPi / 2,
0);
// bottom left corner
uiDrawPathArcTo(path,
x + radius, y + height - radius,
radius,
90 * degrees, M_PI / 2,
90 * degrees, uiPi / 2,
0);
// top left corner
uiDrawPathArcTo(path,
x + radius, y + radius,
radius,
180 * degrees, M_PI / 2,
180 * degrees, uiPi / 2,
0);
uiDrawPathCloseFigure(path);
uiDrawPathEnd(path);

View File

@ -41,7 +41,7 @@ static void handlerDraw(uiAreaHandler *a, uiArea *area, uiAreaDrawParams *p)
startText = uiEntryText(startAngle);
sweepText = uiEntryText(sweep);
factor = M_PI / 180;
factor = uiPi / 180;
if (uiCheckboxChecked(radians))
factor = 1;

View File

@ -65,7 +65,7 @@ static void handlerDraw(uiAreaHandler *a, uiArea *area, uiAreaDrawParams *dp)
uiDrawPathNewFigureWithArc(path,
areaSize / 2, areaSize / 2,
circleRadius,
0, 2 * M_PI,
0, 2 * uiPi,
0);
uiDrawPathEnd(path);
stops[0].Pos =0.0;

View File

@ -1,7 +1,4 @@
// 22 april 2015
// TODO
#define _GNU_SOURCE
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>

4
ui.h
View File

@ -21,6 +21,10 @@ extern "C" {
// This has the advantage of being ABI-able should we ever need an ABI...
#define _UI_ENUM(s) typedef unsigned int s; enum
// This constant is provided because M_PI is nonstandard.
// This comes from Go's math.Pi, which in turn comes from http://oeis.org/A000796.
#define uiPi 3.14159265358979323846264338327950288419716939937510582097494459
typedef struct uiInitOptions uiInitOptions;
struct uiInitOptions {

View File

@ -61,8 +61,8 @@ void uiDrawPathNewFigureWithArc(uiDrawPath *p, double xCenter, double yCenter, d
{
struct piece piece;
if (sweep > 2 * M_PI)
sweep = 2 * M_PI;
if (sweep > 2 * uiPi)
sweep = 2 * uiPi;
piece.type = newFigureArc;
piece.d[0] = xCenter;
piece.d[1] = yCenter;
@ -87,8 +87,8 @@ void uiDrawPathArcTo(uiDrawPath *p, double xCenter, double yCenter, double radiu
{
struct piece piece;
if (sweep > 2 * M_PI)
sweep = 2 * M_PI;
if (sweep > 2 * uiPi)
sweep = 2 * uiPi;
piece.type = arcTo;
piece.d[0] = xCenter;
piece.d[1] = yCenter;

View File

@ -3,8 +3,6 @@
#define GLIB_VERSION_MAX_ALLOWED GLIB_VERSION_2_32
#define GDK_VERSION_MIN_REQUIRED GDK_VERSION_3_4
#define GDK_VERSION_MAX_ALLOWED GDK_VERSION_3_4
// TODO make this unnecessary
#define _GNU_SOURCE
#include <gtk/gtk.h>
#include <math.h>
#include <dlfcn.h> // see drawtext.c

View File

@ -43,7 +43,7 @@ void uiDrawMatrixScale(uiDrawMatrix *m, double xCenter, double yCenter, double x
d2m(&dm, m);
}
#define r2d(x) (x * (180.0 / M_PI))
#define r2d(x) (x * (180.0 / uiPi))
void uiDrawMatrixRotate(uiDrawMatrix *m, double x, double y, double amount)
{

View File

@ -96,20 +96,20 @@ static void drawArc(uiDrawPath *p, struct arc *a, void (*startFunction)(uiDrawPa
fullCircle = FALSE;
// use the absolute value to tackle both ≥2π and ≤-2π at the same time
absSweep = fabs(a->sweep);
if (absSweep > (2 * M_PI)) // this part is easy
if (absSweep > (2 * uiPi)) // this part is easy
fullCircle = TRUE;
else {
double aerDiff;
aerDiff = fabs(absSweep - (2 * M_PI));
aerDiff = fabs(absSweep - (2 * uiPi));
// if we got here then we know a->sweep is larger (or the same!)
fullCircle = aerDiff <= absSweep * aerMax;
}
// TODO make sure this works right for the negative direction
if (fullCircle) {
a->sweep = M_PI;
a->sweep = uiPi;
drawArc(p, a, startFunction);
a->startAngle += M_PI;
a->startAngle += uiPi;
drawArc(p, a, NULL);
return;
}
@ -144,13 +144,13 @@ static void drawArc(uiDrawPath *p, struct arc *a, void (*startFunction)(uiDrawPa
as.sweepDirection = D2D1_SWEEP_DIRECTION_CLOCKWISE;
// TODO explain the outer if
if (!a->negative)
if (a->sweep > M_PI)
if (a->sweep > uiPi)
as.arcSize = D2D1_ARC_SIZE_LARGE;
else
as.arcSize = D2D1_ARC_SIZE_SMALL;
else
// TODO especially this part
if (a->sweep > M_PI)
if (a->sweep > uiPi)
as.arcSize = D2D1_ARC_SIZE_SMALL;
else
as.arcSize = D2D1_ARC_SIZE_LARGE;

View File

@ -8,9 +8,6 @@
// TODO get rid of this
#define INITGUID
// TODO see if we can remove this
#define _USE_MATH_DEFINES
// for the manifest
#define ISOLATION_AWARE_ENABLED 1