XCircle.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /* This file contains code for X-CHESS.
  2. Copyright (C) 1986 Free Software Foundation, Inc.
  3. This file is part of X-CHESS.
  4. X-CHESS is distributed in the hope that it will be useful,
  5. but WITHOUT ANY WARRANTY. No author or distributor
  6. accepts responsibility to anyone for the consequences of using it
  7. or for whether it serves any particular purpose or works at all,
  8. unless he says so in writing. Refer to the X-CHESS General Public
  9. License for full details.
  10. Everyone is granted permission to copy, modify and redistribute
  11. X-CHESS, but only under the conditions described in the
  12. X-CHESS General Public License. A copy of this license is
  13. supposed to have been given to you along with X-CHESS so you
  14. can know your rights and responsibilities. It should be in a
  15. file named COPYING. Among other things, the copyright notice
  16. and this notice must be preserved on all copies. */
  17. /* RCS Info: $Revision: 1.2 $ on $Date: 86/11/23 17:17:04 $
  18. * $Source: /users/faustus/xchess/RCS/XCircle.c,v $
  19. * Copyright (c) 1986 Wayne A. Christopher, U. C. Berkeley CAD Group
  20. * Permission is granted to do anything with this code except sell it
  21. * or remove this message.
  22. *
  23. */
  24. #include <stdio.h>
  25. #include <X/Xlib.h>
  26. #include <math.h>
  27. #define PI 3.1415926535897932384
  28. #define MAXVERTS 1000
  29. void
  30. XCircle(win, x, y, rad, start, end, width, height, pixel, func, planes)
  31. Window win;
  32. int x, y, rad;
  33. double start, end;
  34. int pixel;
  35. int width, height;
  36. int func, planes;
  37. {
  38. Vertex verts[MAXVERTS];
  39. double xp, yp, ang;
  40. int lx, ly, xpt, ypt, i;
  41. double gradincr = 2 / (double) rad;
  42. int bk = 0;
  43. while (end >= PI * 2)
  44. end -= PI * 2;
  45. while (start >= PI * 2)
  46. start -= PI * 2;
  47. while (end < 0)
  48. end += PI * 2;
  49. while (start < 0)
  50. start += PI * 2;
  51. if (end == start) {
  52. if (end < gradincr)
  53. end = end + PI * 2 - gradincr / 2;
  54. else
  55. end -= gradincr / 2;
  56. }
  57. for (ang = start, i = 0; i < MAXVERTS; ) {
  58. xp = x + rad * cos(ang);
  59. yp = y + rad * sin(ang);
  60. xpt = xp;
  61. ypt = yp;
  62. if (!i || (lx != xpt) || (ly != ypt)) {
  63. verts[i].x = xpt;
  64. verts[i].y = ypt;
  65. verts[i].flags = 0;
  66. i++;
  67. }
  68. lx = xpt;
  69. ly = ypt;
  70. if (bk)
  71. break;
  72. if (((ang < end) && (ang + gradincr > end)) || ((end < start)
  73. && (ang + gradincr > 2 * PI)
  74. && (ang + gradincr - 2 * PI > end))) {
  75. ang = end;
  76. bk = 1;
  77. } else if (ang == end) {
  78. break;
  79. } else {
  80. ang += gradincr;
  81. }
  82. if (ang >= PI * 2)
  83. ang -= PI * 2;
  84. }
  85. /* Now draw the thing.. */
  86. XDraw(win, verts, i, width, height, pixel, func, planes);
  87. return;
  88. }
  89. #ifdef notdef VertexCurved is screwed up
  90. void
  91. XCircle(win, x, y, rad, start, end, width, height, pixel, func, planes)
  92. Window win;
  93. int x, y, rad;
  94. double start, end;
  95. int pixel;
  96. int width, height;
  97. int func, planes;
  98. {
  99. Vertex verts[7];
  100. int i, j, sv, ev;
  101. int dp = 0;
  102. for (i = j = 0 ; i < 4; i++) {
  103. verts[j].x = x + rad * cos((double) (PI * i / 2));
  104. verts[j].y = y + rad * sin((double) (PI * i / 2));
  105. verts[j].flags = VertexCurved;
  106. if ((start >= PI * i / 2) && (start < PI * (i + 1) / 2) &&
  107. (start != end)) {
  108. j++;
  109. verts[j].x = x + rad * cos(start);
  110. verts[j].y = y + rad * sin(start);
  111. verts[j].flags = VertexCurved;
  112. sv = j;
  113. } else if ((end >= PI * i / 2) && (end < PI * (i + 1) / 2)
  114. && (start != end)) {
  115. j++;
  116. verts[j].x = x + rad * cos(end);
  117. verts[j].y = y + rad * sin(end);
  118. verts[j].flags = VertexCurved;
  119. ev = j;
  120. }
  121. j++;
  122. }
  123. verts[0].flags |= VertexStartClosed;
  124. verts[j].x = verts[0].x;
  125. verts[j].y = verts[0].y;
  126. verts[j].flags = (verts[0].flags & ~VertexStartClosed) |
  127. VertexEndClosed;
  128. for (i = 0; i < 15; i++) {
  129. if (dp)
  130. verts[i % 7].flags |= VertexDontDraw;
  131. if (i % 7 == ev)
  132. dp = 1;
  133. else if (i % 7 == sv)
  134. dp = 0;
  135. }
  136. XDraw(win, verts, j + 1, width, height, pixel, func, planes);
  137. return;
  138. }
  139. #endif notdef