mi_fllarc.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. /* This file is part of the GNU libxmi package.
  2. Copyright (C) 1985, 1986, 1987, 1988, 1989, X Consortium. For an
  3. associated permission notice, see the accompanying file README-X.
  4. GNU enhancements Copyright (C) 1998, 1999, 2000, 2005, Free Software
  5. Foundation, Inc.
  6. The GNU libxmi package is free software. You may redistribute it
  7. and/or modify it under the terms of the GNU General Public License as
  8. published by the Free Software foundation; either version 2, or (at your
  9. option) any later version.
  10. The GNU libxmi package is distributed in the hope that it will be
  11. useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. General Public License for more details.
  14. You should have received a copy of the GNU General Public License along
  15. with the GNU plotutils package; see the file COPYING. If not, write to
  16. the Free Software Foundation, Inc., 51 Franklin St., Fifth Floor,
  17. Boston, MA 02110-1301, USA. */
  18. /* This header file is included by mi_fllarc.c (which contains code for
  19. filling a poly-arc) and mi_arc.c (which contains code for drawing a wide
  20. poly-arc). */
  21. #define FULLCIRCLE (360 * 64)
  22. /*----------------------------------------------------------------------*/
  23. /* Structures and macros used by arc-filling code in mi_arc.c */
  24. /*----------------------------------------------------------------------*/
  25. /* Structure containing variables that are updated during a scan through a
  26. filled arc. */
  27. typedef struct
  28. {
  29. int xorg, yorg;
  30. int y;
  31. int dx, dy;
  32. int e;
  33. int ym, yk, xm, xk;
  34. } miFillArc;
  35. /* A floating-point version, used for non-circular arcs one of whose
  36. dimensions (width or height) is greater than 800 pixels. Could use
  37. 64-bit integers. */
  38. typedef struct
  39. {
  40. int xorg, yorg; /* upper left corner */
  41. int y; /* vertical semi-axis */
  42. int dx, dy;
  43. double e;
  44. double ym, yk, xm, xk;
  45. } miFillArcD;
  46. /* Which to use? */
  47. #define MI_CAN_FILL_ARC(arc) (((arc)->width == (arc)->height) || \
  48. (((arc)->width <= 800) && ((arc)->height <= 800)))
  49. /* Nothing to draw? */
  50. #define MI_FILLED_ARC_IS_EMPTY(arc) (!(arc)->angle2 || \
  51. !(arc)->width || !(arc)->height || \
  52. (((arc)->width == 1) && ((arc)->height & 1)))
  53. /* used for setup only */
  54. #define MIFILLARCSETUP(info, x, y, e, xk, xm, yk, ym, dx, dy, xorg, yorg) \
  55. x = 0; \
  56. y = info.y; \
  57. e = info.e; \
  58. xk = info.xk; \
  59. xm = info.xm; \
  60. yk = info.yk; \
  61. ym = info.ym; \
  62. dx = info.dx; \
  63. dy = info.dy; \
  64. xorg = info.xorg; \
  65. yorg = info.yorg
  66. #define MIFILLARCSTEP(x, y, e, xk, xm, yk, ym, dx, slw) \
  67. e += yk; \
  68. while (e >= 0) \
  69. { \
  70. x++; \
  71. xk -= xm; \
  72. e += xk; \
  73. } \
  74. y--; \
  75. yk -= ym; \
  76. slw = (x << 1) + dx; \
  77. if ((e == xk) && (slw > 1)) \
  78. slw--
  79. #define MIFILLARCLOWER(e, xk, y, dy, slw) (((y + dy) != 0) && ((slw > 1) || (e != xk)))
  80. /* pie-slice related things */
  81. typedef struct
  82. {
  83. int x;
  84. int stepx;
  85. int deltax;
  86. int e;
  87. int dy;
  88. int dx;
  89. } miSliceEdge;
  90. typedef struct
  91. {
  92. miSliceEdge edge1, edge2;
  93. int min_top_y, max_top_y;
  94. int min_bot_y, max_bot_y;
  95. bool edge1_top, edge2_top;
  96. bool flip_top, flip_bot;
  97. } miArcSlice;
  98. #define MIARCSLICESTEP(edge) \
  99. edge.x -= edge.stepx; \
  100. edge.e -= edge.dx; \
  101. if (edge.e <= 0) \
  102. { \
  103. edge.x -= edge.deltax; \
  104. edge.e += edge.dy; \
  105. }
  106. #define MIFILLSLICEUPPER(y, slice) \
  107. ((y >= slice.min_top_y) && (y <= slice.max_top_y))
  108. #define MIFILLSLICELOWER(y, slice) \
  109. ((y >= slice.min_bot_y) && (y <= slice.max_bot_y))
  110. #define MIARCSLICEUPPER(xl,xr,slice,slw) \
  111. xl = xorg - x; \
  112. xr = xl + slw - 1; \
  113. if (slice.edge1_top && (slice.edge1.x < xr)) \
  114. xr = slice.edge1.x; \
  115. if (slice.edge2_top && (slice.edge2.x > xl)) \
  116. xl = slice.edge2.x;
  117. #define MIARCSLICELOWER(xl,xr,slice,slw) \
  118. xl = xorg - x; \
  119. xr = xl + slw - 1; \
  120. if (!slice.edge1_top && (slice.edge1.x > xl)) \
  121. xl = slice.edge1.x; \
  122. if (!slice.edge2_top && (slice.edge2.x < xr)) \
  123. xr = slice.edge2.x;
  124. /*----------------------------------------------------------------------*/
  125. /* Macros used by wide-arc-drawing code in mi_arc.c */
  126. /*----------------------------------------------------------------------*/
  127. /* used for setup only */
  128. #define MIWIDEARCSETUP(x,y,dy,slw,e,xk,xm,yk,ym) \
  129. x = 0; \
  130. y = slw >> 1; \
  131. yk = y << 3; \
  132. xm = 8; \
  133. ym = 8; \
  134. if (dy) \
  135. { \
  136. xk = 0; \
  137. if (slw & 1) \
  138. e = -1; \
  139. else \
  140. e = -(y << 2) - 2; \
  141. } \
  142. else \
  143. { \
  144. y++; \
  145. yk += 4; \
  146. xk = -4; \
  147. if (slw & 1) \
  148. e = -(y << 2) - 3; \
  149. else \
  150. e = - (y << 3); \
  151. }
  152. #define MIFILLINARCSTEP(inx, iny, ine, inxk, inxm, inyk, inym, dx, slw) \
  153. ine += inyk; \
  154. while (ine >= 0) \
  155. { \
  156. inx++; \
  157. inxk -= inxm; \
  158. ine += inxk; \
  159. } \
  160. iny--; \
  161. inyk -= inym; \
  162. slw = (inx << 1) + dx; \
  163. if ((ine == inxk) && (slw > 1)) \
  164. slw--
  165. /*----------------------------------------------------------------------*/