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.
40 #include "glimports.h"
43 #include "subdivider.h"
46 #include "trimvertex.h"
47 #include "simplemath.h"
50 Subdivider::bbox( TrimVertex
*a
, TrimVertex
*b
, TrimVertex
*c
, int p
)
52 return bbox( a
->param
[p
], b
->param
[p
], c
->param
[p
],
53 a
->param
[1-p
], b
->param
[1-p
], c
->param
[1-p
] );
57 Subdivider::ccwTurn_sr( Arc_ptr j1
, Arc_ptr j2
) // dir = 1
59 register TrimVertex
*v1
= &j1
->pwlArc
->pts
[j1
->pwlArc
->npts
-1];
60 register TrimVertex
*v1last
= &j1
->pwlArc
->pts
[0];
61 register TrimVertex
*v2
= &j2
->pwlArc
->pts
[0];
62 register TrimVertex
*v2last
= &j2
->pwlArc
->pts
[j2
->pwlArc
->npts
-1];
63 register TrimVertex
*v1next
= v1
-1;
64 register TrimVertex
*v2next
= v2
+1;
67 assert( v1
!= v1last
);
68 assert( v2
!= v2last
);
71 _glu_dprintf( "arc_ccw_turn, p = %d\n", 0 );
74 // the arcs lie on the line (0 == v1->param[0])
75 if( v1
->param
[0] == v1next
->param
[0] && v2
->param
[0] == v2next
->param
[0] )
78 if( v2next
->param
[0] < v2
->param
[0] || v1next
->param
[0] < v1
->param
[0] )
79 ::mylongjmp( jumpbuffer
, 28 );
81 if( v1
->param
[1] < v2
->param
[1] )
83 else if( v1
->param
[1] > v2
->param
[1] )
87 if( v1next
->param
[0] < v2next
->param
[0] ) {
89 _glu_dprintf( "case a\n" );
91 assert( v1
->param
[0] <= v1next
->param
[0] );
92 assert( v2
->param
[0] <= v1next
->param
[0] );
93 switch( bbox( v2
, v2next
, v1next
, 1 ) ) {
97 sgn
= ccw( v1next
, v2
, v2next
);
102 _glu_dprintf( "decr\n" );
107 _glu_dprintf( "no good results\n" );
109 return 0; // ill-conditioned, guess answer
116 } else if( v1next
->param
[0] > v2next
->param
[0] ) {
118 _glu_dprintf( "case b\n" );
120 assert( v1
->param
[0] <= v2next
->param
[0] );
121 assert( v2
->param
[0] <= v2next
->param
[0] );
122 switch( bbox( v1
, v1next
, v2next
, 1 ) ) {
126 sgn
= ccw( v1next
, v1
, v2next
);
131 _glu_dprintf( "incr\n" );
136 _glu_dprintf( "no good results\n" );
138 return 0; // ill-conditioned, guess answer
147 _glu_dprintf( "case ab\n" );
149 if( v1next
->param
[1] < v2next
->param
[1] )
151 else if( v1next
->param
[1] > v2next
->param
[1] )
155 _glu_dprintf( "incr\n" );
160 _glu_dprintf( "no good results\n" );
162 return 0; // ill-conditioned, guess answer
170 Subdivider::ccwTurn_sl( Arc_ptr j1
, Arc_ptr j2
) // dir = 0
172 register TrimVertex
*v1
= &j1
->pwlArc
->pts
[j1
->pwlArc
->npts
-1];
173 register TrimVertex
*v1last
= &j1
->pwlArc
->pts
[0];
174 register TrimVertex
*v2
= &j2
->pwlArc
->pts
[0];
175 register TrimVertex
*v2last
= &j2
->pwlArc
->pts
[j2
->pwlArc
->npts
-1];
176 register TrimVertex
*v1next
= v1
-1;
177 register TrimVertex
*v2next
= v2
+1;
180 assert( v1
!= v1last
);
181 assert( v2
!= v2last
);
184 _glu_dprintf( "arc_ccw_turn, p = %d\n", 0 );
187 // the arcs lie on the line (0 == v1->param[0])
188 if( v1
->param
[0] == v1next
->param
[0] && v2
->param
[0] == v2next
->param
[0] )
191 if( v2next
->param
[0] > v2
->param
[0] || v1next
->param
[0] > v1
->param
[0] )
192 ::mylongjmp( jumpbuffer
, 28 );
194 if( v1
->param
[1] < v2
->param
[1] )
196 else if( v1
->param
[1] > v2
->param
[1] )
200 if( v1next
->param
[0] > v2next
->param
[0] ) {
202 _glu_dprintf( "case c\n" );
204 assert( v1
->param
[0] >= v1next
->param
[0] );
205 assert( v2
->param
[0] >= v1next
->param
[0] );
206 switch( bbox( v2next
, v2
, v1next
, 1 ) ) {
210 sgn
= ccw( v1next
, v2
, v2next
);
216 _glu_dprintf( "decr\n" );
220 _glu_dprintf( "no good results\n" );
222 return 0; // ill-conditioned, guess answer
229 } else if( v1next
->param
[0] < v2next
->param
[0] ) {
231 _glu_dprintf( "case d\n" );
233 assert( v1
->param
[0] >= v2next
->param
[0] );
234 assert( v2
->param
[0] >= v2next
->param
[0] );
235 switch( bbox( v1next
, v1
, v2next
, 1 ) ) {
239 sgn
= ccw( v1next
, v1
, v2next
);
245 _glu_dprintf( "incr\n" );
249 _glu_dprintf( "no good results\n" );
251 return 0; // ill-conditioned, guess answer
260 _glu_dprintf( "case cd\n" );
262 if( v1next
->param
[1] < v2next
->param
[1] )
264 else if( v1next
->param
[1] > v2next
->param
[1] )
269 _glu_dprintf( "incr\n" );
273 _glu_dprintf( "no good results\n" );
275 return 0; // ill-conditioned, guess answer
283 Subdivider::ccwTurn_tr( Arc_ptr j1
, Arc_ptr j2
) // dir = 1
285 register TrimVertex
*v1
= &j1
->pwlArc
->pts
[j1
->pwlArc
->npts
-1];
286 register TrimVertex
*v1last
= &j1
->pwlArc
->pts
[0];
287 register TrimVertex
*v2
= &j2
->pwlArc
->pts
[0];
288 register TrimVertex
*v2last
= &j2
->pwlArc
->pts
[j2
->pwlArc
->npts
-1];
289 register TrimVertex
*v1next
= v1
-1;
290 register TrimVertex
*v2next
= v2
+1;
293 assert( v1
!= v1last
);
294 assert( v2
!= v2last
);
297 _glu_dprintf( "arc_ccw_turn, p = %d\n", 1 );
300 // the arcs lie on the line (1 == v1->param[1])
301 if( v1
->param
[1] == v1next
->param
[1] && v2
->param
[1] == v2next
->param
[1] )
304 if( v2next
->param
[1] < v2
->param
[1] || v1next
->param
[1] < v1
->param
[1] )
305 ::mylongjmp( jumpbuffer
, 28 );
307 if( v1
->param
[0] < v2
->param
[0] )
309 else if( v1
->param
[0] > v2
->param
[0] )
313 if( v1next
->param
[1] < v2next
->param
[1] ) {
315 _glu_dprintf( "case a\n" );
317 assert( v1
->param
[1] <= v1next
->param
[1] );
318 assert( v2
->param
[1] <= v1next
->param
[1] );
319 switch( bbox( v2
, v2next
, v1next
, 0 ) ) {
323 sgn
= ccw( v1next
, v2
, v2next
);
328 _glu_dprintf( "decr\n" );
333 _glu_dprintf( "no good results\n" );
335 return 0; // ill-conditioned, guess answer
342 } else if( v1next
->param
[1] > v2next
->param
[1] ) {
344 _glu_dprintf( "case b\n" );
346 assert( v1
->param
[1] <= v2next
->param
[1] );
347 assert( v2
->param
[1] <= v2next
->param
[1] );
348 switch( bbox( v1
, v1next
, v2next
, 0 ) ) {
352 sgn
= ccw( v1next
, v1
, v2next
);
357 _glu_dprintf( "incr\n" );
362 _glu_dprintf( "no good results\n" );
364 return 0; // ill-conditioned, guess answer
373 _glu_dprintf( "case ab\n" );
375 if( v1next
->param
[0] < v2next
->param
[0] )
377 else if( v1next
->param
[0] > v2next
->param
[0] )
381 _glu_dprintf( "incr\n" );
386 _glu_dprintf( "no good results\n" );
388 return 0; // ill-conditioned, guess answer
396 Subdivider::ccwTurn_tl( Arc_ptr j1
, Arc_ptr j2
)
398 register TrimVertex
*v1
= &j1
->pwlArc
->pts
[j1
->pwlArc
->npts
-1];
399 register TrimVertex
*v1last
= &j1
->pwlArc
->pts
[0];
400 register TrimVertex
*v2
= &j2
->pwlArc
->pts
[0];
401 register TrimVertex
*v2last
= &j2
->pwlArc
->pts
[j2
->pwlArc
->npts
-1];
402 register TrimVertex
*v1next
= v1
-1;
403 register TrimVertex
*v2next
= v2
+1;
406 assert( v1
!= v1last
);
407 assert( v2
!= v2last
);
410 _glu_dprintf( "arc_ccw_turn, p = %d\n", 1 );
413 // the arcs lie on the line (1 == v1->param[1])
414 if( v1
->param
[1] == v1next
->param
[1] && v2
->param
[1] == v2next
->param
[1] )
417 if( v2next
->param
[1] > v2
->param
[1] || v1next
->param
[1] > v1
->param
[1] )
418 ::mylongjmp( jumpbuffer
, 28 );
420 if( v1
->param
[0] < v2
->param
[0] )
422 else if( v1
->param
[0] > v2
->param
[0] )
426 if( v1next
->param
[1] > v2next
->param
[1] ) {
428 _glu_dprintf( "case c\n" );
430 assert( v1
->param
[1] >= v1next
->param
[1] );
431 assert( v2
->param
[1] >= v1next
->param
[1] );
432 switch( bbox( v2next
, v2
, v1next
, 0 ) ) {
436 sgn
= ccw( v1next
, v2
, v2next
);
442 _glu_dprintf( "decr\n" );
446 _glu_dprintf( "no good results\n" );
448 return 0; // ill-conditioned, guess answer
455 } else if( v1next
->param
[1] < v2next
->param
[1] ) {
457 _glu_dprintf( "case d\n" );
458 assert( v1
->param
[1] >= v2next
->param
[1] );
459 assert( v2
->param
[1] >= v2next
->param
[1] );
461 switch( bbox( v1next
, v1
, v2next
, 0 ) ) {
465 sgn
= ccw( v1next
, v1
, v2next
);
471 _glu_dprintf( "incr\n" );
475 _glu_dprintf( "no good results\n" );
477 return 0; // ill-conditioned, guess answer
486 _glu_dprintf( "case cd\n" );
488 if( v1next
->param
[0] < v2next
->param
[0] )
490 else if( v1next
->param
[0] > v2next
->param
[0] )
495 _glu_dprintf( "incr\n" );
499 _glu_dprintf( "no good results\n" );
501 return 0; // ill-conditioned, guess answer
511 Subdivider::bbox( register REAL sa
, register REAL sb
, register REAL sc
,
512 register REAL ta
, register REAL tb
, register REAL tc
)
515 Subdivider::bbox( register REAL sa
, register REAL sb
, register REAL sc
,
516 register REAL
, register REAL
, register REAL
)
527 } else if( sb
<= sc
) {
532 } else if( sa
> sb
) {
535 } else if( sb
>= sc
) {
543 } else if( sb
> sc
) {
551 /*----------------------------------------------------------------------------
552 * ccw - determine how three points are oriented by computing their
554 * Return 1 if the vertices are ccw oriented,
555 * 0 if they are cw oriented, or
556 * -1 if the computation is ill-conditioned.
557 *----------------------------------------------------------------------------
560 Subdivider::ccw( TrimVertex
*a
, TrimVertex
*b
, TrimVertex
*c
)
562 REAL d
= det3( a
, b
, c
);
563 if( glu_abs(d
) < 0.0001 ) return -1;
564 return (d
< 0.0) ? 0 : 1;