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.

122 lines
3.1 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. * varray.c++ - $Revision: 1.6 $
  14. * Derrick Burns - 1991
  15. */
  16. #include "glimport.h"
  17. #include "myassert.h"
  18. #include "mystdio.h"
  19. #include "varray.h"
  20. #include "arc.h"
  21. #include "math.h" // fabs()
  22. #define TINY 0.0001
  23. inline long sgn( REAL x )
  24. {
  25. return (x < -TINY) ? -1 : ((x > TINY) ? 1 : 0 );
  26. }
  27. Varray::Varray( void )
  28. {
  29. varray = 0;
  30. size = 0;
  31. }
  32. Varray::~Varray( void )
  33. {
  34. if( varray ) delete[] varray;
  35. }
  36. inline void
  37. Varray::update( Arc_ptr arc, long dir[2], REAL val )
  38. {
  39. register long ds = sgn(arc->tail()[0] - arc->prev->tail()[0]);
  40. register long dt = sgn(arc->tail()[1] - arc->prev->tail()[1]);
  41. if( dir[0] != ds || dir[1] != dt ) {
  42. dir[0] = ds;
  43. dir[1] = dt;
  44. append( val );
  45. }
  46. }
  47. void
  48. Varray::grow( long guess )
  49. {
  50. if( size < guess ) {
  51. size = guess * 2;
  52. if( varray ) delete[] varray;
  53. varray = new REAL[size];
  54. assert( varray != 0 );
  55. }
  56. }
  57. long
  58. Varray::init( REAL delta, Arc_ptr toparc, Arc_ptr botarc )
  59. {
  60. Arc_ptr left = toparc->next;
  61. Arc_ptr right = toparc;
  62. long ldir[2], rdir[2];
  63. ldir[0] = sgn( left->tail()[0] - left->prev->tail()[0] );
  64. ldir[1] = sgn( left->tail()[1] - left->prev->tail()[1] );
  65. rdir[0] = sgn( right->tail()[0] - right->prev->tail()[0] );
  66. rdir[1] = sgn( right->tail()[1] - right->prev->tail()[1] );
  67. vval[0] = toparc->tail()[1];
  68. numquads = 0;
  69. while( 1 ) {
  70. switch( sgn( left->tail()[1] - right->prev->tail()[1] ) ) {
  71. case 1:
  72. left = left->next;
  73. update( left, ldir, left->prev->tail()[1] );
  74. break;
  75. case -1:
  76. right = right->prev;
  77. update( right, rdir, right->tail()[1] );
  78. break;
  79. case 0:
  80. if( fabs(left->tail()[1] - botarc->tail()[1]) < TINY) goto end;
  81. if( fabs(left->tail()[0]-right->prev->tail()[0]) < TINY &&
  82. fabs(left->tail()[1]-right->prev->tail()[1]) < TINY) goto end;
  83. left = left->next;
  84. break;
  85. }
  86. }
  87. end:
  88. append( botarc->tail()[1] );
  89. grow( ((long) ((vval[0] - vval[numquads])/delta)) + numquads + 2 );
  90. long index = 0;
  91. for( long i=0; i<numquads; i++ ) {
  92. voffset[i] = index;
  93. varray[index++] = vval[i];
  94. REAL dist = vval[i] - vval[i+1];
  95. if( dist > delta ) {
  96. long steps = ((long) (dist/delta)) +1;
  97. float deltav = - dist / (REAL) steps;
  98. for( long j=1; j<steps; j++ )
  99. varray[index++] = vval[i] + j * deltav;
  100. }
  101. }
  102. voffset[i] = index;
  103. varray[index] = vval[i];
  104. return index;
  105. }