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.

198 lines
4.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. * trimline.c++ - $Revision: 1.1 $
  14. * Derrick Burns - 1991
  15. */
  16. #include "glimport.h"
  17. #include "myassert.h"
  18. #include "mystdio.h"
  19. #include "trimline.h"
  20. #include "backend.h"
  21. Trimline::Trimline()
  22. {
  23. size = 0; pts = 0; numverts = 0;
  24. tinterp = &t; binterp = &b;
  25. }
  26. Trimline::~Trimline()
  27. {
  28. if( pts ) delete[] pts;
  29. }
  30. void
  31. Trimline::init( TrimVertex *v )
  32. {
  33. reset();
  34. grow(1);
  35. append(v);
  36. }
  37. inline void
  38. Trimline::grow( long npts )
  39. {
  40. if( size < npts ) {
  41. size = 2 * npts;
  42. if( pts ) delete[] pts;
  43. pts = new TrimVertex_p[size];
  44. }
  45. }
  46. inline void
  47. Trimline::append( TrimVertex *v )
  48. {
  49. assert( numverts != size );
  50. pts[numverts++] = v;
  51. }
  52. void
  53. Trimline::init( long npts, Arc_ptr jarc, long last )
  54. {
  55. jarcl.init( jarc, 0, last );
  56. grow( npts + 2 );
  57. }
  58. inline void
  59. Trimline::swap()
  60. {
  61. TrimVertex *tmp=tinterp;
  62. tinterp=binterp;
  63. binterp=tmp;
  64. }
  65. void
  66. Trimline::getNextPt()
  67. {
  68. *binterp = *jarcl.getnextpt();
  69. }
  70. void
  71. Trimline::getPrevPt()
  72. {
  73. *binterp = *jarcl.getprevpt();
  74. }
  75. /*----------------------------------------------------------------------
  76. * getNextPts - make arrays of pointers to trim points on left and right
  77. * hulls of trim strip.
  78. *----------------------------------------------------------------------
  79. */
  80. void
  81. Trimline::getNextPts( REAL vval, Backend& backend )
  82. {
  83. reset(); swap(); append( tinterp );
  84. assert( tinterp->param[1] >= vval );
  85. register TrimVertex *p;
  86. for( p=jarcl.getnextpt() ; p->param[1] >= vval; p=jarcl.getnextpt() ) {
  87. append( p );
  88. }
  89. /* compute and copy pointer to final point on left hull */
  90. if( interpvert( last(), p, binterp, vval ) ) {
  91. binterp->nuid = p->nuid;
  92. backend.triangle( p, binterp, last() );
  93. append( binterp );
  94. }
  95. jarcl.reverse();
  96. (void) jarcl.getprevpt(); /* reset jarcl to proper position */
  97. jarcl.reverse();
  98. }
  99. void
  100. Trimline::getPrevPts( REAL vval, Backend& backend )
  101. {
  102. reset(); swap(); append( tinterp );
  103. assert( tinterp->param[1] >= vval );
  104. register TrimVertex *q;
  105. for( q=jarcl.getprevpt(); q->param[1] >= vval; q=jarcl.getprevpt() ) {
  106. append( q );
  107. }
  108. /* compute and copy pointer to final point on right hull */
  109. if( interpvert( q, last(), binterp, vval ) ) {
  110. binterp->nuid = q->nuid;
  111. backend.triangle( last(), binterp, q );
  112. append( binterp );
  113. }
  114. jarcl.reverse();
  115. (void) jarcl.getnextpt(); /* reset jarcl to proper position */
  116. jarcl.reverse();
  117. }
  118. void
  119. Trimline::getNextPts( Arc_ptr botarc )
  120. {
  121. reset(); swap(); append( tinterp );
  122. PwlArc *lastpwl = botarc->prev->pwlArc;
  123. TrimVertex *lastpt1 = &lastpwl->pts[lastpwl->npts-1];
  124. TrimVertex *lastpt2 = botarc->pwlArc->pts;
  125. register TrimVertex *p = jarcl.getnextpt();
  126. for( append( p ); p != lastpt2; append( p ) ) {
  127. assert( p != lastpt1 );
  128. p = jarcl.getnextpt();
  129. }
  130. }
  131. void
  132. Trimline::getPrevPts( Arc_ptr botarc )
  133. {
  134. reset(); swap(); append( tinterp );
  135. PwlArc *lastpwl = botarc->prev->pwlArc;
  136. TrimVertex *lastpt1 = &lastpwl->pts[lastpwl->npts-1];
  137. TrimVertex *lastpt2 = botarc->pwlArc->pts;
  138. register TrimVertex *q = jarcl.getprevpt();
  139. for( append( q ); q != lastpt1; append( q ) ) {
  140. assert( q != lastpt2 );
  141. q = jarcl.getprevpt();
  142. }
  143. }
  144. long
  145. Trimline::interpvert( TrimVertex *a, TrimVertex *b, TrimVertex *c, REAL vval )
  146. {
  147. REAL denom = a->param[1] - b->param[1];
  148. if(denom != 0) {
  149. if( vval == a->param[1] ) {
  150. c->param[0] = a->param[0];
  151. c->param[1] = a->param[1];
  152. c->nuid = a->nuid;
  153. return 0;
  154. } else if( vval == b->param[1] ) {
  155. c->param[0] = b->param[0];
  156. c->param[1] = b->param[1];
  157. c->nuid = b->nuid;
  158. return 0;
  159. } else {
  160. REAL r = (a->param[1] - vval)/denom;
  161. c->param[0] = a->param[0] - r * (a->param[0] - b->param[0]);
  162. c->param[1] = vval;
  163. return 1;
  164. }
  165. } else {
  166. c->param[0] = a->param[0];
  167. c->param[1] = a->param[1];
  168. c->nuid = a->nuid;
  169. return 0;
  170. }
  171. }