annotate src/dmlineclip.h @ 2294:7f6ba3b32f54

Cleanups.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 03 Jul 2019 10:28:43 +0300
parents e06abfde6c39
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
264
200329bb7688 Fix the Cohen-Sutherland clipping implementation and add optional
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
1 /* Clip line coordinates. Return value:
200329bb7688 Fix the Cohen-Sutherland clipping implementation and add optional
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
2 * = 0 : No clipping needed.
200329bb7688 Fix the Cohen-Sutherland clipping implementation and add optional
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
3 * > 0 : Clipped. Line partially inside the clipping area.
200329bb7688 Fix the Cohen-Sutherland clipping implementation and add optional
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
4 * < 0 : Line completely outside the clipping area.
200329bb7688 Fix the Cohen-Sutherland clipping implementation and add optional
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
5 */
200329bb7688 Fix the Cohen-Sutherland clipping implementation and add optional
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
6
262
9d015d32841a Clean up the line clipping a bit, in preparation for fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 234
diff changeset
7 #ifndef DM_HEADER
264
200329bb7688 Fix the Cohen-Sutherland clipping implementation and add optional
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
8 #define DM_CLIP_BITS(QB, QX, QY) \
262
9d015d32841a Clean up the line clipping a bit, in preparation for fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 234
diff changeset
9 do { \
264
200329bb7688 Fix the Cohen-Sutherland clipping implementation and add optional
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
10 QB = 0; \
200329bb7688 Fix the Cohen-Sutherland clipping implementation and add optional
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
11 if (QX < clipX0) QB |= CLIP_LEFT; \
262
9d015d32841a Clean up the line clipping a bit, in preparation for fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 234
diff changeset
12 else \
264
200329bb7688 Fix the Cohen-Sutherland clipping implementation and add optional
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
13 if (QX > clipX1) QB |= CLIP_RIGHT; \
200329bb7688 Fix the Cohen-Sutherland clipping implementation and add optional
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
14 \
200329bb7688 Fix the Cohen-Sutherland clipping implementation and add optional
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
15 if (QY < clipY0) QB |= CLIP_TOP; \
262
9d015d32841a Clean up the line clipping a bit, in preparation for fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 234
diff changeset
16 else \
264
200329bb7688 Fix the Cohen-Sutherland clipping implementation and add optional
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
17 if (QY > clipY1) QB |= CLIP_BOTTOM; \
262
9d015d32841a Clean up the line clipping a bit, in preparation for fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 234
diff changeset
18 } while (0)
9d015d32841a Clean up the line clipping a bit, in preparation for fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 234
diff changeset
19
265
51ba74f7668c Make line clipping floating point only.
Matti Hamalainen <ccr@tnsp.org>
parents: 264
diff changeset
20 #define xA (fx0)
51ba74f7668c Make line clipping floating point only.
Matti Hamalainen <ccr@tnsp.org>
parents: 264
diff changeset
21 #define xB (fx1)
51ba74f7668c Make line clipping floating point only.
Matti Hamalainen <ccr@tnsp.org>
parents: 264
diff changeset
22 #define yA (fy0)
51ba74f7668c Make line clipping floating point only.
Matti Hamalainen <ccr@tnsp.org>
parents: 264
diff changeset
23 #define yB (fy1)
262
9d015d32841a Clean up the line clipping a bit, in preparation for fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 234
diff changeset
24 #endif
9d015d32841a Clean up the line clipping a bit, in preparation for fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 234
diff changeset
25
264
200329bb7688 Fix the Cohen-Sutherland clipping implementation and add optional
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
26 #ifdef DM_CLIP_DEBUG
200329bb7688 Fix the Cohen-Sutherland clipping implementation and add optional
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
27 #define CLIPDEB(fmt, ...) fprintf(stderr, fmt, __VA_ARGS__)
200329bb7688 Fix the Cohen-Sutherland clipping implementation and add optional
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
28 #else
200329bb7688 Fix the Cohen-Sutherland clipping implementation and add optional
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
29 #define CLIPDEB(fmt, ...)
200329bb7688 Fix the Cohen-Sutherland clipping implementation and add optional
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
30 #endif
232
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
31
234
a2abd0b991b6 Modularize line drawing related templates and functions, add clipping
Matti Hamalainen <ccr@tnsp.org>
parents: 232
diff changeset
32 int DM_CLIP_FUNC (SDL_Surface *screen, DM_COORD_TYPE *x0, DM_COORD_TYPE *y0, DM_COORD_TYPE *x1, DM_COORD_TYPE *y1)
a2abd0b991b6 Modularize line drawing related templates and functions, add clipping
Matti Hamalainen <ccr@tnsp.org>
parents: 232
diff changeset
33 #ifdef DM_HEADER
a2abd0b991b6 Modularize line drawing related templates and functions, add clipping
Matti Hamalainen <ccr@tnsp.org>
parents: 232
diff changeset
34 ;
a2abd0b991b6 Modularize line drawing related templates and functions, add clipping
Matti Hamalainen <ccr@tnsp.org>
parents: 232
diff changeset
35 #else
232
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
36 {
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
37 const DM_COORD_TYPE
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
38 clipX0 = screen->clip_rect.x,
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
39 clipY0 = screen->clip_rect.y,
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
40 clipX1 = clipX0 + screen->clip_rect.w - 1,
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
41 clipY1 = clipY0 + screen->clip_rect.h - 1;
265
51ba74f7668c Make line clipping floating point only.
Matti Hamalainen <ccr@tnsp.org>
parents: 264
diff changeset
42 double fx0 = *x0, fy0 = *y0, fx1 = *x1, fy1 = *y1;
262
9d015d32841a Clean up the line clipping a bit, in preparation for fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 234
diff changeset
43 int clipA, clipB;
232
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
44
262
9d015d32841a Clean up the line clipping a bit, in preparation for fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 234
diff changeset
45 DM_CLIP_BITS(clipA, xA, yA);
9d015d32841a Clean up the line clipping a bit, in preparation for fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 234
diff changeset
46 DM_CLIP_BITS(clipB, xB, yB);
232
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
47
265
51ba74f7668c Make line clipping floating point only.
Matti Hamalainen <ccr@tnsp.org>
parents: 264
diff changeset
48 CLIPDEB("-- clip [%1.3f, %1.3f - %1.3f, %1.3f] --\n", xA, yA, xB, yB);
264
200329bb7688 Fix the Cohen-Sutherland clipping implementation and add optional
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
49
200329bb7688 Fix the Cohen-Sutherland clipping implementation and add optional
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
50 #if 1
232
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
51 // Cohen-Sutherland clipping method
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
52 do
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
53 {
262
9d015d32841a Clean up the line clipping a bit, in preparation for fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 234
diff changeset
54 const int c = clipA ? clipA : clipB;
232
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
55 DM_COORD_TYPE x, y;
1102
e06abfde6c39 Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 812
diff changeset
56
265
51ba74f7668c Make line clipping floating point only.
Matti Hamalainen <ccr@tnsp.org>
parents: 264
diff changeset
57 // The segment is inside?
51ba74f7668c Make line clipping floating point only.
Matti Hamalainen <ccr@tnsp.org>
parents: 264
diff changeset
58 if ((clipA | clipB) == 0)
51ba74f7668c Make line clipping floating point only.
Matti Hamalainen <ccr@tnsp.org>
parents: 264
diff changeset
59 {
51ba74f7668c Make line clipping floating point only.
Matti Hamalainen <ccr@tnsp.org>
parents: 264
diff changeset
60 *x0 = fx0;
51ba74f7668c Make line clipping floating point only.
Matti Hamalainen <ccr@tnsp.org>
parents: 264
diff changeset
61 *y0 = fy0;
51ba74f7668c Make line clipping floating point only.
Matti Hamalainen <ccr@tnsp.org>
parents: 264
diff changeset
62 *x1 = fx1;
51ba74f7668c Make line clipping floating point only.
Matti Hamalainen <ccr@tnsp.org>
parents: 264
diff changeset
63 *y1 = fy1;
51ba74f7668c Make line clipping floating point only.
Matti Hamalainen <ccr@tnsp.org>
parents: 264
diff changeset
64 return 0;
51ba74f7668c Make line clipping floating point only.
Matti Hamalainen <ccr@tnsp.org>
parents: 264
diff changeset
65 }
51ba74f7668c Make line clipping floating point only.
Matti Hamalainen <ccr@tnsp.org>
parents: 264
diff changeset
66
51ba74f7668c Make line clipping floating point only.
Matti Hamalainen <ccr@tnsp.org>
parents: 264
diff changeset
67 // The line segment is outside of the clip region
51ba74f7668c Make line clipping floating point only.
Matti Hamalainen <ccr@tnsp.org>
parents: 264
diff changeset
68 if (clipA & clipB)
51ba74f7668c Make line clipping floating point only.
Matti Hamalainen <ccr@tnsp.org>
parents: 264
diff changeset
69 return -1;
51ba74f7668c Make line clipping floating point only.
Matti Hamalainen <ccr@tnsp.org>
parents: 264
diff changeset
70
264
200329bb7688 Fix the Cohen-Sutherland clipping implementation and add optional
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
71 #ifdef DM_CLIP_DEBUG
200329bb7688 Fix the Cohen-Sutherland clipping implementation and add optional
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
72 CLIPDEB "CLIP : ");
200329bb7688 Fix the Cohen-Sutherland clipping implementation and add optional
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
73 if (c == clipA)
265
51ba74f7668c Make line clipping floating point only.
Matti Hamalainen <ccr@tnsp.org>
parents: 264
diff changeset
74 CLIPDEB("A [%1.3f, %1.3f]\n", xA, yA);
264
200329bb7688 Fix the Cohen-Sutherland clipping implementation and add optional
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
75 else
265
51ba74f7668c Make line clipping floating point only.
Matti Hamalainen <ccr@tnsp.org>
parents: 264
diff changeset
76 CLIPDEB("B [%1.3f, %1.3f]\n", xB, yB);
264
200329bb7688 Fix the Cohen-Sutherland clipping implementation and add optional
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
77 #endif
262
9d015d32841a Clean up the line clipping a bit, in preparation for fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 234
diff changeset
78 if (c & CLIP_TOP)
232
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
79 {
265
51ba74f7668c Make line clipping floating point only.
Matti Hamalainen <ccr@tnsp.org>
parents: 264
diff changeset
80 if (yB - yA != 0)
51ba74f7668c Make line clipping floating point only.
Matti Hamalainen <ccr@tnsp.org>
parents: 264
diff changeset
81 x = xA + ((clipY0 - yA) * (xB - xA)) / (yB - yA);
51ba74f7668c Make line clipping floating point only.
Matti Hamalainen <ccr@tnsp.org>
parents: 264
diff changeset
82 else
51ba74f7668c Make line clipping floating point only.
Matti Hamalainen <ccr@tnsp.org>
parents: 264
diff changeset
83 x = xA;
264
200329bb7688 Fix the Cohen-Sutherland clipping implementation and add optional
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
84 y = clipY0;
265
51ba74f7668c Make line clipping floating point only.
Matti Hamalainen <ccr@tnsp.org>
parents: 264
diff changeset
85 CLIPDEB("TOP : %1.3f, %1.3f\n", x, y);
232
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
86 }
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
87 else
262
9d015d32841a Clean up the line clipping a bit, in preparation for fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 234
diff changeset
88 if (c & CLIP_BOTTOM)
232
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
89 {
265
51ba74f7668c Make line clipping floating point only.
Matti Hamalainen <ccr@tnsp.org>
parents: 264
diff changeset
90 if (yB - yA != 0)
51ba74f7668c Make line clipping floating point only.
Matti Hamalainen <ccr@tnsp.org>
parents: 264
diff changeset
91 x = xA + ((clipY1 - yA) * (xB - xA)) / (yB - yA);
51ba74f7668c Make line clipping floating point only.
Matti Hamalainen <ccr@tnsp.org>
parents: 264
diff changeset
92 else
51ba74f7668c Make line clipping floating point only.
Matti Hamalainen <ccr@tnsp.org>
parents: 264
diff changeset
93 x = xA;
264
200329bb7688 Fix the Cohen-Sutherland clipping implementation and add optional
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
94 y = clipY1;
265
51ba74f7668c Make line clipping floating point only.
Matti Hamalainen <ccr@tnsp.org>
parents: 264
diff changeset
95 CLIPDEB("BOTTOM : %1.3f, %1.3f\n", x, y);
232
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
96 }
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
97 else
262
9d015d32841a Clean up the line clipping a bit, in preparation for fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 234
diff changeset
98 if (c & CLIP_RIGHT)
232
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
99 {
265
51ba74f7668c Make line clipping floating point only.
Matti Hamalainen <ccr@tnsp.org>
parents: 264
diff changeset
100 if (xB - xA != 0)
51ba74f7668c Make line clipping floating point only.
Matti Hamalainen <ccr@tnsp.org>
parents: 264
diff changeset
101 y = yA + ((clipX1 - xA) * (yB - yA)) / (xB - xA);
51ba74f7668c Make line clipping floating point only.
Matti Hamalainen <ccr@tnsp.org>
parents: 264
diff changeset
102 else
51ba74f7668c Make line clipping floating point only.
Matti Hamalainen <ccr@tnsp.org>
parents: 264
diff changeset
103 y = yA;
264
200329bb7688 Fix the Cohen-Sutherland clipping implementation and add optional
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
104 x = clipX1;
265
51ba74f7668c Make line clipping floating point only.
Matti Hamalainen <ccr@tnsp.org>
parents: 264
diff changeset
105 CLIPDEB("RIGHT : %1.3f, %1.3f\n", x, y);
232
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
106 }
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
107 else
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
108 {
265
51ba74f7668c Make line clipping floating point only.
Matti Hamalainen <ccr@tnsp.org>
parents: 264
diff changeset
109 if (xB - xA != 0)
266
4ad2b9739c4a Fix a stupid bug in the clipping.
Matti Hamalainen <ccr@tnsp.org>
parents: 265
diff changeset
110 y = yA + ((clipX0 - xA) * (yB - yA)) / (xB - xA);
265
51ba74f7668c Make line clipping floating point only.
Matti Hamalainen <ccr@tnsp.org>
parents: 264
diff changeset
111 else
51ba74f7668c Make line clipping floating point only.
Matti Hamalainen <ccr@tnsp.org>
parents: 264
diff changeset
112 y = yA;
264
200329bb7688 Fix the Cohen-Sutherland clipping implementation and add optional
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
113 x = clipX0;
265
51ba74f7668c Make line clipping floating point only.
Matti Hamalainen <ccr@tnsp.org>
parents: 264
diff changeset
114 CLIPDEB("LEFT : %1.3f, %1.3f\n", x, y);
232
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
115 }
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
116
262
9d015d32841a Clean up the line clipping a bit, in preparation for fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 234
diff changeset
117 if (c == clipA)
232
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
118 {
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
119 xA = x;
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
120 yA = y;
262
9d015d32841a Clean up the line clipping a bit, in preparation for fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 234
diff changeset
121 DM_CLIP_BITS(clipA, xA, yA);
232
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
122 }
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
123 else
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
124 {
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
125 xB = x;
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
126 yB = y;
262
9d015d32841a Clean up the line clipping a bit, in preparation for fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 234
diff changeset
127 DM_CLIP_BITS(clipB, xB, yB);
232
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
128 }
1102
e06abfde6c39 Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 812
diff changeset
129
265
51ba74f7668c Make line clipping floating point only.
Matti Hamalainen <ccr@tnsp.org>
parents: 264
diff changeset
130 } while (1);
232
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
131 #else
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
132 // Buyu-Skala clipping method
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
133 const DM_COORD_TYPE dx = xB - xA;
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
134 const DM_COORD_TYPE dy = yB - yA;
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
135 float k, m;
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
136 int z;
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
137
262
9d015d32841a Clean up the line clipping a bit, in preparation for fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 234
diff changeset
138 switch (clipA + clipB)
232
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
139 {
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
140 case 1:
262
9d015d32841a Clean up the line clipping a bit, in preparation for fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 234
diff changeset
141 if (clipA == 1)
232
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
142 {
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
143 xA = clipX0;
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
144 yA = (clipX0 - xB) * dy / dx + yB;
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
145 }
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
146 else
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
147 {
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
148 xB = clipX0;
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
149 yB = (clipX0 - xA) * dy / dx + yA;
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
150 }
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
151 break;
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
152
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
153 case 3:
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
154 k = dy / dx;
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
155 yA = (clipX0 - xA) * k + yA;
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
156 xA = clipX0;
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
157 yB = (clipX1 - xB) * k + yB;
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
158 xB = clipX1;
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
159 break;
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
160
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
161 case 5:
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
162 k = dy / dx;
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
163 z = (clipX0 - xA) * k + yA;
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
164 if (z < clipY0)
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
165 {
262
9d015d32841a Clean up the line clipping a bit, in preparation for fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 234
diff changeset
166 switch (clipA)
232
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
167 {
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
168 case 0:
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
169 xB = xB + (clipY0 - yB) / k;
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
170 yB = clipY0;
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
171 break;
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
172 case 5:
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
173 xA = xA + (clipY0 - yA) / k;
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
174 yA = clipY0;
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
175 break;
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
176
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
177 default:
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
178 return -1; /* the line segment is outside */
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
179 }
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
180 }
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
181 else
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
182 {
262
9d015d32841a Clean up the line clipping a bit, in preparation for fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 234
diff changeset
183 switch (clipA)
232
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
184 {
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
185 case 0:
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
186 xB = clipX0;
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
187 yB = z;
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
188 break;
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
189 case 1:
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
190 xB = xB + (clipY0 - yB) / k;
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
191 yB = clipY0;
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
192 xA = clipX0;
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
193 yA = z;
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
194 break;
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
195 case 4:
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
196 xA = xA + (clipY0 - yA) / k;
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
197 yA = clipY0;
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
198 xB = clipX0;
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
199 yB = z;
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
200 break;
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
201 case 5:
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
202 xA = clipX0;
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
203 yA = z;
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
204 break;
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
205 }
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
206 }
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
207 break;
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
208
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
209 case 7:
262
9d015d32841a Clean up the line clipping a bit, in preparation for fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 234
diff changeset
210 switch (clipA)
232
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
211 {
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
212 case 1:
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
213 k = dy / dx;
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
214 yA = (clipX0 - xB) * k + yB;
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
215 if (yA < clipY0)
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
216 return -1; /* the line segment is outside */
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
217 xA = clipX0;
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
218 yB = (clipX1 - clipX0) * k + yA;
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
219 if (yB < clipY0)
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
220 {
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
221 xB = (clipY0 - yB) / k + clipX1;
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
222 yB = clipY0;
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
223 }
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
224 else
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
225 xB = clipX1;
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
226 break;
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
227
262
9d015d32841a Clean up the line clipping a bit, in preparation for fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 234
diff changeset
228 /* similarly for cases clipA == 2, 5, 6 */
232
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
229 }
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
230 case 15:
262
9d015d32841a Clean up the line clipping a bit, in preparation for fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 234
diff changeset
231 switch (clipA)
232
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
232 {
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
233 case 5:
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
234 if (dy * (clipX1 - clipX0) < dx * (clipY1 - clipY0))
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
235 {
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
236 k = dy / dx;
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
237 yA = (clipX0 - xB) * k + yB;
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
238 if (yA > clipY1)
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
239 return -1; /* the line segment is outside */
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
240 yB = (clipX1 - clipX0) * k + yA;
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
241 if (yB < clipY0)
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
242 return -1; /* the line segment is outside */
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
243 if (yA < clipY0)
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
244 {
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
245 xA = (clipY0 - yA) / k + clipX0;
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
246 yA = clipY0;
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
247 xB = clipX1;
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
248 }
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
249 else
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
250 {
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
251 xA = clipX0;
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
252 if (yB > clipY1)
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
253 {
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
254 xB = (clipY1 - yB) / k + clipX1;
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
255 yB = clipY1;
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
256 }
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
257 else
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
258 xB = clipX1;
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
259 }
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
260 }
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
261 else
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
262 {
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
263 m = dx / dy;
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
264 xA = (clipY0 - yB) * m + xB;
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
265 if (xA > clipX1)
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
266 return -1; /* the line segment is outside */
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
267 xB = (clipY1 - clipY0) * m + xA;
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
268 if (xB < clipX0)
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
269 return -1; /* the line segment is outside */
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
270 if (xA < clipX0)
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
271 {
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
272 yA = (clipX0 - xA) / m + clipY0;
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
273 xA = clipX0;
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
274 yB = clipY1;
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
275 }
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
276 else
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
277 {
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
278 yA = clipY0;
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
279 if (xB > clipX1)
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
280 {
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
281 yB = (clipX1 - xB) / m + clipY1;
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
282 xB = clipX1;
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
283 }
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
284 else
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
285 yB = clipY1;
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
286 }
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
287 }
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
288
262
9d015d32841a Clean up the line clipping a bit, in preparation for fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 234
diff changeset
289 /* similarly for cases clipA == 6, 9, 10 */
232
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
290 }
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
291
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
292 /* cases 2, 4, 8 are similar as case 1, cases 6, 9, 10 are similar as case 5 */
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
293 /* cases 11, 13, 14 are similar as case 7, case 12 is similar case 3 */
262
9d015d32841a Clean up the line clipping a bit, in preparation for fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 234
diff changeset
294 } /* of case clipA + clipB */
232
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
295 #endif
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
296
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
297 return 1;
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
298 }
262
9d015d32841a Clean up the line clipping a bit, in preparation for fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 234
diff changeset
299
9d015d32841a Clean up the line clipping a bit, in preparation for fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 234
diff changeset
300 #undef DM_CLIP_BITS
9d015d32841a Clean up the line clipping a bit, in preparation for fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 234
diff changeset
301 #undef xA
9d015d32841a Clean up the line clipping a bit, in preparation for fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 234
diff changeset
302 #undef xB
9d015d32841a Clean up the line clipping a bit, in preparation for fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 234
diff changeset
303 #undef yA
9d015d32841a Clean up the line clipping a bit, in preparation for fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 234
diff changeset
304 #undef yB
264
200329bb7688 Fix the Cohen-Sutherland clipping implementation and add optional
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
305 #undef CLIPDEB
234
a2abd0b991b6 Modularize line drawing related templates and functions, add clipping
Matti Hamalainen <ccr@tnsp.org>
parents: 232
diff changeset
306 #endif
232
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
307
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
308 #undef DM_CLIP_FUNC
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
309 #undef DM_COORD_TYPE