Leaked source code of windows server 2003
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.

332 lines
8.7 KiB

  1. /**************************************************************************
  2. * *
  3. * Copyright (C) 1992, Silicon Graphics, Inc. *
  4. * *
  5. * These coded instructions, statements, and computer programs contain *
  6. * unpublished proprietary information of Silicon Graphics, Inc., and *
  7. * are protected by Federal copyright law. They may not be disclosed *
  8. * to third parties or copied or duplicated in any form, in whole or *
  9. * in part, without the prior written consent of Silicon Graphics, Inc. *
  10. * *
  11. **************************************************************************/
  12. /*
  13. * arc.c++ - $Revision: 1.7 $
  14. * Derrick Burns - 1991
  15. */
  16. #include "glimport.h"
  17. #include "mystdio.h"
  18. #include "myassert.h"
  19. #include "arc.h"
  20. #include "bin.h"
  21. #include "bezierar.h"
  22. #include "pwlarc.h"
  23. #include "simplema.h"
  24. /* local preprocessor definitions */
  25. #define ZERO 0.00001/*0.000001*/
  26. const int Arc::bezier_tag = (1<<13);
  27. const int Arc::arc_tag = (1<<3);
  28. const int Arc::tail_tag = (1<<6);
  29. /*--------------------------------------------------------------------------
  30. * makeSide - attach a pwl arc to an arc and mark it as a border arc
  31. *--------------------------------------------------------------------------
  32. */
  33. void
  34. Arc::makeSide( PwlArc *pwl, arc_side side )
  35. {
  36. assert( pwl != 0);
  37. assert( pwlArc == 0 );
  38. assert( pwl->npts > 0 );
  39. assert( pwl->pts != 0);
  40. pwlArc = pwl;
  41. clearbezier();
  42. setside( side );
  43. }
  44. /*--------------------------------------------------------------------------
  45. * numpts - count number of points on arc loop
  46. *--------------------------------------------------------------------------
  47. */
  48. int
  49. Arc::numpts( void )
  50. {
  51. Arc_ptr jarc = this;
  52. int npts = 0;
  53. do {
  54. npts += jarc->pwlArc->npts;
  55. jarc = jarc->next;
  56. } while( jarc != this );
  57. return npts;
  58. }
  59. /*--------------------------------------------------------------------------
  60. * markverts - mark each point with id of arc
  61. *--------------------------------------------------------------------------
  62. */
  63. void
  64. Arc::markverts( void )
  65. {
  66. Arc_ptr jarc = this;
  67. do {
  68. TrimVertex *p = jarc->pwlArc->pts;
  69. for( int i=0; i<jarc->pwlArc->npts; i++ )
  70. p[i].nuid = jarc->nuid;
  71. jarc = jarc->next;
  72. } while( jarc != this );
  73. }
  74. /*--------------------------------------------------------------------------
  75. * getextrema - find axis extrema on arc loop
  76. *--------------------------------------------------------------------------
  77. */
  78. void
  79. Arc::getextrema( Arc_ptr extrema[4] )
  80. {
  81. REAL leftpt, botpt, rightpt, toppt;
  82. extrema[0] = extrema[1] = extrema[2] = extrema[3] = this;
  83. leftpt = rightpt = this->tail()[0];
  84. botpt = toppt = this->tail()[1];
  85. for( Arc_ptr jarc = this->next; jarc != this; jarc = jarc->next ) {
  86. if ( jarc->tail()[0] < leftpt ||
  87. (jarc->tail()[0] <= leftpt && jarc->rhead()[0]<=leftpt)) {
  88. leftpt = jarc->pwlArc->pts->param[0];
  89. extrema[1] = jarc;
  90. }
  91. if ( jarc->tail()[0] > rightpt ||
  92. (jarc->tail()[0] >= rightpt && jarc->rhead()[0] >= rightpt)) {
  93. rightpt = jarc->pwlArc->pts->param[0];
  94. extrema[3] = jarc;
  95. }
  96. if ( jarc->tail()[1] < botpt ||
  97. (jarc->tail()[1] <= botpt && jarc->rhead()[1] <= botpt )) {
  98. botpt = jarc->pwlArc->pts->param[1];
  99. extrema[2] = jarc;
  100. }
  101. if ( jarc->tail()[1] > toppt ||
  102. (jarc->tail()[1] >= toppt && jarc->rhead()[1] >= toppt)) {
  103. toppt = jarc->pwlArc->pts->param[1];
  104. extrema[0] = jarc;
  105. }
  106. }
  107. }
  108. /*-------------------------------------------------------------------------
  109. * show - print to the stdout the vertices of a pwl arc
  110. *-------------------------------------------------------------------------
  111. */
  112. void
  113. Arc::show()
  114. {
  115. #ifndef NDEBUG
  116. dprintf( "\tPWLARC NP: %d FL: 1\n", pwlArc->npts );
  117. for( int i = 0; i < pwlArc->npts; i++ ) {
  118. dprintf( "\t\tVERTEX %f %f\n", pwlArc->pts[i].param[0],
  119. pwlArc->pts[i].param[1] );
  120. }
  121. #endif
  122. }
  123. /*-------------------------------------------------------------------------
  124. * print - print out the vertices of all pwl arcs on a loop
  125. *-------------------------------------------------------------------------
  126. */
  127. void
  128. Arc::print( void )
  129. {
  130. Arc_ptr jarc = this;
  131. if( ! this ) {
  132. #ifndef NDEBUG
  133. dprintf( "\n\nEMPTY TRIM\n\n" );
  134. #endif
  135. return;
  136. }
  137. #ifndef NDEBUG
  138. dprintf( "BGNTRIM\n" );
  139. #endif
  140. do {
  141. jarc->show( );
  142. jarc = jarc->next;
  143. } while (jarc != this);
  144. #ifndef NDEBUG
  145. dprintf("ENDTRIM\n" );
  146. #endif
  147. }
  148. /*-------------------------------------------------------------------------
  149. * isDisconnected - check if tail of arc and head of prev meet
  150. *-------------------------------------------------------------------------
  151. */
  152. int
  153. Arc::isDisconnected( void )
  154. {
  155. if( pwlArc == 0 ) return 0;
  156. if( prev->pwlArc == 0 ) return 0;
  157. REAL *p0 = tail();
  158. REAL *p1 = prev->rhead();
  159. if( ((p0[0] - p1[0]) > ZERO) || ((p1[0] - p0[0]) > ZERO) ||
  160. ((p0[1] - p1[1]) > ZERO) || ((p1[1] - p0[1]) > ZERO) ) {
  161. #ifndef NDEBUG
  162. dprintf( "x coord = %f %f %f\n", p0[0], p1[0], p0[0] - p1[0] );
  163. dprintf( "y coord = %f %f %f\n", p0[1], p1[1], p0[1] - p1[1] );
  164. #endif
  165. return 1;
  166. } else {
  167. /* average two points together */
  168. p0[0] = p1[0] = (p1[0] + p0[0]) * 0.5;
  169. p0[1] = p1[1] = (p1[1] + p0[1]) * 0.5;
  170. return 0;
  171. }
  172. }
  173. /*-------------------------------------------------------------------------
  174. * neq_vert - assert that two 2D vertices are not equal
  175. *-------------------------------------------------------------------------
  176. */
  177. inline static int
  178. neq_vert( REAL *v1, REAL *v2 )
  179. {
  180. return ((v1[0] != v2[0]) || (v1[1] != v2[1] )) ? 1 : 0;
  181. }
  182. /*-------------------------------------------------------------------------
  183. * check - verify consistency of a loop, including
  184. * 1) if pwl, no two consecutive vertices are identical
  185. * 2) the circular link pointers are valid
  186. * 3) the geometric info at the head and tail are consistent
  187. *-------------------------------------------------------------------------
  188. */
  189. int
  190. Arc::check( void )
  191. {
  192. if( this == 0 ) return 1;
  193. Arc_ptr jarc = this;
  194. do {
  195. assert( (jarc->pwlArc != 0) || (jarc->bezierArc != 0) );
  196. if (jarc->prev == 0 || jarc->next == 0) {
  197. #ifndef NDEBUG
  198. dprintf( "checkjarc:null next/prev pointer\n");
  199. jarc->print( );
  200. #endif
  201. return 0;
  202. }
  203. if (jarc->next->prev != jarc) {
  204. #ifndef NDEBUG
  205. dprintf( "checkjarc: pointer linkage screwed up\n");
  206. jarc->print( );
  207. #endif
  208. return 0;
  209. }
  210. if( jarc->pwlArc ) {
  211. #ifndef NDEBUG
  212. assert( jarc->pwlArc->npts > 1 );
  213. assert( jarc->pwlArc->npts < 100000 );
  214. /*
  215. for( int i=0; i < jarc->pwlArc->npts-1; i++ )
  216. assert( neq_vert( jarc->pwlArc->pts[i].param,
  217. jarc->pwlArc->pts[i+1].param) );
  218. */
  219. #endif
  220. if( jarc->prev->pwlArc ) {
  221. if( jarc->tail()[1] != jarc->prev->rhead()[1] ) {
  222. #ifndef NDEBUG
  223. dprintf( "checkjarc: geometric linkage screwed up 1\n");
  224. jarc->prev->show();
  225. jarc->show();
  226. #endif
  227. return 0;
  228. }
  229. if( jarc->tail()[0] != jarc->prev->rhead()[0] ) {
  230. #ifndef NDEBUG
  231. dprintf( "checkjarc: geometric linkage screwed up 2\n");
  232. jarc->prev->show();
  233. jarc->show();
  234. #endif
  235. return 0;
  236. }
  237. }
  238. if( jarc->next->pwlArc ) {
  239. if( jarc->next->tail()[0] != jarc->rhead()[0] ) {
  240. #ifndef NDEBUG
  241. dprintf( "checkjarc: geometric linkage screwed up 3\n");
  242. jarc->show();
  243. jarc->next->show();
  244. #endif
  245. return 0;
  246. }
  247. if( jarc->next->tail()[1] != jarc->rhead()[1] ) {
  248. #ifndef NDEBUG
  249. dprintf( "checkjarc: geometric linkage screwed up 4\n");
  250. jarc->show();
  251. jarc->next->show();
  252. #endif
  253. return 0;
  254. }
  255. }
  256. if( jarc->isbezier() ) {
  257. assert( jarc->pwlArc->npts == 2 );
  258. assert( (jarc->pwlArc->pts[0].param[0] == \
  259. jarc->pwlArc->pts[1].param[0]) ||\
  260. (jarc->pwlArc->pts[0].param[1] == \
  261. jarc->pwlArc->pts[1].param[1]) );
  262. }
  263. }
  264. jarc = jarc->next;
  265. } while (jarc != this);
  266. return 1;
  267. }
  268. #define TOL 0.00001
  269. inline long tooclose( REAL x, REAL y )
  270. {
  271. return (abs(x-y) < TOL) ? 1 : 0;
  272. }
  273. /*--------------------------------------------------------------------------
  274. * append - append a jordan arc to a circularly linked list
  275. *--------------------------------------------------------------------------
  276. */
  277. Arc_ptr
  278. Arc::append( Arc_ptr jarc )
  279. {
  280. if( jarc != 0 ) {
  281. next = jarc->next;
  282. prev = jarc;
  283. next->prev = prev->next = this;
  284. } else {
  285. next = prev = this;
  286. }
  287. return this;
  288. }