This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project gfxprim.git.
The branch, master has been updated via 25e3933b27e047c26e4eefd3024d51bd44fca741 (commit) from 69614535beec61f64ac9b3d5c5016896d0a27beb (commit)
Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below.
- Log ----------------------------------------------------------------- http://repo.or.cz/w/gfxprim.git/commit/25e3933b27e047c26e4eefd3024d51bd44fca...
commit 25e3933b27e047c26e4eefd3024d51bd44fca741 Author: BlueBear jiri.bluebear.dluhos@gmail.com Date: Mon Dec 12 00:34:17 2011 +0100
Simplified GP_ArcSegment() and extended it to two quadrants.
diff --git a/include/gfx/GP_Arc.h b/include/gfx/GP_Arc.h index ed4147b..2989489 100644 --- a/include/gfx/GP_Arc.h +++ b/include/gfx/GP_Arc.h @@ -30,29 +30,13 @@
#include <math.h>
-/* - * Bits for quadrant mask used with GP_ArcSegment(). - * Quadrants are ordered using the standard mathematical order, i.e. - * the top right quadrant (where x > 0 and y < 0) is the first (#0), - * then the top left, then the bottom left, and then the bottom right. - */ -#define GP_QUADRANT_0 1 -#define GP_QUADRANT_1 2 -#define GP_QUADRANT_2 4 -#define GP_QUADRANT_3 8 -#define GP_QUADRANT_MINUSMINUS GP_QUADRANT_2 -#define GP_QUADRANT_PLUSMINUS GP_QUADRANT_0 -#define GP_QUADRANT_MINUSPLUS GP_QUADRANT_1 -#define GP_QUADRANT_PLUSPLUS GP_QUADRANT_3 -#define GP_QUADRANT_ALL 15 - void GP_ArcSegment(GP_Context *context, GP_Coord xcenter, GP_Coord ycenter, - GP_Size a, GP_Size b, int quadrant_mask, + GP_Size a, GP_Size b, int direction, double start, double end, GP_Pixel pixel);
void GP_ArcSegment_Raw(GP_Context *context, GP_Coord xcenter, GP_Coord ycenter, - GP_Size a, GP_Size b, int quadrant_mask, + GP_Size a, GP_Size b, int direction, double start, double end, GP_Pixel pixel);
diff --git a/libs/gfx/GP_Arc.c b/libs/gfx/GP_Arc.c index bd28a74..094497d 100644 --- a/libs/gfx/GP_Arc.c +++ b/libs/gfx/GP_Arc.c @@ -32,20 +32,19 @@ GP_DEF_DRAW_FN_PER_BPP(GP_ArcSegment_Raw, DEF_ARCSEGMENT_FN)
void GP_ArcSegment_Raw(GP_Context *context, GP_Coord xcenter, GP_Coord ycenter, - GP_Size a, GP_Size b, int quadrant_mask, + GP_Size a, GP_Size b, int direction, double start, double end, GP_Pixel pixel) { GP_CHECK_CONTEXT(context);
GP_FN_PER_BPP_CONTEXT(GP_ArcSegment_Raw, context, context, - xcenter, ycenter, a, b, quadrant_mask, - start, end, - pixel); + xcenter, ycenter, a, b, direction, + start, end, pixel); }
void GP_ArcSegment(GP_Context *context, GP_Coord xcenter, GP_Coord ycenter, - GP_Size a, GP_Size b, int quadrant_mask, + GP_Size a, GP_Size b, int direction, double start, double end, GP_Pixel pixel) { @@ -55,7 +54,6 @@ void GP_ArcSegment(GP_Context *context, GP_Coord xcenter, GP_Coord ycenter, GP_TRANSFORM_POINT(context, xcenter, ycenter); GP_TRANSFORM_SWAP(context, a, b); - GP_ArcSegment_Raw(context, xcenter, ycenter, a, b, quadrant_mask, - start, end, - pixel); + GP_ArcSegment_Raw(context, xcenter, ycenter, a, b, direction, + start, end, pixel); } diff --git a/libs/gfx/algo/Arc.algo.h b/libs/gfx/algo/Arc.algo.h index 215fb77..fe94302 100644 --- a/libs/gfx/algo/Arc.algo.h +++ b/libs/gfx/algo/Arc.algo.h @@ -30,8 +30,13 @@ */
/* - * This macro defines a function that draws a single-quadrant - * (optionally mirrored) segment of an arc. + * This macro defines a function that draws a segment of an arc within + * two horizontal quadrants. For a larger arc, two calls are needed. + * + * The 'direction' parameter specifies which two quadrants to work in: + * if <0, the top two quadrants (y < 0) are used, if >0, the bottom two + * (y > 0) are used. + * * Arguments: * CONTEXT_T - user-defined type of drawing context (passed to PUTPIXEL) * PIXVAL_T - user-defined pixel value type (passed to PUTPIXEL) @@ -40,19 +45,18 @@ */ #define DEF_ARCSEGMENT_FN(FN_NAME, CONTEXT_T, PIXVAL_T, PUTPIXEL) void FN_NAME(CONTEXT_T context, int xcenter, int ycenter, - unsigned int a, unsigned int b, int quadrant_mask, + unsigned int a, unsigned int b, int direction, double start, double end, PIXVAL_T pixval) { /* Precompute quadratic terms. */ int a2 = a*a; int b2 = b*b; - double phi_min = GP_MIN(start, end); - double phi_max = GP_MAX(start, end); - int xmin = (int)(cos(start)*a); - int ymin = (int)(sin(start)*b); - int xmax = (int)(cos(end)*a); - int ymax = (int)(sin(end)*b); + /* Compute minimum and maximum value of X from the angles. */ + int x1 = (int)(cos(start)*a); + int x2 = (int)(cos(end)*a); + int xmin = GP_MIN(x1, x2); + int xmax = GP_MAX(x1, x2); int x, y, error; for (x = 0, error = -b2*a, y = b; y >= 0; y--) { @@ -62,42 +66,42 @@ void FN_NAME(CONTEXT_T context, int xcenter, int ycenter, error += 2*x*b2 + b2; x++; - if (quadrant_mask & GP_QUADRANT_MINUSMINUS && - (-x+1) >= xmin && (-x+1) <= xmax) { - PUTPIXEL(context, xcenter-x+1, ycenter-y, pixval); - } - if (quadrant_mask & GP_QUADRANT_PLUSMINUS && - (x-1) >= xmin && (x-1) <= xmax) { - PUTPIXEL(context, xcenter+x-1, ycenter-y, pixval); - } - if (quadrant_mask & GP_QUADRANT_MINUSPLUS && - (-x+1) >= xmin && (-x+1) <= xmax) { - PUTPIXEL(context, xcenter-x+1, ycenter+y, pixval); + if (direction < 0) { + if ((-x+1) >= xmin && (-x+1) <= xmax) { + PUTPIXEL(context, xcenter-x+1, ycenter-y, pixval); + } + if ((x-1) >= xmin && (x-1) <= xmax) { + PUTPIXEL(context, xcenter+x-1, ycenter-y, pixval); + } } - if (quadrant_mask & GP_QUADRANT_PLUSPLUS && - (x-1) >= xmin && (x-1) <= xmax) { - PUTPIXEL(context, xcenter+x-1, ycenter+y, pixval); + if (direction > 0) { + if ((-x+1) >= xmin && (-x+1) <= xmax) { + PUTPIXEL(context, xcenter-x+1, ycenter+y, pixval); + } + if ((x-1) >= xmin && (x-1) <= xmax) { + PUTPIXEL(context, xcenter+x-1 , ycenter+y, pixval); + } } } /* Calculate error(y-1) from error(y). */ error += -2*y*a2 + a2; - if (quadrant_mask & GP_QUADRANT_MINUSMINUS && - (-x+1) >= xmin && (-x+1) <= xmax) { - PUTPIXEL(context, xcenter-x+1, ycenter-y, pixval); - } - if (quadrant_mask & GP_QUADRANT_PLUSMINUS && - (x-1) >= xmin && (x-1) <= xmax) { - PUTPIXEL(context, xcenter+x-1, ycenter-y, pixval); - } - if (quadrant_mask & GP_QUADRANT_MINUSPLUS && - (-x+1) >= xmin && (-x+1) <= xmax) { - PUTPIXEL(context, xcenter-x+1, ycenter+y, pixval); + if (direction < 0) { + if ((-x+1) >= xmin && (-x+1) <= xmax) { + PUTPIXEL(context, xcenter-x+1, ycenter-y, pixval); + } + if ((x-1) >= xmin && (x-1) <= xmax) { + PUTPIXEL(context, xcenter+x-1, ycenter-y, pixval); + } } - if (quadrant_mask & GP_QUADRANT_PLUSPLUS && - (x-1) >= xmin && (x-1) <= xmax) { - PUTPIXEL(context, xcenter+x-1, ycenter+y, pixval); + if (direction > 0) { + if ((-x+1) >= xmin && (-x+1 ) <= xmax) { + PUTPIXEL(context, xcenter-x+1, ycenter+y, pixval); + } + if ((x-1) >= xmin && (x-1) <= xmax) { + PUTPIXEL(context, xcenter+x-1, ycenter+y, pixval); + } } } } diff --git a/tests/SDL/shapetest.c b/tests/SDL/shapetest.c index aebd83d..9e40d33 100644 --- a/tests/SDL/shapetest.c +++ b/tests/SDL/shapetest.c @@ -189,8 +189,8 @@ void draw_testing_ellipse(int x, int y, int xradius, int yradius)
void draw_testing_arc(int x, int y, int xradius, int yradius) { - GP_ArcSegment(&context, x, y, xradius, yradius, GP_QUADRANT_ALL, - M_PI/3, 0, red); + GP_ArcSegment(&context, x, y, xradius, yradius, -1, + M_PI - M_PI/8.0, M_PI/4.0, red); }
void draw_testing_rectangle(int x, int y, int xradius, int yradius)
-----------------------------------------------------------------------
Summary of changes: include/gfx/GP_Arc.h | 20 +---------- libs/gfx/GP_Arc.c | 14 +++----- libs/gfx/algo/Arc.algo.h | 78 ++++++++++++++++++++++++---------------------- tests/SDL/shapetest.c | 4 +- 4 files changed, 51 insertions(+), 65 deletions(-)
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos@gmail.com if you want to unsubscribe, or site admin admin@repo.or.cz if you receive no reply.