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$ $Revision: 1.1 $
39 * $Header: /cygdrive/c/RCVS/CVS/ReactOS/reactos/lib/glu32/libnurbs/internals/ccw.cc,v 1.1 2004/02/02 16:39:11 navaraf Exp $
42 #include "glimports.h"
45 #include "subdivider.h"
48 #include "trimvertex.h"
49 #include "simplemath.h"
52 Subdivider::bbox( TrimVertex
*a
, TrimVertex
*b
, TrimVertex
*c
, int p
)
54 return bbox( a
->param
[p
], b
->param
[p
], c
->param
[p
],
55 a
->param
[1-p
], b
->param
[1-p
], c
->param
[1-p
] );
59 Subdivider::ccwTurn_sr( Arc_ptr j1
, Arc_ptr j2
) // dir = 1
61 register TrimVertex
*v1
= &j1
->pwlArc
->pts
[j1
->pwlArc
->npts
-1];
62 register TrimVertex
*v1last
= &j1
->pwlArc
->pts
[0];
63 register TrimVertex
*v2
= &j2
->pwlArc
->pts
[0];
64 register TrimVertex
*v2last
= &j2
->pwlArc
->pts
[j2
->pwlArc
->npts
-1];
65 register TrimVertex
*v1next
= v1
-1;
66 register TrimVertex
*v2next
= v2
+1;
69 assert( v1
!= v1last
);
70 assert( v2
!= v2last
);
73 dprintf( "arc_ccw_turn, p = %d\n", 0 );
76 // the arcs lie on the line (0 == v1->param[0])
77 if( v1
->param
[0] == v1next
->param
[0] && v2
->param
[0] == v2next
->param
[0] )
80 if( v2next
->param
[0] < v2
->param
[0] || v1next
->param
[0] < v1
->param
[0] )
81 ::mylongjmp( jumpbuffer
, 28 );
83 if( v1
->param
[1] < v2
->param
[1] )
85 else if( v1
->param
[1] > v2
->param
[1] )
89 if( v1next
->param
[0] < v2next
->param
[0] ) {
91 dprintf( "case a\n" );
93 assert( v1
->param
[0] <= v1next
->param
[0] );
94 assert( v2
->param
[0] <= v1next
->param
[0] );
95 switch( bbox( v2
, v2next
, v1next
, 1 ) ) {
99 sgn
= ccw( v1next
, v2
, v2next
);
109 dprintf( "no good results\n" );
111 return 0; // ill-conditioned, guess answer
118 } else if( v1next
->param
[0] > v2next
->param
[0] ) {
120 dprintf( "case b\n" );
122 assert( v1
->param
[0] <= v2next
->param
[0] );
123 assert( v2
->param
[0] <= v2next
->param
[0] );
124 switch( bbox( v1
, v1next
, v2next
, 1 ) ) {
128 sgn
= ccw( v1next
, v1
, v2next
);
138 dprintf( "no good results\n" );
140 return 0; // ill-conditioned, guess answer
149 dprintf( "case ab\n" );
151 if( v1next
->param
[1] < v2next
->param
[1] )
153 else if( v1next
->param
[1] > v2next
->param
[1] )
162 dprintf( "no good results\n" );
164 return 0; // ill-conditioned, guess answer
172 Subdivider::ccwTurn_sl( Arc_ptr j1
, Arc_ptr j2
) // dir = 0
174 register TrimVertex
*v1
= &j1
->pwlArc
->pts
[j1
->pwlArc
->npts
-1];
175 register TrimVertex
*v1last
= &j1
->pwlArc
->pts
[0];
176 register TrimVertex
*v2
= &j2
->pwlArc
->pts
[0];
177 register TrimVertex
*v2last
= &j2
->pwlArc
->pts
[j2
->pwlArc
->npts
-1];
178 register TrimVertex
*v1next
= v1
-1;
179 register TrimVertex
*v2next
= v2
+1;
182 assert( v1
!= v1last
);
183 assert( v2
!= v2last
);
186 dprintf( "arc_ccw_turn, p = %d\n", 0 );
189 // the arcs lie on the line (0 == v1->param[0])
190 if( v1
->param
[0] == v1next
->param
[0] && v2
->param
[0] == v2next
->param
[0] )
193 if( v2next
->param
[0] > v2
->param
[0] || v1next
->param
[0] > v1
->param
[0] )
194 ::mylongjmp( jumpbuffer
, 28 );
196 if( v1
->param
[1] < v2
->param
[1] )
198 else if( v1
->param
[1] > v2
->param
[1] )
202 if( v1next
->param
[0] > v2next
->param
[0] ) {
204 dprintf( "case c\n" );
206 assert( v1
->param
[0] >= v1next
->param
[0] );
207 assert( v2
->param
[0] >= v1next
->param
[0] );
208 switch( bbox( v2next
, v2
, v1next
, 1 ) ) {
212 sgn
= ccw( v1next
, v2
, v2next
);
222 dprintf( "no good results\n" );
224 return 0; // ill-conditioned, guess answer
231 } else if( v1next
->param
[0] < v2next
->param
[0] ) {
233 dprintf( "case d\n" );
235 assert( v1
->param
[0] >= v2next
->param
[0] );
236 assert( v2
->param
[0] >= v2next
->param
[0] );
237 switch( bbox( v1next
, v1
, v2next
, 1 ) ) {
241 sgn
= ccw( v1next
, v1
, v2next
);
251 dprintf( "no good results\n" );
253 return 0; // ill-conditioned, guess answer
262 dprintf( "case cd\n" );
264 if( v1next
->param
[1] < v2next
->param
[1] )
266 else if( v1next
->param
[1] > v2next
->param
[1] )
275 dprintf( "no good results\n" );
277 return 0; // ill-conditioned, guess answer
285 Subdivider::ccwTurn_tr( Arc_ptr j1
, Arc_ptr j2
) // dir = 1
287 register TrimVertex
*v1
= &j1
->pwlArc
->pts
[j1
->pwlArc
->npts
-1];
288 register TrimVertex
*v1last
= &j1
->pwlArc
->pts
[0];
289 register TrimVertex
*v2
= &j2
->pwlArc
->pts
[0];
290 register TrimVertex
*v2last
= &j2
->pwlArc
->pts
[j2
->pwlArc
->npts
-1];
291 register TrimVertex
*v1next
= v1
-1;
292 register TrimVertex
*v2next
= v2
+1;
295 assert( v1
!= v1last
);
296 assert( v2
!= v2last
);
299 dprintf( "arc_ccw_turn, p = %d\n", 1 );
302 // the arcs lie on the line (1 == v1->param[1])
303 if( v1
->param
[1] == v1next
->param
[1] && v2
->param
[1] == v2next
->param
[1] )
306 if( v2next
->param
[1] < v2
->param
[1] || v1next
->param
[1] < v1
->param
[1] )
307 ::mylongjmp( jumpbuffer
, 28 );
309 if( v1
->param
[0] < v2
->param
[0] )
311 else if( v1
->param
[0] > v2
->param
[0] )
315 if( v1next
->param
[1] < v2next
->param
[1] ) {
317 dprintf( "case a\n" );
319 assert( v1
->param
[1] <= v1next
->param
[1] );
320 assert( v2
->param
[1] <= v1next
->param
[1] );
321 switch( bbox( v2
, v2next
, v1next
, 0 ) ) {
325 sgn
= ccw( v1next
, v2
, v2next
);
335 dprintf( "no good results\n" );
337 return 0; // ill-conditioned, guess answer
344 } else if( v1next
->param
[1] > v2next
->param
[1] ) {
346 dprintf( "case b\n" );
348 assert( v1
->param
[1] <= v2next
->param
[1] );
349 assert( v2
->param
[1] <= v2next
->param
[1] );
350 switch( bbox( v1
, v1next
, v2next
, 0 ) ) {
354 sgn
= ccw( v1next
, v1
, v2next
);
364 dprintf( "no good results\n" );
366 return 0; // ill-conditioned, guess answer
375 dprintf( "case ab\n" );
377 if( v1next
->param
[0] < v2next
->param
[0] )
379 else if( v1next
->param
[0] > v2next
->param
[0] )
388 dprintf( "no good results\n" );
390 return 0; // ill-conditioned, guess answer
398 Subdivider::ccwTurn_tl( Arc_ptr j1
, Arc_ptr j2
)
400 register TrimVertex
*v1
= &j1
->pwlArc
->pts
[j1
->pwlArc
->npts
-1];
401 register TrimVertex
*v1last
= &j1
->pwlArc
->pts
[0];
402 register TrimVertex
*v2
= &j2
->pwlArc
->pts
[0];
403 register TrimVertex
*v2last
= &j2
->pwlArc
->pts
[j2
->pwlArc
->npts
-1];
404 register TrimVertex
*v1next
= v1
-1;
405 register TrimVertex
*v2next
= v2
+1;
408 assert( v1
!= v1last
);
409 assert( v2
!= v2last
);
412 dprintf( "arc_ccw_turn, p = %d\n", 1 );
415 // the arcs lie on the line (1 == v1->param[1])
416 if( v1
->param
[1] == v1next
->param
[1] && v2
->param
[1] == v2next
->param
[1] )
419 if( v2next
->param
[1] > v2
->param
[1] || v1next
->param
[1] > v1
->param
[1] )
420 ::mylongjmp( jumpbuffer
, 28 );
422 if( v1
->param
[0] < v2
->param
[0] )
424 else if( v1
->param
[0] > v2
->param
[0] )
428 if( v1next
->param
[1] > v2next
->param
[1] ) {
430 dprintf( "case c\n" );
432 assert( v1
->param
[1] >= v1next
->param
[1] );
433 assert( v2
->param
[1] >= v1next
->param
[1] );
434 switch( bbox( v2next
, v2
, v1next
, 0 ) ) {
438 sgn
= ccw( v1next
, v2
, v2next
);
448 dprintf( "no good results\n" );
450 return 0; // ill-conditioned, guess answer
457 } else if( v1next
->param
[1] < v2next
->param
[1] ) {
459 dprintf( "case d\n" );
460 assert( v1
->param
[1] >= v2next
->param
[1] );
461 assert( v2
->param
[1] >= v2next
->param
[1] );
463 switch( bbox( v1next
, v1
, v2next
, 0 ) ) {
467 sgn
= ccw( v1next
, v1
, v2next
);
477 dprintf( "no good results\n" );
479 return 0; // ill-conditioned, guess answer
488 dprintf( "case cd\n" );
490 if( v1next
->param
[0] < v2next
->param
[0] )
492 else if( v1next
->param
[0] > v2next
->param
[0] )
501 dprintf( "no good results\n" );
503 return 0; // ill-conditioned, guess answer
513 Subdivider::bbox( register REAL sa
, register REAL sb
, register REAL sc
,
514 register REAL ta
, register REAL tb
, register REAL tc
)
517 Subdivider::bbox( register REAL sa
, register REAL sb
, register REAL sc
,
518 register REAL
, register REAL
, register REAL
)
529 } else if( sb
<= sc
) {
534 } else if( sa
> sb
) {
537 } else if( sb
>= sc
) {
545 } else if( sb
> sc
) {
553 /*----------------------------------------------------------------------------
554 * ccw - determine how three points are oriented by computing their
556 * Return 1 if the vertices are ccw oriented,
557 * 0 if they are cw oriented, or
558 * -1 if the computation is ill-conditioned.
559 *----------------------------------------------------------------------------
562 Subdivider::ccw( TrimVertex
*a
, TrimVertex
*b
, TrimVertex
*c
)
564 REAL d
= det3( a
, b
, c
);
565 if( glu_abs(d
) < 0.0001 ) return -1;
566 return (d
< 0.0) ? 0 : 1;