File: mi_zerarc.h

package info (click to toggle)
plotutils 2.6-15
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 14,040 kB
  • sloc: ansic: 68,670; sh: 20,086; cpp: 12,382; yacc: 2,588; makefile: 838; lex: 137
file content (124 lines) | stat: -rw-r--r-- 3,067 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/* This file is part of the GNU libxmi package.  

   Copyright (C) 1985, 1986, 1987, 1988, 1989, X Consortium.  For an
   associated permission notice, see the accompanying file README-X.
   
   GNU enhancements Copyright (C) 1998, 1999, 2000, 2005, Free Software
   Foundation, Inc.

   The GNU libxmi package is free software.  You may redistribute it
   and/or modify it under the terms of the GNU General Public License as
   published by the Free Software foundation; either version 2, or (at your
   option) any later version.

   The GNU libxmi package is distributed in the hope that it will be
   useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   General Public License for more details.

   You should have received a copy of the GNU General Public License along
   with the GNU plotutils package; see the file COPYING.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin St., Fifth Floor,
   Boston, MA 02110-1301, USA. */

/* This header file is included by mi_zerarc.c, which draws a single-pixel
   (i.e. Bresenham) poly-arc using a fast integer algorithm.  It defines
   structures and macros used in the algorithm. */

typedef struct 
{
  int x;
  int y;
  unsigned int mask;
} miZeroArcPt;

typedef struct 
{
  int x, y, k1, k3, a, b, d, dx, dy;
  int alpha, beta;
  int xorg, yorg;		/* upper left corner */
  int xorgo, yorgo;
  unsigned int w, h;
  unsigned int initialMask;
  miZeroArcPt start, altstart, end, altend;
  int firstx, firsty;
  int startAngle, endAngle;	/* in 1/64 degrees */
} miZeroArc;

/* miZeroPolyArc() draws an arc only if it satisfies the following size
   constraint.  If it doesn't, miZeroPolyArc() hands it off to miPolyArc(),
   which uses a floating point algorithm. */
#define MI_CAN_ZERO_ARC(arc) (((arc)->width == (arc)->height) || \
			     (((arc)->width <= 800) && ((arc)->height <= 800)))

/* used for setup only */
#define MIARCSETUP(info, x, y, k1, k3, a, b, d, dx, dy) \
x = info.x; \
y = info.y; \
k1 = info.k1; \
k3 = info.k3; \
a = info.a; \
b = info.b; \
d = info.d; \
dx = info.dx; \
dy = info.dy

#define MIARCOCTANTSHIFT(info, x, y, dx, dy, a, b, d, k1, k3, clause) \
if (a < 0) \
{ \
    if (y == (int)info.h) \
      { \
	d = -1; \
	a = b = k1 = 0; \
      } \
  else \
    { \
      dx = (k1 << 1) - k3; \
      k1 = dx - k1; \
      k3 = -k3; \
      b = b + a - (k1 >> 1); \
      d = b + ((-a) >> 1) - d + (k3 >> 3); \
      if (dx < 0) \
	  a = -((-dx) >> 1) - a; \
      else \
	  a = (dx >> 1) - a; \
      dx = 0; \
      dy = 1; \
      clause \
    } \
}

#define MIARCSTEP(x, y, dx, dy, a, b, d, k1, k3, move1, move2) \
b -= k1; \
if (d < 0) \
{ \
    x += dx; \
    y += dy; \
    a += k1; \
    d += b; \
    move1 \
} \
else \
{ \
    x++; \
    y++; \
    a += k3; \
    d -= a; \
    move2 \
}

#define MIARCCIRCLESTEP(x, y, a, b, d, k1, k3, clause) \
b -= k1; \
x++; \
if (d < 0) \
{ \
  a += k1; \
  d += b; \
} \
else \
{ \
  y++; \
  a += k3; \
  d -= a; \
  clause \
}