summaryrefslogtreecommitdiff
path: root/graphics/geist/files/patch-ad
blob: e43c0f908702e5f342bad74b70a748c5aae1f4e7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
--- src/geist_line.c.orig	Sun Oct 22 00:05:45 2000
+++ src/geist_line.c	Sat Feb 12 20:39:50 2005
@@ -406,6 +406,114 @@
 
 }
 
+/*
+ * Recent versions of Imlib2 lack imlib_clip_line() function, which was
+ * around at Imlib2-1.1.0 times.  Dig it and some related stuff from
+ * old sources and paste here, so we're buildable again with new Imlib2.
+ */
+
+enum { TOP = 0x1, BOTTOM = 0x2, RIGHT = 0x4, LEFT = 0x8 };
+
+unsigned int
+__imlib_comp_outcode(double x, double y, double xmin,
+                     double xmax, double ymin, double ymax)
+{
+   unsigned int        code = 0;
+
+   if (y > ymax)
+      code |= TOP;
+   else if (y < ymin)
+      code |= BOTTOM;
+   if (x > xmax)
+      code |= RIGHT;
+   else if (x < xmin)
+      code |= LEFT;
+   return code;
+}
+
+int
+imlib_clip_line(int x0, int y0, int x1, int y1, int xmin, int xmax, int ymin,
+                int ymax, int *clip_x0, int *clip_y0, int *clip_x1,
+                int *clip_y1)
+{
+   unsigned int        outcode0, outcode1, outcode_out;
+   unsigned char       accept = FALSE, done = FALSE;
+   double              dx0, dy0, dx1, dy1;
+
+   dx0 = x0;
+   dx1 = x1;
+   dy0 = y0;
+   dy1 = y1;
+
+   outcode0 = __imlib_comp_outcode(dx0, dy0, xmin, xmax, ymin, ymax);
+   outcode1 = __imlib_comp_outcode(dx1, dy1, xmin, xmax, ymin, ymax);
+
+   do
+     {
+        if (!(outcode0 | outcode1))
+          {
+             accept = TRUE;
+             done = TRUE;
+          }
+        else if (outcode0 & outcode1)
+           done = TRUE;
+        else
+          {
+             double              x, y;
+
+             outcode_out = outcode0 ? outcode0 : outcode1;
+             if (outcode_out & TOP)
+               {
+                  x = dx0 + (dx1 - dx0) * ((double)ymax - dy0) / (dy1 - dy0);
+                  y = ymax;
+               }
+             else if (outcode_out & BOTTOM)
+               {
+                  x = dx0 + (dx1 - dx0) * ((double)ymin - dy0) / (dy1 - dy0);
+                  y = ymin;
+               }
+             else if (outcode_out & RIGHT)
+               {
+                  y = dy0 + (dy1 - dy0) * ((double)xmax - dx0) / (dx1 - dx0);
+                  x = xmax;
+               }
+             else
+               {
+                  y = dy0 + (dy1 - dy0) * ((double)xmin - dx0) / (dx1 - dx0);
+                  x = xmin;
+               }
+             if (outcode_out == outcode0)
+               {
+                  dx0 = x;
+                  dy0 = y;
+                  outcode0 =
+                      __imlib_comp_outcode(dx0, dy0, xmin, xmax, ymin, ymax);
+               }
+             else
+               {
+                  dx1 = x;
+                  dy1 = y;
+                  outcode1 =
+                      __imlib_comp_outcode(dx1, dy1, xmin, xmax, ymin, ymax);
+               }
+          }
+     }
+   while (done == FALSE);
+
+   /* round up before converting down to ints */
+   dx0 = floor(dx0 + 0.5);
+   dx1 = floor(dx1 + 0.5);
+   dy0 = floor(dy0 + 0.5);
+   dy1 = floor(dy1 + 0.5);
+
+   *clip_x0 = dx0;
+   *clip_y0 = dy0;
+   *clip_x1 = dx1;
+   *clip_y1 = dy1;
+
+   return accept;
+}
+
 int
 geist_line_get_clipped_line(geist_line * line, int *clip_x0, int *clip_y0,
                             int *clip_x1, int *clip_y1)