mi_zerarc.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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_zerarc.c, which draws a single-pixel
  19. (i.e. Bresenham) poly-arc using a fast integer algorithm. It defines
  20. structures and macros used in the algorithm. */
  21. typedef struct
  22. {
  23. int x;
  24. int y;
  25. unsigned int mask;
  26. } miZeroArcPt;
  27. typedef struct
  28. {
  29. int x, y, k1, k3, a, b, d, dx, dy;
  30. int alpha, beta;
  31. int xorg, yorg; /* upper left corner */
  32. int xorgo, yorgo;
  33. unsigned int w, h;
  34. unsigned int initialMask;
  35. miZeroArcPt start, altstart, end, altend;
  36. int firstx, firsty;
  37. int startAngle, endAngle; /* in 1/64 degrees */
  38. } miZeroArc;
  39. /* miZeroPolyArc() draws an arc only if it satisfies the following size
  40. constraint. If it doesn't, miZeroPolyArc() hands it off to miPolyArc(),
  41. which uses a floating point algorithm. */
  42. #define MI_CAN_ZERO_ARC(arc) (((arc)->width == (arc)->height) || \
  43. (((arc)->width <= 800) && ((arc)->height <= 800)))
  44. /* used for setup only */
  45. #define MIARCSETUP(info, x, y, k1, k3, a, b, d, dx, dy) \
  46. x = info.x; \
  47. y = info.y; \
  48. k1 = info.k1; \
  49. k3 = info.k3; \
  50. a = info.a; \
  51. b = info.b; \
  52. d = info.d; \
  53. dx = info.dx; \
  54. dy = info.dy
  55. #define MIARCOCTANTSHIFT(info, x, y, dx, dy, a, b, d, k1, k3, clause) \
  56. if (a < 0) \
  57. { \
  58. if (y == (int)info.h) \
  59. { \
  60. d = -1; \
  61. a = b = k1 = 0; \
  62. } \
  63. else \
  64. { \
  65. dx = (k1 << 1) - k3; \
  66. k1 = dx - k1; \
  67. k3 = -k3; \
  68. b = b + a - (k1 >> 1); \
  69. d = b + ((-a) >> 1) - d + (k3 >> 3); \
  70. if (dx < 0) \
  71. a = -((-dx) >> 1) - a; \
  72. else \
  73. a = (dx >> 1) - a; \
  74. dx = 0; \
  75. dy = 1; \
  76. clause \
  77. } \
  78. }
  79. #define MIARCSTEP(x, y, dx, dy, a, b, d, k1, k3, move1, move2) \
  80. b -= k1; \
  81. if (d < 0) \
  82. { \
  83. x += dx; \
  84. y += dy; \
  85. a += k1; \
  86. d += b; \
  87. move1 \
  88. } \
  89. else \
  90. { \
  91. x++; \
  92. y++; \
  93. a += k3; \
  94. d -= a; \
  95. move2 \
  96. }
  97. #define MIARCCIRCLESTEP(x, y, a, b, d, k1, k3, clause) \
  98. b -= k1; \
  99. x++; \
  100. if (d < 0) \
  101. { \
  102. a += k1; \
  103. d += b; \
  104. } \
  105. else \
  106. { \
  107. y++; \
  108. a += k3; \
  109. d -= a; \
  110. clause \
  111. }