Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1 | pmbaty | 1 | /* |
2 | * Portions of this file are copyright Rebirth contributors and licensed as |
||
3 | * described in COPYING.txt. |
||
4 | * Portions of this file are copyright Parallax Software and licensed |
||
5 | * according to the Parallax license below. |
||
6 | * See COPYING.txt for license details. |
||
7 | |||
8 | THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX |
||
9 | SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO |
||
10 | END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A |
||
11 | ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS |
||
12 | IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS |
||
13 | SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE |
||
14 | FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE |
||
15 | CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS |
||
16 | AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE. |
||
17 | COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. |
||
18 | */ |
||
19 | /* |
||
20 | * |
||
21 | * Macros used for clipping |
||
22 | * |
||
23 | */ |
||
24 | |||
25 | |||
26 | // sort two values |
||
27 | #define SORT2(a,b) do { \ |
||
28 | using std::swap; \ |
||
29 | if((a) > (b)) swap(a,b); \ |
||
30 | } while(0) |
||
31 | |||
32 | # define FIXSCALE(var,arg,num,den) ((var) = fixmuldiv((arg),(num),(den))) |
||
33 | |||
34 | #define CLIPLINE(x1,y1,x2,y2,XMIN,YMIN,XMAX,YMAX,WHEN_OUTSIDE,WHEN_CLIPPED,MY_SCALE) do { \ |
||
35 | int temp; \ |
||
36 | if(y1 > y2) \ |
||
37 | { \ |
||
38 | using std::swap; \ |
||
39 | swap(y1,y2); swap(x1,x2); } \ |
||
40 | if((y2 < YMIN) || (y1 > YMAX)) \ |
||
41 | { WHEN_OUTSIDE; } \ |
||
42 | if(x1 < x2) { \ |
||
43 | if((x2 < XMIN) || (x1 > XMAX)) { \ |
||
44 | WHEN_OUTSIDE; \ |
||
45 | } \ |
||
46 | if(x1 < XMIN) { \ |
||
47 | MY_SCALE(temp,(y2 - y1),(XMIN - x1),(x2 - x1)); \ |
||
48 | if((y1 += temp) > YMAX) { WHEN_OUTSIDE; } \ |
||
49 | x1 = XMIN; \ |
||
50 | WHEN_CLIPPED; \ |
||
51 | } \ |
||
52 | if(x2 > XMAX) { \ |
||
53 | MY_SCALE(temp,(y2 - y1),(x2 - XMAX),(x2 - x1)); \ |
||
54 | if((y2 -= temp) < YMIN) { WHEN_OUTSIDE; } \ |
||
55 | x2 = XMAX; \ |
||
56 | WHEN_CLIPPED; \ |
||
57 | } \ |
||
58 | if(y1 < YMIN) { \ |
||
59 | MY_SCALE(temp,(x2 - x1),(YMIN - y1),(y2 - y1)); \ |
||
60 | x1 += temp; \ |
||
61 | y1 = YMIN; \ |
||
62 | WHEN_CLIPPED; \ |
||
63 | } \ |
||
64 | if(y2 > YMAX) { \ |
||
65 | MY_SCALE(temp,(x2 - x1),(y2 - YMAX),(y2 - y1)); \ |
||
66 | x2 -= temp; \ |
||
67 | y2 = YMAX; \ |
||
68 | WHEN_CLIPPED; \ |
||
69 | } \ |
||
70 | } \ |
||
71 | else { \ |
||
72 | if((x1 < XMIN) || (x2 > XMAX)) { \ |
||
73 | WHEN_OUTSIDE; \ |
||
74 | } \ |
||
75 | if(x1 > XMAX) { \ |
||
76 | MY_SCALE(temp,(y2 - y1),(x1 - XMAX),(x1 - x2)); \ |
||
77 | if((y1 += temp) > YMAX) { WHEN_OUTSIDE; } \ |
||
78 | x1 = XMAX; \ |
||
79 | WHEN_CLIPPED; \ |
||
80 | } \ |
||
81 | if(x2 < XMIN) { \ |
||
82 | MY_SCALE(temp,(y2 - y1),(XMIN - x2),(x1 - x2)); \ |
||
83 | if((y2 -= temp) < YMIN) { WHEN_OUTSIDE; } \ |
||
84 | x2 = XMIN; \ |
||
85 | WHEN_CLIPPED; \ |
||
86 | } \ |
||
87 | if(y1 < YMIN) { \ |
||
88 | MY_SCALE(temp,(x1 - x2),(YMIN - y1),(y2 - y1)); \ |
||
89 | x1 -= temp; \ |
||
90 | y1 = YMIN; \ |
||
91 | WHEN_CLIPPED; \ |
||
92 | } \ |
||
93 | if(y2 > YMAX) { \ |
||
94 | MY_SCALE(temp,(x1 - x2),(y2 - YMAX),(y2 - y1)); \ |
||
95 | x2 += temp; \ |
||
96 | y2 = YMAX; \ |
||
97 | WHEN_CLIPPED; \ |
||
98 | } \ |
||
99 | } \ |
||
100 | } while(0) |