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.

149 lines
3.9 KiB

  1. #ifndef __gluarcsorter_c_
  2. #define __gluarcsorter_c_
  3. /**************************************************************************
  4. * *
  5. * Copyright (C) 1992, Silicon Graphics, Inc. *
  6. * *
  7. * These coded instructions, statements, and computer programs contain *
  8. * unpublished proprietary information of Silicon Graphics, Inc., and *
  9. * are protected by Federal copyright law. They may not be disclosed *
  10. * to third parties or copied or duplicated in any form, in whole or *
  11. * in part, without the prior written consent of Silicon Graphics, Inc. *
  12. * *
  13. **************************************************************************/
  14. /*
  15. * arcsorter.c++ - $Revision: 1.1 $
  16. * Derrick Burns - 1991
  17. */
  18. #include "glimport.h"
  19. #include "arc.h"
  20. #include "arcsorte.h"
  21. #include "subdivid.h"
  22. ArcSorter::ArcSorter(Subdivider &s) : Sorter( sizeof( Arc ** ) ), subdivider(s)
  23. {
  24. }
  25. int
  26. ArcSorter::qscmp( char *, char * )
  27. {
  28. dprintf( "ArcSorter::qscmp: pure virtual called\n" );
  29. return 0;
  30. }
  31. void
  32. ArcSorter::qsort( Arc **a, int n )
  33. {
  34. Sorter::qsort( (void *) a, n );
  35. }
  36. void
  37. ArcSorter::qsexc( char *i, char *j )// i<-j, j<-i
  38. {
  39. Arc **jarc1 = (Arc **) i;
  40. Arc **jarc2 = (Arc **) j;
  41. Arc *tmp = *jarc1;
  42. *jarc1 = *jarc2;
  43. *jarc2 = tmp;
  44. }
  45. void
  46. ArcSorter::qstexc( char *i, char *j, char *k )// i<-k, k<-j, j<-i
  47. {
  48. Arc **jarc1 = (Arc **) i;
  49. Arc **jarc2 = (Arc **) j;
  50. Arc **jarc3 = (Arc **) k;
  51. Arc *tmp = *jarc1;
  52. *jarc1 = *jarc3;
  53. *jarc3 = *jarc2;
  54. *jarc2 = tmp;
  55. }
  56. ArcSdirSorter::ArcSdirSorter( Subdivider &s ) : ArcSorter(s)
  57. {
  58. }
  59. int
  60. ArcSdirSorter::qscmp( char *i, char *j )
  61. {
  62. Arc *jarc1 = *(Arc **) i;
  63. Arc *jarc2 = *(Arc **) j;
  64. int v1 = (jarc1->getitail() ? 0 : (jarc1->pwlArc->npts - 1));
  65. int v2 = (jarc2->getitail() ? 0 : (jarc2->pwlArc->npts - 1));
  66. REAL diff = jarc1->pwlArc->pts[v1].param[1] -
  67. jarc2->pwlArc->pts[v2].param[1];
  68. if( diff < 0.0)
  69. return -1;
  70. else if( diff > 0.0)
  71. return 1;
  72. else {
  73. if( v1 == 0 ) {
  74. if( jarc2->tail()[0] < jarc1->tail()[0] ) {
  75. return subdivider.ccwTurn_sl( jarc2, jarc1 ) ? 1 : -1;
  76. } else {
  77. return subdivider.ccwTurn_sr( jarc2, jarc1 ) ? -1 : 1;
  78. }
  79. } else {
  80. if( jarc2->head()[0] < jarc1->head()[0] ) {
  81. return subdivider.ccwTurn_sl( jarc1, jarc2 ) ? -1 : 1;
  82. } else {
  83. return subdivider.ccwTurn_sr( jarc1, jarc2 ) ? 1 : -1;
  84. }
  85. }
  86. }
  87. }
  88. ArcTdirSorter::ArcTdirSorter( Subdivider &s ) : ArcSorter(s)
  89. {
  90. }
  91. /*----------------------------------------------------------------------------
  92. * ArcTdirSorter::qscmp -
  93. * compare two axis monotone arcs that are incident
  94. * to the line T == compare_value. Determine which of the
  95. * two intersects that line with a LESSER S value. If
  96. * jarc1 does, return 1. If jarc2 does, return -1.
  97. *----------------------------------------------------------------------------
  98. */
  99. int
  100. ArcTdirSorter::qscmp( char *i, char *j )
  101. {
  102. Arc *jarc1 = *(Arc **) i;
  103. Arc *jarc2 = *(Arc **) j;
  104. int v1 = (jarc1->getitail() ? 0 : (jarc1->pwlArc->npts - 1));
  105. int v2 = (jarc2->getitail() ? 0 : (jarc2->pwlArc->npts - 1));
  106. REAL diff = jarc1->pwlArc->pts[v1].param[0] -
  107. jarc2->pwlArc->pts[v2].param[0];
  108. if( diff < 0.0)
  109. return 1;
  110. else if( diff > 0.0)
  111. return -1;
  112. else {
  113. if( v1 == 0 ) {
  114. if (jarc2->tail()[1] < jarc1->tail()[1]) {
  115. return subdivider.ccwTurn_tl( jarc2, jarc1 ) ? 1 : -1;
  116. } else {
  117. return subdivider.ccwTurn_tr( jarc2, jarc1 ) ? -1 : 1;
  118. }
  119. } else {
  120. if( jarc2->head()[1] < jarc1->head()[1] ) {
  121. return subdivider.ccwTurn_tl( jarc1, jarc2 ) ? -1 : 1;
  122. } else {
  123. return subdivider.ccwTurn_tr( jarc1, jarc2 ) ? 1 : -1;
  124. }
  125. }
  126. }
  127. }
  128. #endif /* __gluarcsorter_c_ */