| 1 |
/* |
| 2 |
* |
| 3 |
* Copyright (C) 2000 Silicon Graphics, Inc. All Rights Reserved. |
| 4 |
* |
| 5 |
* This library is free software; you can redistribute it and/or |
| 6 |
* modify it under the terms of the GNU Lesser General Public |
| 7 |
* License as published by the Free Software Foundation; either |
| 8 |
* version 2.1 of the License, or (at your option) any later version. |
| 9 |
* |
| 10 |
* This library is distributed in the hope that it will be useful, |
| 11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 |
* Lesser General Public License for more details. |
| 14 |
* |
| 15 |
* Further, this software is distributed without any warranty that it is |
| 16 |
* free of the rightful claim of any third person regarding infringement |
| 17 |
* or the like. Any license provided herein, whether implied or |
| 18 |
* otherwise, applies only to this software file. Patent licenses, if |
| 19 |
* any, provided herein do not apply to combinations of this program with |
| 20 |
* other software, or any other product whatsoever. |
| 21 |
* |
| 22 |
* You should have received a copy of the GNU Lesser General Public |
| 23 |
* License along with this library; if not, write to the Free Software |
| 24 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 25 |
* |
| 26 |
* Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, |
| 27 |
* Mountain View, CA 94043, or: |
| 28 |
* |
| 29 |
* http://www.sgi.com |
| 30 |
* |
| 31 |
* For further information regarding this notice, see: |
| 32 |
* |
| 33 |
* http://oss.sgi.com/projects/GenInfo/NoticeExplan/ |
| 34 |
* |
| 35 |
*/ |
| 36 |
|
| 37 |
#ifndef __gluarcsorter_c_ |
| 38 |
#define __gluarcsorter_c_ |
| 39 |
/* |
| 40 |
* arcsorter.c++ - $Revision: 1.1.1.1 $ |
| 41 |
* Derrick Burns - 1991 |
| 42 |
*/ |
| 43 |
|
| 44 |
#include "glimports.h" |
| 45 |
#include "arc.h" |
| 46 |
#include "arcsorter.h" |
| 47 |
#include "subdivider.h" |
| 48 |
|
| 49 |
ArcSorter::ArcSorter(Subdivider &s) : Sorter( sizeof( Arc ** ) ), subdivider(s) |
| 50 |
{ |
| 51 |
} |
| 52 |
|
| 53 |
int |
| 54 |
ArcSorter::qscmp( char *, char * ) |
| 55 |
{ |
| 56 |
dprintf( "ArcSorter::qscmp: pure virtual called\n" ); |
| 57 |
return 0; |
| 58 |
} |
| 59 |
|
| 60 |
void |
| 61 |
ArcSorter::qsort( Arc **a, int n ) |
| 62 |
{ |
| 63 |
Sorter::qsort( (void *) a, n ); |
| 64 |
} |
| 65 |
|
| 66 |
void |
| 67 |
ArcSorter::qsexc( char *i, char *j )// i<-j, j<-i |
| 68 |
{ |
| 69 |
Arc **jarc1 = (Arc **) i; |
| 70 |
Arc **jarc2 = (Arc **) j; |
| 71 |
Arc *tmp = *jarc1; |
| 72 |
*jarc1 = *jarc2; |
| 73 |
*jarc2 = tmp; |
| 74 |
} |
| 75 |
|
| 76 |
void |
| 77 |
ArcSorter::qstexc( char *i, char *j, char *k )// i<-k, k<-j, j<-i |
| 78 |
{ |
| 79 |
Arc **jarc1 = (Arc **) i; |
| 80 |
Arc **jarc2 = (Arc **) j; |
| 81 |
Arc **jarc3 = (Arc **) k; |
| 82 |
Arc *tmp = *jarc1; |
| 83 |
*jarc1 = *jarc3; |
| 84 |
*jarc3 = *jarc2; |
| 85 |
*jarc2 = tmp; |
| 86 |
} |
| 87 |
|
| 88 |
|
| 89 |
ArcSdirSorter::ArcSdirSorter( Subdivider &s ) : ArcSorter(s) |
| 90 |
{ |
| 91 |
} |
| 92 |
|
| 93 |
int |
| 94 |
ArcSdirSorter::qscmp( char *i, char *j ) |
| 95 |
{ |
| 96 |
Arc *jarc1 = *(Arc **) i; |
| 97 |
Arc *jarc2 = *(Arc **) j; |
| 98 |
|
| 99 |
int v1 = (jarc1->getitail() ? 0 : (jarc1->pwlArc->npts - 1)); |
| 100 |
int v2 = (jarc2->getitail() ? 0 : (jarc2->pwlArc->npts - 1)); |
| 101 |
|
| 102 |
REAL diff = jarc1->pwlArc->pts[v1].param[1] - |
| 103 |
jarc2->pwlArc->pts[v2].param[1]; |
| 104 |
|
| 105 |
if( diff < 0.0) |
| 106 |
return -1; |
| 107 |
else if( diff > 0.0) |
| 108 |
return 1; |
| 109 |
else { |
| 110 |
if( v1 == 0 ) { |
| 111 |
if( jarc2->tail()[0] < jarc1->tail()[0] ) { |
| 112 |
return subdivider.ccwTurn_sl( jarc2, jarc1 ) ? 1 : -1; |
| 113 |
} else { |
| 114 |
return subdivider.ccwTurn_sr( jarc2, jarc1 ) ? -1 : 1; |
| 115 |
} |
| 116 |
} else { |
| 117 |
if( jarc2->head()[0] < jarc1->head()[0] ) { |
| 118 |
return subdivider.ccwTurn_sl( jarc1, jarc2 ) ? -1 : 1; |
| 119 |
} else { |
| 120 |
return subdivider.ccwTurn_sr( jarc1, jarc2 ) ? 1 : -1; |
| 121 |
} |
| 122 |
} |
| 123 |
} |
| 124 |
} |
| 125 |
|
| 126 |
ArcTdirSorter::ArcTdirSorter( Subdivider &s ) : ArcSorter(s) |
| 127 |
{ |
| 128 |
} |
| 129 |
|
| 130 |
/*---------------------------------------------------------------------------- |
| 131 |
* ArcTdirSorter::qscmp - |
| 132 |
* compare two axis monotone arcs that are incident |
| 133 |
* to the line T == compare_value. Determine which of the |
| 134 |
* two intersects that line with a LESSER S value. If |
| 135 |
* jarc1 does, return 1. If jarc2 does, return -1. |
| 136 |
*---------------------------------------------------------------------------- |
| 137 |
*/ |
| 138 |
int |
| 139 |
ArcTdirSorter::qscmp( char *i, char *j ) |
| 140 |
{ |
| 141 |
Arc *jarc1 = *(Arc **) i; |
| 142 |
Arc *jarc2 = *(Arc **) j; |
| 143 |
|
| 144 |
int v1 = (jarc1->getitail() ? 0 : (jarc1->pwlArc->npts - 1)); |
| 145 |
int v2 = (jarc2->getitail() ? 0 : (jarc2->pwlArc->npts - 1)); |
| 146 |
|
| 147 |
REAL diff = jarc1->pwlArc->pts[v1].param[0] - |
| 148 |
jarc2->pwlArc->pts[v2].param[0]; |
| 149 |
|
| 150 |
if( diff < 0.0) |
| 151 |
return 1; |
| 152 |
else if( diff > 0.0) |
| 153 |
return -1; |
| 154 |
else { |
| 155 |
if( v1 == 0 ) { |
| 156 |
if (jarc2->tail()[1] < jarc1->tail()[1]) { |
| 157 |
return subdivider.ccwTurn_tl( jarc2, jarc1 ) ? 1 : -1; |
| 158 |
} else { |
| 159 |
return subdivider.ccwTurn_tr( jarc2, jarc1 ) ? -1 : 1; |
| 160 |
} |
| 161 |
} else { |
| 162 |
if( jarc2->head()[1] < jarc1->head()[1] ) { |
| 163 |
return subdivider.ccwTurn_tl( jarc1, jarc2 ) ? -1 : 1; |
| 164 |
} else { |
| 165 |
return subdivider.ccwTurn_tr( jarc1, jarc2 ) ? 1 : -1; |
| 166 |
} |
| 167 |
} |
| 168 |
} |
| 169 |
} |
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
#endif /* __gluarcsorter_c_ */ |