From 5a4b6aa6f00119a485e5e2f336683a2860424e32 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sun, 22 May 2016 12:00:44 -0400 Subject: [PATCH] Switched from using M_PI to a named constant uiPi. --- README.md | 1 + TODO.md | 8 ---- darwin/draw.m | 4 +- test/drawtests.c | 90 +++++++++++++++++++++--------------------- test/page7a.c | 2 +- test/page7c.c | 2 +- test/test.h | 3 -- ui.h | 4 ++ unix/GNUosspecific.mk | 2 +- unix/drawpath.c | 8 ++-- unix/uipriv_unix.h | 2 - windows/drawmatrix.cpp | 2 +- windows/drawpath.cpp | 12 +++--- windows/winapi.hpp | 3 -- 14 files changed, 66 insertions(+), 77 deletions(-) diff --git a/README.md b/README.md index 374eae61..b7a6b562 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,7 @@ This README is being written.
* **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 diff --git a/TODO.md b/TODO.md index 8f9fdc1d..9b599845 100644 --- a/TODO.md +++ b/TODO.md @@ -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 diff --git a/darwin/draw.m b/darwin/draw.m index 40c47a99..0552c07d 100644 --- a/darwin/draw.m +++ b/darwin/draw.m @@ -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; diff --git a/test/drawtests.c b/test/drawtests.c index ab1ca8bc..d821d495 100644 --- a/test/drawtests.c +++ b/test/drawtests.c @@ -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); diff --git a/test/page7a.c b/test/page7a.c index ff0db201..72e03216 100644 --- a/test/page7a.c +++ b/test/page7a.c @@ -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; diff --git a/test/page7c.c b/test/page7c.c index 1ebddad1..ac6a316c 100644 --- a/test/page7c.c +++ b/test/page7c.c @@ -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; diff --git a/test/test.h b/test/test.h index be37440e..1866b30c 100644 --- a/test/test.h +++ b/test/test.h @@ -1,7 +1,4 @@ // 22 april 2015 -// TODO -#define _GNU_SOURCE -#define _USE_MATH_DEFINES #include #include #include diff --git a/ui.h b/ui.h index 2302b7b4..b4a97023 100644 --- a/ui.h +++ b/ui.h @@ -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 { diff --git a/unix/GNUosspecific.mk b/unix/GNUosspecific.mk index b5fa75e5..7d8cb726 100644 --- a/unix/GNUosspecific.mk +++ b/unix/GNUosspecific.mk @@ -10,4 +10,4 @@ USESSONAME = 1 SOVERSION = $(SOVERSION0) SONAMEEXT = $(LIBSUFFIX).$(SOVERSION) # this is not gcc-global because OS X uses a different filename format -SONAMEFLAG = -Wl,-soname, \ No newline at end of file +SONAMEFLAG = -Wl,-soname, diff --git a/unix/drawpath.c b/unix/drawpath.c index acfcc953..a0165fb8 100644 --- a/unix/drawpath.c +++ b/unix/drawpath.c @@ -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; diff --git a/unix/uipriv_unix.h b/unix/uipriv_unix.h index 6a260830..67e48a85 100644 --- a/unix/uipriv_unix.h +++ b/unix/uipriv_unix.h @@ -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 #include #include // see drawtext.c diff --git a/windows/drawmatrix.cpp b/windows/drawmatrix.cpp index 807b41ad..090972a5 100644 --- a/windows/drawmatrix.cpp +++ b/windows/drawmatrix.cpp @@ -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) { diff --git a/windows/drawpath.cpp b/windows/drawpath.cpp index be02b826..49855be6 100644 --- a/windows/drawpath.cpp +++ b/windows/drawpath.cpp @@ -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; diff --git a/windows/winapi.hpp b/windows/winapi.hpp index 5763f297..ed30b782 100644 --- a/windows/winapi.hpp +++ b/windows/winapi.hpp @@ -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