mi_widelin.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. /* Author: Keith Packard, MIT X Consortium */
  19. /* definitions related to filling of convex polygons, used in code for
  20. * drawing of wide lines (with caps/joins) via span merging
  21. */
  22. /* Structure used for moving along left and right edges of polygons via the
  23. midpoint line algorithm. The algorithm: increment y, (height-1) times.
  24. At each step, increment e by dx. If this makes e positive, also
  25. subtract dy. Corresponding change to x: add stepx to x, and (if dy
  26. needed to be subtracted from e), also add signdx to x. */
  27. typedef struct
  28. {
  29. unsigned int height; /* number of scanlines in edge */
  30. int x; /* starting x coordinate of edge */
  31. int stepx; /* fixed integer dx (usually 0) */
  32. int signdx; /* additional (optional) integer dx */
  33. int e; /* initial value for decision variable */
  34. int dy; /* dy/dx is (rational) slope of edge */
  35. int dx;
  36. } PolyEdge;
  37. /*
  38. * types for general polygon routines
  39. */
  40. typedef struct
  41. {
  42. double x, y;
  43. } PolyVertex;
  44. typedef struct
  45. {
  46. int dx, dy; /* dy/dx is (rational) slope */
  47. double k; /* x0 * dy - y0 * dx */
  48. } PolySlope;
  49. /*
  50. * Line face, used in constructing additional cap/join polygons
  51. */
  52. typedef struct
  53. {
  54. double xa, ya; /* endpoint of line face (rel. to (x,y)) */
  55. int dx, dy; /* (dx,dy) points into line (a convention) */
  56. int x, y; /* line end, i.e. center of face */
  57. double k; /* xa * dy - ya * dx */
  58. } LineFace;
  59. /* Macros for stepping around a convex polygon (i.e. downward from top,
  60. along the sequence of `left edges' and `right edges') */
  61. /* load fields from next left edge in list */
  62. #define MIPOLYRELOADLEFT if (!left_height && left_count) { \
  63. left_height = left->height; \
  64. left_x = left->x; \
  65. left_stepx = left->stepx; \
  66. left_signdx = left->signdx; \
  67. left_e = left->e; \
  68. left_dy = left->dy; \
  69. left_dx = left->dx; \
  70. --left_count; \
  71. ++left; \
  72. }
  73. /* load fields from next right edge in list */
  74. #define MIPOLYRELOADRIGHT if (!right_height && right_count) { \
  75. right_height = right->height; \
  76. right_x = right->x; \
  77. right_stepx = right->stepx; \
  78. right_signdx = right->signdx; \
  79. right_e = right->e; \
  80. right_dy = right->dy; \
  81. right_dx = right->dx; \
  82. --right_count; \
  83. ++right; \
  84. }
  85. /* Update steps in edge traversal via midpoint line algorithm */
  86. /* step along left edge (modify x appropriately as y is incremented by 1) */
  87. #define MIPOLYSTEPLEFT left_x += left_stepx; \
  88. left_e += left_dx; \
  89. if (left_e > 0) \
  90. { \
  91. left_x += left_signdx; \
  92. left_e -= left_dy; \
  93. }
  94. /* step along right edge (modify x appropriately as y is incremented by 1) */
  95. #define MIPOLYSTEPRIGHT right_x += right_stepx; \
  96. right_e += right_dx; \
  97. if (right_e > 0) \
  98. { \
  99. right_x += right_signdx; \
  100. right_e -= right_dy; \
  101. }