Changeset 1172
 Timestamp:
 Oct 1, 2006, 12:47:41 PM (16 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

libcaca/trunk/cucul/triangle.c
r1036 r1172 92 92 int x3, int y3, char const *str) 93 93 { 94 int x, y, xa, xb, xmax, ymax; 94 int x, y, xmax, ymax; 95 long int xa, xb, sl21, sl31, sl32; 95 96 uint32_t ch; 96 97 … … 102 103 return cucul_fill_triangle(cv, x1, y1, x3, y3, x2, y2, str); 103 104 104 /* Promote precision */ 105 x1 *= 4; 106 x2 *= 4; 107 x3 *= 4; 105 ch = cucul_utf8_to_utf32(str, NULL); 106 107 /* Compute slopes and promote precision */ 108 sl21 = (y2 == y1) ? 0 : (x2  x1) * 0x1000 / (y2  y1); 109 sl31 = (y3 == y1) ? 0 : (x3  x1) * 0x1000 / (y3  y1); 110 sl32 = (y3 == y2) ? 0 : (x3  x2) * 0x1000 / (y3  y2); 111 112 x1 *= 0x1000; 113 x2 *= 0x1000; 114 x3 *= 0x1000; 108 115 109 116 xmax = cv>width  1; 110 117 ymax = cv>height  1; 111 118 112 ch = cucul_utf8_to_utf32(str, NULL);113 114 119 /* Rasterize our triangle */ 115 120 for(y = y1 < 0 ? 0 : y1; y <= y3 && y <= ymax; y++) 116 121 { 117 if(y < =y2)122 if(y < y2) 118 123 { 119 xa = (y1 == y2) ? x2 : x1 + (x2  x1) * (y  y1) / (y2 y1);120 xb = (y1 == y3) ? x3 : x1 + (x3  x1) * (y  y1) / (y3 y1);124 xa = x1 + sl21 * (y  y1); 125 xb = x1 + sl31 * (y  y1); 121 126 } 122 else 127 else if(y == y2) 123 128 { 124 xa = (y3 == y2) ? x2 : x3 + (x2  x3) * (y  y3) / (y2  y3); 125 xb = (y3 == y1) ? x1 : x3 + (x1  x3) * (y  y3) / (y1  y3); 129 xa = x2; 130 xb = (y1 == y3) ? x3 : x1 + sl31 * (y  y1); 131 } 132 else /* (y > y2) */ 133 { 134 xa = x3 + sl32 * (y  y3); 135 xb = x3 + sl31 * (y  y3); 126 136 } 127 137 128 138 if(xb < xa) 129 139 { 130 int tmp = xb; 131 xb = xa; xa = tmp; 140 long int tmp = xb; xb = xa; xa = tmp; 132 141 } 133 142 134 143 /* Rescale xa and xb, recentering the division */ 135 xa = (xa + 1) / 4;136 xb = (xb + 2) / 4;144 xa = (xa + 0x800) / 0x1000; 145 xb = (xb + 0x801) / 0x1000; 137 146 138 if(xb < 0) continue; 139 if(xa > xmax) continue; 140 if(xa < 0) xa = 0; 141 if((xb) > xmax) xb = xmax; 142 143 for(x = xa; x <= xb; x++) 147 for(x = xa < 0 ? 0 : xa; x <= xb && x <= xmax; x++) 144 148 cucul_putchar(cv, x, y, ch); 145 149 }
Note: See TracChangeset
for help on using the changeset viewer.