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.

271 lines
7.8 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. * splitarcs.c++ - $Revision: 1.5 $
  14. * Derrick Burns - 1991
  15. */
  16. #include "glimport.h"
  17. #include "myassert.h"
  18. #include "mysetjmp.h"
  19. #include "mystdio.h"
  20. #include "subdivid.h"
  21. #include "arcsorte.h"
  22. #include "arc.h"
  23. #include "bin.h"
  24. /* local preprocessor definitions */
  25. #define MAXARCS 10
  26. /*----------------------------------------------------------------------------
  27. * Subdivider::split - split trim regions in source bin by line (param == value).
  28. *----------------------------------------------------------------------------
  29. */
  30. void
  31. Subdivider::split( Bin& bin, Bin& left, Bin& right, int param, REAL value )
  32. {
  33. Bin intersections, unknown;
  34. partition( bin, left, intersections, right, unknown, param, value );
  35. int count = intersections.numarcs();
  36. if( count % 2 ) {
  37. #ifndef NDEBUG
  38. left.show( "left" );
  39. intersections.show( "intersections" );
  40. right.show( "right" );
  41. #endif
  42. ::mylongjmp( jumpbuffer, 29 );
  43. }
  44. Arc_ptr arclist[MAXARCS], *list;
  45. if( count >= MAXARCS ) {
  46. list = new Arc_ptr[count];
  47. } else {
  48. list = arclist;
  49. }
  50. Arc_ptr jarc;
  51. for( Arc_ptr *last = list; jarc=intersections.removearc(); last++ )
  52. *last = jarc;
  53. if( param == 0 ) { /* sort into increasing t order */
  54. ArcSdirSorter sorter(*this);
  55. sorter.qsort( list, count );
  56. //::qsort ((void *)list, count, sizeof(Arc_ptr), (cmpfunc)compare_s);
  57. for( Arc_ptr *lptr=list; lptr<last; lptr+=2 )
  58. check_s ( lptr[0], lptr[1] );
  59. for( lptr=list; lptr<last; lptr+=2 )
  60. join_s ( left, right, lptr[0], lptr[1] );
  61. for( lptr=list; lptr != last; lptr++ ) {
  62. if( ((*lptr)->head()[0] <= value) && ((*lptr)->tail()[0] <= value) )
  63. left.addarc( *lptr );
  64. else
  65. right.addarc( *lptr );
  66. }
  67. } else { /* sort into decreasing s order */
  68. ArcTdirSorter sorter(*this);
  69. sorter.qsort( list, count );
  70. //::qsort ((void *)list, count, sizeof(Arc_ptr), (cmpfunc)compare_t);
  71. for( Arc_ptr *lptr=list; lptr<last; lptr+=2 )
  72. check_t ( lptr[0], lptr[1] );
  73. for( lptr=list; lptr<last; lptr+=2 )
  74. join_t ( left, right, lptr[0], lptr[1] );
  75. for( lptr=list; lptr != last; lptr++ ) {
  76. if( ((*lptr)->head()[1] <= value) && ((*lptr)->tail()[1] <= value) )
  77. left.addarc( *lptr );
  78. else
  79. right.addarc( *lptr );
  80. }
  81. }
  82. if( list != arclist ) delete[] list;
  83. unknown.adopt();
  84. }
  85. void
  86. Subdivider::check_s( Arc_ptr jarc1, Arc_ptr jarc2 )
  87. {
  88. assert( jarc1->check( ) != 0 );
  89. assert( jarc2->check( ) != 0 );
  90. assert( jarc1->next->check( ) != 0 );
  91. assert( jarc2->next->check( ) != 0 );
  92. assert( jarc1 != jarc2 );
  93. /* XXX - if these assertions fail, it is due to user error or
  94. undersampling */
  95. if( ! ( jarc1->tail()[0] < (jarc1)->head()[0] ) ) {
  96. #ifndef NDEBUG
  97. dprintf( "s difference %f\n", (jarc1)->tail()[0] - (jarc1)->head()[0] );
  98. #endif
  99. ::mylongjmp( jumpbuffer, 28 );
  100. }
  101. if( ! ( jarc2->tail()[0] > (jarc2)->head()[0] ) ) {
  102. #ifndef NDEBUG
  103. dprintf( "s difference %f\n", (jarc2)->tail()[0] - (jarc2)->head()[0] );
  104. #endif
  105. ::mylongjmp( jumpbuffer, 28 );
  106. }
  107. }
  108. inline void
  109. Subdivider::link( Arc_ptr jarc1, Arc_ptr jarc2, Arc_ptr up, Arc_ptr down )
  110. {
  111. up->nuid = down->nuid = 0; // XXX
  112. up->next = jarc2;
  113. down->next = jarc1;
  114. up->prev = jarc1->prev;
  115. down->prev = jarc2->prev;
  116. down->next->prev = down;
  117. up->next->prev = up;
  118. down->prev->next = down;
  119. up->prev->next = up;
  120. }
  121. inline void
  122. Subdivider::simple_link( Arc_ptr jarc1, Arc_ptr jarc2 )
  123. {
  124. Arc_ptr tmp = jarc2->prev;
  125. jarc2->prev = jarc1->prev;
  126. jarc1->prev = tmp;
  127. jarc2->prev->next = jarc2;
  128. jarc1->prev->next = jarc1;
  129. }
  130. /*----------------------------------------------------------------------------
  131. * join - add a pair of oppositely directed jordan arcs between two arcs
  132. *----------------------------------------------------------------------------
  133. */
  134. void
  135. Subdivider::join_s( Bin& left, Bin& right, Arc_ptr jarc1, Arc_ptr jarc2 )
  136. {
  137. assert( jarc1->check( ) != 0);
  138. assert( jarc2->check( ) != 0);
  139. assert( jarc1 != jarc2 );
  140. if( ! jarc1->getitail() )
  141. jarc1 = jarc1->next;
  142. if( ! jarc2->getitail() )
  143. jarc2 = jarc2->next;
  144. REAL s = jarc1->tail()[0];
  145. REAL t1 = jarc1->tail()[1];
  146. REAL t2 = jarc2->tail()[1];
  147. if( t1 == t2 ) {
  148. simple_link( jarc1, jarc2 );
  149. } else {
  150. Arc_ptr newright = new(arcpool) Arc( arc_right, 0 );
  151. Arc_ptr newleft = new(arcpool) Arc( arc_left, 0 );
  152. assert( t1 < t2 );
  153. if( isBezierArcType() ) {
  154. arctessellator.bezier( newright, s, s, t1, t2 );
  155. arctessellator.bezier( newleft, s, s, t2, t1 );
  156. } else {
  157. arctessellator.pwl_right( newright, s, t1, t2, stepsizes[0] );
  158. arctessellator.pwl_left( newleft, s, t2, t1, stepsizes[2] );
  159. }
  160. link( jarc1, jarc2, newright, newleft );
  161. left.addarc( newright );
  162. right.addarc( newleft );
  163. }
  164. assert( jarc1->check( ) != 0 );
  165. assert( jarc2->check( ) != 0 );
  166. assert( jarc1->next->check( ) != 0);
  167. assert( jarc2->next->check( ) != 0);
  168. }
  169. void
  170. Subdivider::check_t( Arc_ptr jarc1, Arc_ptr jarc2 )
  171. {
  172. assert( jarc1->check( ) != 0 );
  173. assert( jarc2->check( ) != 0 );
  174. assert( jarc1->next->check( ) != 0 );
  175. assert( jarc2->next->check( ) != 0 );
  176. assert( jarc1 != jarc2 );
  177. /* XXX - if these assertions fail, it is due to user error or
  178. undersampling */
  179. if( ! ( jarc1->tail()[1] < (jarc1)->head()[1] ) ) {
  180. #ifndef NDEBUG
  181. dprintf( "t difference %f\n", jarc1->tail()[1] - (jarc1)->head()[1] );
  182. #endif
  183. ::mylongjmp( jumpbuffer, 28 );
  184. }
  185. if( ! ( jarc2->tail()[1] > (jarc2)->head()[1] ) ) {
  186. #ifndef NDEBUG
  187. dprintf( "t difference %f\n", jarc2->tail()[1] - (jarc2)->head()[1] );
  188. #endif
  189. ::mylongjmp( jumpbuffer, 28 );
  190. }
  191. }
  192. /*----------------------------------------------------------------------------
  193. * join_t - add a pair of oppositely directed jordan arcs between two arcs
  194. *----------------------------------------------------------------------------
  195. */
  196. void
  197. Subdivider::join_t( Bin& bottom, Bin& top, Arc_ptr jarc1, Arc_ptr jarc2 )
  198. {
  199. assert( jarc1->check( ) != 0 );
  200. assert( jarc2->check( ) != 0 );
  201. assert( jarc1->next->check( ) != 0 );
  202. assert( jarc2->next->check( ) != 0 );
  203. assert( jarc1 != jarc2 );
  204. if( ! jarc1->getitail() )
  205. jarc1 = jarc1->next;
  206. if( ! jarc2->getitail() )
  207. jarc2 = jarc2->next;
  208. REAL s1 = jarc1->tail()[0];
  209. REAL s2 = jarc2->tail()[0];
  210. REAL t = jarc1->tail()[1];
  211. if( s1 == s2 ) {
  212. simple_link( jarc1, jarc2 );
  213. } else {
  214. Arc_ptr newtop = new(arcpool) Arc( arc_top, 0 );
  215. Arc_ptr newbot = new(arcpool) Arc( arc_bottom, 0 );
  216. assert( s1 > s2 );
  217. if( isBezierArcType() ) {
  218. arctessellator.bezier( newtop, s1, s2, t, t );
  219. arctessellator.bezier( newbot, s2, s1, t, t );
  220. } else {
  221. arctessellator.pwl_top( newtop, t, s1, s2, stepsizes[1] );
  222. arctessellator.pwl_bottom( newbot, t, s2, s1, stepsizes[3] );
  223. }
  224. link( jarc1, jarc2, newtop, newbot );
  225. bottom.addarc( newtop );
  226. top.addarc( newbot );
  227. }
  228. assert( jarc1->check( ) != 0 );
  229. assert( jarc2->check( ) != 0 );
  230. assert( jarc1->next->check( ) != 0 );
  231. assert( jarc2->next->check( ) != 0 );
  232. }