demos: py_simple: Remove *_AA.py
[gfxprim.git] / libs / gfx / algo / PartialEllipse.algo.h
blob6bf4385e7b25c885ac5a63d66123495f21180c45
1 /*****************************************************************************
2 * This file is part of gfxprim library. *
3 * *
4 * Gfxprim is free software; you can redistribute it and/or *
5 * modify it under the terms of the GNU Lesser General Public *
6 * License as published by the Free Software Foundation; either *
7 * version 2.1 of the License, or (at your option) any later version. *
8 * *
9 * Gfxprim is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
12 * Lesser General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU Lesser General Public *
15 * License along with gfxprim; if not, write to the Free Software *
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
17 * Boston, MA 02110-1301 USA *
18 * *
19 * Copyright (C) 2009-2010 Jiri "BlueBear" Dluhos *
20 * <jiri.bluebear.dluhos@gmail.com> *
21 * *
22 * Copyright (C) 2009-2012 Cyril Hrubis <metan@ucw.cz> *
23 * *
24 *****************************************************************************/
26 #include "GP_AngleUtils.h"
28 #include <math.h>
31 * This macro defines a partial ellipse drawing function.
32 * Arguments:
33 * PIXMAP_T - user-defined type of drawing pixmap (passed to PUTPIXEL)
34 * PIXVAL_T - user-defined pixel value type (passed to PUTPIXEL)
35 * PUTPIXEL - a pixel drawing function f(pixmap, x, y, pixval)
36 * FN_NAME - name of the function to be defined
38 #define DEF_PARTIAL_ELLIPSE_FN(FN_NAME, PIXMAP_T, PIXVAL_T, PUTPIXEL) \
39 static void FN_NAME(PIXMAP_T pixmap, int xcenter, int ycenter, int a, int b, \
40 int start, int end, PIXVAL_T pixval) \
41 { \
42 double startAngle = GP_NormalizeAngle(2*M_PI*(start / 360000.0)); \
43 double endAngle = GP_NormalizeAngle(2*M_PI*(end / 360000.0)); \
45 int x; \
46 for (x = -a; x <= a; x++) { \
47 double angle = acos(((double) x) / a); \
48 double y = floor(b*sin(angle)); \
49 if (GP_AngleInRange(angle, startAngle, endAngle)) { \
50 PUTPIXEL(pixmap, xcenter+x, ycenter-y, pixval); \
51 } \
52 if (GP_AngleInRange(2*M_PI - angle, startAngle, endAngle)) { \
53 PUTPIXEL(pixmap, xcenter+x, ycenter+y, pixval); \
54 } \
55 } \
57 int y; \
58 for (y = -b; y <= b; y++) { \
59 double angle = asin(((double) y) / b); \
60 double x = floor(a*cos(angle)); \
61 if (GP_AngleInRange(angle, startAngle, endAngle)) { \
62 PUTPIXEL(pixmap, xcenter+x, ycenter-y, pixval); \
63 } \
64 if (GP_AngleInRange(M_PI - angle, startAngle, endAngle)) { \
65 PUTPIXEL(pixmap, xcenter-x, ycenter-y, pixval); \
66 } \
67 } \