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.
38 * $Date: 2001/03/17 00:25:40 $ $Revision: 1.1 $
39 * $Header: /home/krh/git/sync/mesa-cvs-repo/Mesa/src/glu/sgi/libnurbs/internals/arc.cc,v 1.1 2001/03/17 00:25:40 brianp Exp $
43 #include "glimports.h"
48 #include "bezierarc.h"
50 #include "simplemath.h"
52 /* local preprocessor definitions */
53 #define ZERO 0.00001/*0.000001*/
55 const int Arc::bezier_tag
= (1<<13);
56 const int Arc::arc_tag
= (1<<3);
57 const int Arc::tail_tag
= (1<<6);
59 /*--------------------------------------------------------------------------
60 * makeSide - attach a pwl arc to an arc and mark it as a border arc
61 *--------------------------------------------------------------------------
65 Arc::makeSide( PwlArc
*pwl
, arc_side side
)
68 assert( pwlArc
== 0 );
69 assert( pwl
->npts
> 0 );
70 assert( pwl
->pts
!= 0);
77 /*--------------------------------------------------------------------------
78 * numpts - count number of points on arc loop
79 *--------------------------------------------------------------------------
88 npts
+= jarc
->pwlArc
->npts
;
90 } while( jarc
!= this );
94 /*--------------------------------------------------------------------------
95 * markverts - mark each point with id of arc
96 *--------------------------------------------------------------------------
100 Arc::markverts( void )
105 TrimVertex
*p
= jarc
->pwlArc
->pts
;
106 for( int i
=0; i
<jarc
->pwlArc
->npts
; i
++ )
107 p
[i
].nuid
= jarc
->nuid
;
109 } while( jarc
!= this );
112 /*--------------------------------------------------------------------------
113 * getextrema - find axis extrema on arc loop
114 *--------------------------------------------------------------------------
118 Arc::getextrema( Arc_ptr extrema
[4] )
120 REAL leftpt
, botpt
, rightpt
, toppt
;
122 extrema
[0] = extrema
[1] = extrema
[2] = extrema
[3] = this;
124 leftpt
= rightpt
= this->tail()[0];
125 botpt
= toppt
= this->tail()[1];
127 for( Arc_ptr jarc
= this->next
; jarc
!= this; jarc
= jarc
->next
) {
128 if ( jarc
->tail()[0] < leftpt
||
129 (jarc
->tail()[0] <= leftpt
&& jarc
->rhead()[0]<=leftpt
)) {
130 leftpt
= jarc
->pwlArc
->pts
->param
[0];
133 if ( jarc
->tail()[0] > rightpt
||
134 (jarc
->tail()[0] >= rightpt
&& jarc
->rhead()[0] >= rightpt
)) {
135 rightpt
= jarc
->pwlArc
->pts
->param
[0];
138 if ( jarc
->tail()[1] < botpt
||
139 (jarc
->tail()[1] <= botpt
&& jarc
->rhead()[1] <= botpt
)) {
140 botpt
= jarc
->pwlArc
->pts
->param
[1];
143 if ( jarc
->tail()[1] > toppt
||
144 (jarc
->tail()[1] >= toppt
&& jarc
->rhead()[1] >= toppt
)) {
145 toppt
= jarc
->pwlArc
->pts
->param
[1];
152 /*-------------------------------------------------------------------------
153 * show - print to the stdout the vertices of a pwl arc
154 *-------------------------------------------------------------------------
161 dprintf( "\tPWLARC NP: %d FL: 1\n", pwlArc
->npts
);
162 for( int i
= 0; i
< pwlArc
->npts
; i
++ ) {
163 dprintf( "\t\tVERTEX %f %f\n", pwlArc
->pts
[i
].param
[0],
164 pwlArc
->pts
[i
].param
[1] );
169 /*-------------------------------------------------------------------------
170 * print - print out the vertices of all pwl arcs on a loop
171 *-------------------------------------------------------------------------
181 dprintf( "\n\nEMPTY TRIM\n\n" );
187 dprintf( "BGNTRIM\n" );
192 } while (jarc
!= this);
194 dprintf("ENDTRIM\n" );
198 /*-------------------------------------------------------------------------
199 * isDisconnected - check if tail of arc and head of prev meet
200 *-------------------------------------------------------------------------
204 Arc::isDisconnected( void )
206 if( pwlArc
== 0 ) return 0;
207 if( prev
->pwlArc
== 0 ) return 0;
210 REAL
*p1
= prev
->rhead();
212 if( ((p0
[0] - p1
[0]) > ZERO
) || ((p1
[0] - p0
[0]) > ZERO
) ||
213 ((p0
[1] - p1
[1]) > ZERO
) || ((p1
[1] - p0
[1]) > ZERO
) ) {
215 dprintf( "x coord = %f %f %f\n", p0
[0], p1
[0], p0
[0] - p1
[0] );
216 dprintf( "y coord = %f %f %f\n", p0
[1], p1
[1], p0
[1] - p1
[1] );
220 /* average two points together */
221 p0
[0] = p1
[0] = (p1
[0] + p0
[0]) * 0.5;
222 p0
[1] = p1
[1] = (p1
[1] + p0
[1]) * 0.5;
227 /*-------------------------------------------------------------------------
228 * neq_vert - assert that two 2D vertices are not equal
229 *-------------------------------------------------------------------------
233 neq_vert( REAL
*v1
, REAL
*v2
)
235 return ((v1
[0] != v2
[0]) || (v1
[1] != v2
[1] )) ? 1 : 0;
238 /*-------------------------------------------------------------------------
239 * check - verify consistency of a loop, including
240 * 1) if pwl, no two consecutive vertices are identical
241 * 2) the circular link pointers are valid
242 * 3) the geometric info at the head and tail are consistent
243 *-------------------------------------------------------------------------
249 if( this == 0 ) return 1;
252 assert( (jarc
->pwlArc
!= 0) || (jarc
->bezierArc
!= 0) );
254 if (jarc
->prev
== 0 || jarc
->next
== 0) {
256 dprintf( "checkjarc:null next/prev pointer\n");
262 if (jarc
->next
->prev
!= jarc
) {
264 dprintf( "checkjarc: pointer linkage screwed up\n");
272 assert( jarc
->pwlArc
->npts
>= 1 );
273 assert( jarc
->pwlArc
->npts
< 100000 );
275 for( int i=0; i < jarc->pwlArc->npts-1; i++ )
276 assert( neq_vert( jarc->pwlArc->pts[i].param,
277 jarc->pwlArc->pts[i+1].param) );
280 if( jarc
->prev
->pwlArc
) {
281 if( jarc
->tail()[1] != jarc
->prev
->rhead()[1] ) {
283 dprintf( "checkjarc: geometric linkage screwed up 1\n");
289 if( jarc
->tail()[0] != jarc
->prev
->rhead()[0] ) {
292 dprintf( "checkjarc: geometric linkage screwed up 2\n");
299 if( jarc
->next
->pwlArc
) {
300 if( jarc
->next
->tail()[0] != jarc
->rhead()[0] ) {
302 dprintf( "checkjarc: geometric linkage screwed up 3\n");
308 if( jarc
->next
->tail()[1] != jarc
->rhead()[1] ) {
310 dprintf( "checkjarc: geometric linkage screwed up 4\n");
317 if( jarc
->isbezier() ) {
318 assert( jarc
->pwlArc
->npts
== 2 );
319 assert( (jarc
->pwlArc
->pts
[0].param
[0] == \
320 jarc
->pwlArc
->pts
[1].param
[0]) ||\
321 (jarc
->pwlArc
->pts
[0].param
[1] == \
322 jarc
->pwlArc
->pts
[1].param
[1]) );
326 } while (jarc
!= this);
333 inline long tooclose( REAL x
, REAL y
)
335 return (abs(x
-y
) < TOL
) ? 1 : 0;
339 /*--------------------------------------------------------------------------
340 * append - append a jordan arc to a circularly linked list
341 *--------------------------------------------------------------------------
345 Arc::append( Arc_ptr jarc
)
350 next
->prev
= prev
->next
= this;