Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

277 lines
5.8 KiB

  1. //
  2. // Copyright (c) 1997-1999 Microsoft Corporation.
  3. //
  4. #include "stdafx.h"
  5. #include "vdata.h"
  6. #define UNDERFP 0
  7. #define NMAX 129
  8. int MkPoly( int inlst, int outLst);
  9. static int DDACon(struct vecdata *s,struct vecdata *cp,struct vecdata *e,int lstHdl);
  10. static int fsqrt(int n);
  11. /***********************************************************************
  12. * Make Poly line
  13. */
  14. /* */ int
  15. /* */ MkPoly(
  16. /* */ int inLst,
  17. /* */ int outLst)
  18. /*
  19. * returns : 0, -1
  20. ***********************************************************************/
  21. {
  22. struct VHEAD *vhd;
  23. int pcnt,
  24. sts;
  25. struct VDATA *vp;
  26. if ( (sts = VDGetHead( inLst, &vhd))!=0)
  27. goto RET;
  28. VDNew( outLst);
  29. while ( vhd->next != NIL) {
  30. vp = vhd->headp;
  31. pcnt = vhd->nPoints;
  32. while ( pcnt >0) {
  33. if ( vp->next->vd.atr &1) {
  34. sts = DDACon( &vp->vd, &vp->next->vd,
  35. &vp->next->next->vd, outLst);
  36. if ( sts)
  37. goto RET;
  38. vp = vp->next;
  39. pcnt--;
  40. if ( pcnt>0) {
  41. vp = vp->next;
  42. pcnt--;
  43. }
  44. }
  45. else {
  46. if ( (sts = VDSetData( outLst, &vp->vd))<0)
  47. goto RET;
  48. vp = vp->next;
  49. pcnt--;
  50. }
  51. }
  52. vhd = vhd->next;
  53. if ( (sts = VDClose( outLst))<0)
  54. goto RET;
  55. }
  56. RET:
  57. return( sts);
  58. }
  59. static int lowsqr[NMAX] = {
  60. 1, 2, 2, 3, 3,
  61. 4, 4, 4, 4, 5,
  62. 5, 5, 5, 6, 6,
  63. 6, 6, 6, 6, 7,
  64. 7, 7, 7, 7, 7,
  65. 8, 8, 8, 8, 8,
  66. 8, 8, 8, 9, 9,
  67. 9, 9, 9, 9, 9,
  68. 9, 10, 10, 10, 10,
  69. 10, 10, 10, 10, 10,
  70. 10, 11, 11, 11, 11,
  71. 11, 11, 11, 11, 11,
  72. 11, 12, 12, 12, 12,
  73. 12, 12, 12, 12, 12,
  74. 12, 12, 12, 13, 13,
  75. 13, 13, 13, 13, 13,
  76. 13, 13, 13, 13, 13,
  77. 14, 14, 14, 14, 14,
  78. 14, 14, 14, 14, 14,
  79. 14, 14, 14, 14, 15,
  80. 15, 15, 15, 15, 15,
  81. 15, 15, 15, 15, 15,
  82. 15, 15, 15, 16, 16,
  83. 16, 16, 16, 16, 16,
  84. 16, 16, 16, 16, 16,
  85. 16, 16, 16, 16,
  86. };
  87. static int sqrtbl[NMAX] = {
  88. 1, 4, 9, 16, 25,
  89. 36, 49, 64, 81, 100,
  90. 121, 144, 169, 196, 225,
  91. 256, 289, 324, 361, 400,
  92. 441, 484, 529, 576, 625,
  93. 676, 729, 784, 841, 900,
  94. 961, 1024, 1089, 1156, 1225,
  95. 1296, 1369, 1444, 1521, 1600,
  96. 1681, 1764, 1849, 1936, 2025,
  97. 2116, 2209, 2304, 2401, 2500,
  98. 2601, 2704, 2809, 2916, 3025,
  99. 3136, 3249, 3364, 3481, 3600,
  100. 3721, 3844, 3969, 4096, 4225,
  101. 4356, 4489, 4624, 4761, 4900,
  102. 5041, 5181, 5329, 5476, 5625,
  103. 5776, 5929, 6084, 6241, 6400,
  104. 6561, 6724, 6889, 7056, 7225,
  105. 7396, 7569, 7744, 7921, 8100,
  106. 8281, 8464, 8649, 8836, 9025,
  107. 9216, 9409, 9604, 9801, 10000,
  108. 10201, 10404, 10609, 10816, 11025,
  109. 11236, 11449, 11664, 11881, 12100,
  110. 12321, 12544, 12769, 12996, 13225,
  111. 13456, 13689, 13924, 14161, 14400,
  112. 14641, 14884, 15129, 15376, 15625,
  113. 15876, 16129, 16384, 16641
  114. };
  115. /************************************************************
  116. * DDA Poly line generate
  117. */
  118. /* */ static int
  119. /* */ DDACon(
  120. /* */ struct vecdata *s,
  121. /* */ struct vecdata *cp,
  122. /* */ struct vecdata *e,
  123. /* */ int lstHdl)
  124. /*
  125. * returns : 0, -1
  126. ************************************************************/
  127. {
  128. int n2xmax, n2ymax, n2max;
  129. int i, n;
  130. long f1x, /* for f1�@ */
  131. fx, /* for F(i) */
  132. px, /* for G(i) */
  133. g1x, g2x;
  134. long f1y, /* for f1�@ */
  135. fy, /* for F(i) */
  136. py, /* for G(i) */
  137. g1y, g2y;
  138. int sts, num;
  139. long relx, rely; /* ���΍��W */
  140. int n2, n2hlf;
  141. struct vecdata pntdata;
  142. /* Set Start Point */
  143. if ( (sts= VDSetData( lstHdl, s))<0)
  144. goto RET;
  145. /* ������ N�����߂� */
  146. n2xmax = (e->x - cp->x) - ( cp->x - s->x);
  147. if ( n2xmax < 0) n2xmax = -n2xmax;
  148. else if ( n2xmax == 0 && cp->x==s->x)
  149. goto TERM_SET;
  150. n2ymax = (e->y - cp->y) - ( cp->y - s->y);
  151. if ( n2ymax < 0) n2ymax = -n2ymax;
  152. else if ( n2ymax == 0 && cp->y==s->y)
  153. goto TERM_SET;
  154. if ( n2xmax > n2ymax) n2max = (n2xmax*2) >> UNDERFP;
  155. else n2max = (n2ymax*2) >> UNDERFP;
  156. n = fsqrt( n2max);
  157. /* �����_�̍��W�����߂� */
  158. if ( n > 1) {
  159. n2 = n*n;
  160. n2hlf = (n*n)/2; /* Expect Optimize */
  161. px = (long)s->x*n2;
  162. py = (long)s->y*n2;
  163. g2x = (e->x - cp->x) - (cp->x - s->x);
  164. g2y = (e->y - cp->y) - (cp->y - s->y);
  165. g1x = (long)n*(cp->x - s->x) *2;
  166. g1y = (long)n*(cp->y - s->y) *2;
  167. f1x = g2x*2;
  168. f1y = g2y*2;
  169. fx = g1x + g2x;
  170. fy = g1y + g2y;
  171. px += fx;
  172. py += fy;
  173. /* �ŏ��̓_�����߂� : �n�_�����̑��΍��W�����v�Z���� */
  174. relx = fx;
  175. rely = fy;
  176. if (relx >= 0) relx += n2hlf;
  177. else relx -= n2hlf;
  178. if (rely >= 0) rely += n2hlf;
  179. else rely -= n2hlf;
  180. pntdata.x = (int)(relx / n2 + s->x);
  181. pntdata.y = (int)(rely / n2 + s->y);
  182. pntdata.atr = 0;
  183. if ( (sts= VDSetData( lstHdl, &pntdata ))<0)
  184. goto RET;
  185. if (n > 2) {
  186. num = n - 1;
  187. for ( i = 2; i < num; i++) {
  188. fx += f1x;
  189. fy += f1y;
  190. px += fx;
  191. py += fy;
  192. /* �ŏ��ƍŌ��̓_�ȊO�̓_�����΍��W�Ōv�Z���� */
  193. pntdata.x = (int)((px + n2hlf) /n2);
  194. pntdata.y = (int)((py + n2hlf) /n2);
  195. if ( (sts= VDSetData(lstHdl, &pntdata ))<0)
  196. goto RET;
  197. }
  198. fx += f1x;
  199. fy += f1y;
  200. px += fx;
  201. py += fy;
  202. relx = px - (long)e->x*n2;
  203. rely = py - (long)e->y*n2;
  204. if (relx >= 0) relx += n2hlf;
  205. else relx -= n2hlf;
  206. if (rely >= 0) rely += n2hlf;
  207. else rely -= n2hlf;
  208. /* �Ō��̓_�����߂� : �I�_�����̑��΍��W�����v�Z���� */
  209. pntdata.x = (int)(relx / n2 + e->x);
  210. pntdata.y = (int)(rely / n2 + e->y);
  211. if ( (sts= VDSetData(lstHdl, &pntdata))<0)
  212. goto RET;
  213. }
  214. }
  215. TERM_SET:
  216. /* �Ȑ��̏I�_�͐ݒ肵�Ȃ� */
  217. RET:
  218. return( sts);
  219. }
  220. /************************************************************
  221. * Fast SQRT (N̕߂)
  222. */
  223. /* */ static int
  224. /* */ fsqrt( int n)
  225. /*
  226. * returns :
  227. ************************************************************/
  228. {
  229. int i;
  230. if ( n < NMAX*2) {
  231. i = lowsqr[ n/2];
  232. }
  233. else {
  234. for ( i=0; i<NMAX; i++ )
  235. if ( sqrtbl[i] > n) break;
  236. i++;
  237. }
  238. return( i );
  239. }
  240. /* EOF */