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 d05b5939892335e58f0f578928a89a05df78f2a0 (commit) via 5f476be6ba4492daf8d71abb03656c7dcefec959 (commit) from 91989ac6cef96d62797a104a2f99cca17f6151de (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/d05b5939892335e58f0f578928a89a05df78f...
commit d05b5939892335e58f0f578928a89a05df78f2a0 Merge: 5f476be 91989ac Author: BlueBear jiri.bluebear.dluhos@gmail.com Date: Sun Dec 11 20:53:46 2011 +0100
Merge branch 'master' of git://repo.or.cz/gfxprim
diff --cc include/gfx/GP_Gfx.h index 5e54131,3c36bf0..ef5a77c --- a/include/gfx/GP_Gfx.h +++ b/include/gfx/GP_Gfx.h @@@ -46,8 -46,8 +46,9 @@@ #include "GP_Triangle.h" #include "GP_Tetragon.h" #include "GP_Circle.h" + #include "GP_Arc.h" #include "GP_Ellipse.h" +#include "GP_Arc.h" #include "GP_Polygon.h" #include "GP_Symbol.h"
http://repo.or.cz/w/gfxprim.git/commit/5f476be6ba4492daf8d71abb03656c7dcefec...
commit 5f476be6ba4492daf8d71abb03656c7dcefec959 Author: BlueBear jiri.bluebear.dluhos@gmail.com Date: Sun Dec 11 20:52:11 2011 +0100
Arcs, version 2; still strange and doubtful.
diff --git a/include/gfx/GP_Arc.h b/include/gfx/GP_Arc.h index dfec46e..ed4147b 100644 --- a/include/gfx/GP_Arc.h +++ b/include/gfx/GP_Arc.h @@ -28,21 +28,32 @@
#include "core/GP_Context.h"
-#define GP_QUADRANT_MINUSMINUS 1 -#define GP_QUADRANT_PLUSMINUS 2 -#define GP_QUADRANT_MINUSPLUS 4 -#define GP_QUADRANT_PLUSPLUS 8 +#include <math.h>
-void GP_Arc(GP_Context *context, GP_Coord xcenter, GP_Coord ycenter, +/* + * 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, - int low_dx, int low_dy, - int high_dx, int high_dy, + double start, double end, GP_Pixel pixel);
-void GP_Arc_Raw(GP_Context *context, GP_Coord xcenter, GP_Coord ycenter, +void GP_ArcSegment_Raw(GP_Context *context, GP_Coord xcenter, GP_Coord ycenter, GP_Size a, GP_Size b, int quadrant_mask, - int low_dx, int low_dy, - int high_dx, int high_dy, + double start, double end, GP_Pixel pixel);
#endif /* GP_ARC_H */ diff --git a/include/gfx/GP_Gfx.h b/include/gfx/GP_Gfx.h index 5ab2f03..5e54131 100644 --- a/include/gfx/GP_Gfx.h +++ b/include/gfx/GP_Gfx.h @@ -47,6 +47,7 @@ #include "GP_Tetragon.h" #include "GP_Circle.h" #include "GP_Ellipse.h" +#include "GP_Arc.h" #include "GP_Polygon.h" #include "GP_Symbol.h"
diff --git a/libs/gfx/GP_Arc.c b/libs/gfx/GP_Arc.c index c64d94d..bd28a74 100644 --- a/libs/gfx/GP_Arc.c +++ b/libs/gfx/GP_Arc.c @@ -29,26 +29,24 @@ #include "algo/Arc.algo.h"
/* Generate drawing functions for various bit depths. */ -GP_DEF_DRAW_FN_PER_BPP(GP_Arc_Raw, DEF_ARC_FN) +GP_DEF_DRAW_FN_PER_BPP(GP_ArcSegment_Raw, DEF_ARCSEGMENT_FN)
-void GP_Arc_Raw(GP_Context *context, GP_Coord xcenter, GP_Coord ycenter, +void GP_ArcSegment_Raw(GP_Context *context, GP_Coord xcenter, GP_Coord ycenter, GP_Size a, GP_Size b, int quadrant_mask, - int low_dx, int low_dy, - int high_dx, int high_dy, + double start, double end, GP_Pixel pixel) { GP_CHECK_CONTEXT(context);
- GP_FN_PER_BPP_CONTEXT(GP_Arc_Raw, context, context, + GP_FN_PER_BPP_CONTEXT(GP_ArcSegment_Raw, context, context, xcenter, ycenter, a, b, quadrant_mask, - low_dx, low_dy, high_dx, high_dy, + start, end, pixel); }
-void GP_Arc(GP_Context *context, GP_Coord xcenter, GP_Coord ycenter, +void GP_ArcSegment(GP_Context *context, GP_Coord xcenter, GP_Coord ycenter, GP_Size a, GP_Size b, int quadrant_mask, - int low_dx, int low_dy, - int high_dx, int high_dy, + double start, double end, GP_Pixel pixel) { GP_CHECK_CONTEXT(context); @@ -57,7 +55,7 @@ void GP_Arc(GP_Context *context, GP_Coord xcenter, GP_Coord ycenter, GP_TRANSFORM_POINT(context, xcenter, ycenter); GP_TRANSFORM_SWAP(context, a, b); - GP_Arc_Raw(context, xcenter, ycenter, a, b, quadrant_mask, - low_dx, low_dy, high_dx, high_dy, + GP_ArcSegment_Raw(context, xcenter, ycenter, a, b, quadrant_mask, + start, end, pixel); } diff --git a/libs/gfx/algo/Arc.algo.h b/libs/gfx/algo/Arc.algo.h index 1681ce8..215fb77 100644 --- a/libs/gfx/algo/Arc.algo.h +++ b/libs/gfx/algo/Arc.algo.h @@ -30,23 +30,30 @@ */
/* - * This macro defines an elliptic arc drawing function. + * This macro defines a function that draws a single-quadrant + * (optionally mirrored) segment of an arc. * Arguments: * CONTEXT_T - user-defined type of drawing context (passed to PUTPIXEL) * PIXVAL_T - user-defined pixel value type (passed to PUTPIXEL) * PUTPIXEL - a pixel drawing function f(context, x, y, pixval) * FN_NAME - name of the function to be defined */ -#define DEF_ARC_FN(FN_NAME, CONTEXT_T, PIXVAL_T, PUTPIXEL) +#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, - int low_dx, int low_dy, int high_dx, int high_dy, - PIXVAL_T pixval) + 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); + int x, y, error; for (x = 0, error = -b2*a, y = b; y >= 0; y--) { while (error < 0) { @@ -55,30 +62,42 @@ void FN_NAME(CONTEXT_T context, int xcenter, int ycenter, error += 2*x*b2 + b2; x++; - if ((x*low_dy >= y*low_dx) && (x*high_dy <= y*high_dx)) { - if (quadrant_mask & GP_QUADRANT_MINUSMINUS) - PUTPIXEL(context, xcenter-x+ 1, ycenter-y, pixval); - if (quadrant_mask & GP_QUADRANT_PLUSMINUS) - PUTPIXEL(context, xcenter+x-1, ycenter-y, pixval); - if (quadrant_mask & GP_QUADRANT_MINUSPLUS) - PUTPIXEL(context, xcenter-x+1, ycenter+y, pixval); - if (quadrant_mask & GP_QUADRANT_PLUSPLUS) - PUTPIXEL(context, xcenter+x-1, ycenter+y, pixval); + 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 (quadrant_mask & GP_QUADRANT_PLUSPLUS && + (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 ((x*low_dy >= y*low_dx) && (x*high_dy <= y*high_dx)) { - if (quadrant_mask & GP_QUADRANT_MINUSMINUS) - PUTPIXEL(context, xcenter-x+1, ycenter-y, pixval); - if (quadrant_mask & GP_QUADRANT_PLUSMINUS) - PUTPIXEL(context, xcenter+x-1, ycenter-y, pixval); - if (quadrant_mask & GP_QUADRANT_MINUSPLUS) - PUTPIXEL(context, xcenter-x+1, ycenter+y, pixval); - if (quadrant_mask & GP_QUADRANT_PLUSPLUS) - PUTPIXEL(context, xcenter+x-1, ycenter+y, pixval); + 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 (quadrant_mask & GP_QUADRANT_P LUSPLUS && + (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 8435e10..aebd83d 100644 --- a/tests/SDL/shapetest.c +++ b/tests/SDL/shapetest.c @@ -72,7 +72,8 @@ static int show_axes = 1; #define SHAPE_ELLIPSE 4 #define SHAPE_RECTANGLE 5 #define SHAPE_TETRAGON 6 -#define SHAPE_LAST 6 +#define SHAPE_ARC 7 +#define SHAPE_LAST 7 static int shape = SHAPE_FIRST;
/* Variants in coordinates, if applicable */ @@ -186,6 +187,12 @@ void draw_testing_ellipse(int x, int y, int xradius, int yradius) GP_Ellipse(&context, x, y, xradius, yradius, white); }
+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); +} + void draw_testing_rectangle(int x, int y, int xradius, int yradius) { int x0 = x - xradius, y0 = y - yradius; @@ -270,6 +277,10 @@ void redraw_screen(void) draw_testing_tetragon(center_x, center_y, xradius, yradius); title = "TETRAGON"; break; + case SHAPE_ARC: + draw_testing_arc(center_x, center_y, xradius, yradius); + title = "ARC"; + break; }
GP_Text(&context, &style, 16, 16, GP_ALIGN_RIGHT|GP_VALIGN_BELOW,
-----------------------------------------------------------------------
Summary of changes: include/gfx/GP_Arc.h | 31 +++++++++++++++------- include/gfx/GP_Gfx.h | 1 + libs/gfx/GP_Arc.c | 20 ++++++-------- libs/gfx/algo/Arc.algo.h | 63 ++++++++++++++++++++++++++++++---------------- tests/SDL/shapetest.c | 13 ++++++++- 5 files changed, 84 insertions(+), 44 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.