2 ** License Applicability. Except to the extent portions of this file are
3 ** made subject to an alternative license as permitted in the SGI Free
4 ** Software License B, Version 1.1 (the "License"), the contents of this
5 ** file are subject only to the provisions of the License. You may not use
6 ** this file except in compliance with the License. You may obtain a copy
7 ** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
8 ** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
10 ** http://oss.sgi.com/projects/FreeB
12 ** Note that, as provided in the License, the Software is distributed on an
13 ** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
14 ** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
15 ** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
16 ** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
18 ** Original Code. The Original Code is: OpenGL Sample Implementation,
19 ** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
20 ** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
21 ** Copyright in any portions created by third parties is as indicated
22 ** elsewhere herein. All Rights Reserved.
24 ** Additional Notice Provisions: The application programming interfaces
25 ** established by SGI in conjunction with the Original Code are The
26 ** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
27 ** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
28 ** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
29 ** Window System(R) (Version 1.3), released October 19, 1998. This software
30 ** was created using the OpenGL(R) version 1.2.1 Sample Implementation
31 ** published by SGI, but has not been independently verified as being
32 ** compliant with the OpenGL(R) version 1.2.1 Specification.
41 #include "glimports.h"
47 #include "simplemath.h"
49 /* local preprocessor definitions */
50 #define ZERO 0.00001/*0.000001*/
52 const int Arc::bezier_tag
= (1<<13);
53 const int Arc::arc_tag
= (1<<3);
54 const int Arc::tail_tag
= (1<<6);
56 /*--------------------------------------------------------------------------
57 * makeSide - attach a pwl arc to an arc and mark it as a border arc
58 *--------------------------------------------------------------------------
62 Arc::makeSide( PwlArc
*pwl
, arc_side side
)
65 assert( pwlArc
== 0 );
66 assert( pwl
->npts
> 0 );
67 assert( pwl
->pts
!= 0);
74 /*--------------------------------------------------------------------------
75 * numpts - count number of points on arc loop
76 *--------------------------------------------------------------------------
85 npts
+= jarc
->pwlArc
->npts
;
87 } while( jarc
!= this );
91 /*--------------------------------------------------------------------------
92 * markverts - mark each point with id of arc
93 *--------------------------------------------------------------------------
97 Arc::markverts( void )
102 TrimVertex
*p
= jarc
->pwlArc
->pts
;
103 for( int i
=0; i
<jarc
->pwlArc
->npts
; i
++ )
104 p
[i
].nuid
= jarc
->nuid
;
106 } while( jarc
!= this );
109 /*--------------------------------------------------------------------------
110 * getextrema - find axis extrema on arc loop
111 *--------------------------------------------------------------------------
115 Arc::getextrema( Arc_ptr extrema
[4] )
117 REAL leftpt
, botpt
, rightpt
, toppt
;
119 extrema
[0] = extrema
[1] = extrema
[2] = extrema
[3] = this;
121 leftpt
= rightpt
= this->tail()[0];
122 botpt
= toppt
= this->tail()[1];
124 for( Arc_ptr jarc
= this->next
; jarc
!= this; jarc
= jarc
->next
) {
125 if ( jarc
->tail()[0] < leftpt
||
126 (jarc
->tail()[0] <= leftpt
&& jarc
->rhead()[0]<=leftpt
)) {
127 leftpt
= jarc
->pwlArc
->pts
->param
[0];
130 if ( jarc
->tail()[0] > rightpt
||
131 (jarc
->tail()[0] >= rightpt
&& jarc
->rhead()[0] >= rightpt
)) {
132 rightpt
= jarc
->pwlArc
->pts
->param
[0];
135 if ( jarc
->tail()[1] < botpt
||
136 (jarc
->tail()[1] <= botpt
&& jarc
->rhead()[1] <= botpt
)) {
137 botpt
= jarc
->pwlArc
->pts
->param
[1];
140 if ( jarc
->tail()[1] > toppt
||
141 (jarc
->tail()[1] >= toppt
&& jarc
->rhead()[1] >= toppt
)) {
142 toppt
= jarc
->pwlArc
->pts
->param
[1];
149 /*-------------------------------------------------------------------------
150 * show - print to the stdout the vertices of a pwl arc
151 *-------------------------------------------------------------------------
158 _glu_dprintf( "\tPWLARC NP: %d FL: 1\n", pwlArc
->npts
);
159 for( int i
= 0; i
< pwlArc
->npts
; i
++ ) {
160 _glu_dprintf( "\t\tVERTEX %f %f\n", pwlArc
->pts
[i
].param
[0],
161 pwlArc
->pts
[i
].param
[1] );
166 /*-------------------------------------------------------------------------
167 * print - print out the vertices of all pwl arcs on a loop
168 *-------------------------------------------------------------------------
177 _glu_dprintf( "BGNTRIM\n" );
182 } while (jarc
!= this);
184 _glu_dprintf("ENDTRIM\n" );
188 /*-------------------------------------------------------------------------
189 * isDisconnected - check if tail of arc and head of prev meet
190 *-------------------------------------------------------------------------
194 Arc::isDisconnected( void )
196 if( pwlArc
== 0 ) return 0;
197 if( prev
->pwlArc
== 0 ) return 0;
200 REAL
*p1
= prev
->rhead();
202 if( ((p0
[0] - p1
[0]) > ZERO
) || ((p1
[0] - p0
[0]) > ZERO
) ||
203 ((p0
[1] - p1
[1]) > ZERO
) || ((p1
[1] - p0
[1]) > ZERO
) ) {
205 _glu_dprintf( "x coord = %f %f %f\n", p0
[0], p1
[0], p0
[0] - p1
[0] );
206 _glu_dprintf( "y coord = %f %f %f\n", p0
[1], p1
[1], p0
[1] - p1
[1] );
210 /* average two points together */
211 p0
[0] = p1
[0] = (p1
[0] + p0
[0]) * 0.5;
212 p0
[1] = p1
[1] = (p1
[1] + p0
[1]) * 0.5;
217 /*-------------------------------------------------------------------------
218 * neq_vert - assert that two 2D vertices are not equal
219 *-------------------------------------------------------------------------
223 neq_vert( REAL
*v1
, REAL
*v2
)
225 return ((v1
[0] != v2
[0]) || (v1
[1] != v2
[1] )) ? 1 : 0;
228 /*-------------------------------------------------------------------------
229 * check - verify consistency of a loop, including
230 * 1) if pwl, no two consecutive vertices are identical
231 * 2) the circular link pointers are valid
232 * 3) the geometric info at the head and tail are consistent
233 *-------------------------------------------------------------------------
239 if( this == 0 ) return 1;
242 assert( (jarc
->pwlArc
!= 0) || (jarc
->bezierArc
!= 0) );
244 if (jarc
->prev
== 0 || jarc
->next
== 0) {
246 _glu_dprintf( "checkjarc:null next/prev pointer\n");
252 if (jarc
->next
->prev
!= jarc
) {
254 _glu_dprintf( "checkjarc: pointer linkage screwed up\n");
262 assert( jarc
->pwlArc
->npts
>= 1 );
263 assert( jarc
->pwlArc
->npts
< 100000 );
265 for( int i=0; i < jarc->pwlArc->npts-1; i++ )
266 assert( neq_vert( jarc->pwlArc->pts[i].param,
267 jarc->pwlArc->pts[i+1].param) );
270 if( jarc
->prev
->pwlArc
) {
271 if( jarc
->tail()[1] != jarc
->prev
->rhead()[1] ) {
273 _glu_dprintf( "checkjarc: geometric linkage screwed up 1\n");
279 if( jarc
->tail()[0] != jarc
->prev
->rhead()[0] ) {
282 _glu_dprintf( "checkjarc: geometric linkage screwed up 2\n");
289 if( jarc
->next
->pwlArc
) {
290 if( jarc
->next
->tail()[0] != jarc
->rhead()[0] ) {
292 _glu_dprintf( "checkjarc: geometric linkage screwed up 3\n");
298 if( jarc
->next
->tail()[1] != jarc
->rhead()[1] ) {
300 _glu_dprintf( "checkjarc: geometric linkage screwed up 4\n");
307 if( jarc
->isbezier() ) {
308 assert( jarc
->pwlArc
->npts
== 2 );
309 assert( (jarc
->pwlArc
->pts
[0].param
[0] == \
310 jarc
->pwlArc
->pts
[1].param
[0]) ||\
311 (jarc
->pwlArc
->pts
[0].param
[1] == \
312 jarc
->pwlArc
->pts
[1].param
[1]) );
316 } while (jarc
!= this);
323 inline long tooclose( REAL x
, REAL y
)
325 return (glu_abs(x
-y
) < TOL
) ? 1 : 0;
329 /*--------------------------------------------------------------------------
330 * append - append a jordan arc to a circularly linked list
331 *--------------------------------------------------------------------------
335 Arc::append( Arc_ptr jarc
)
340 next
->prev
= prev
->next
= this;