15 #ifndef AGG_RASTERIZER_SL_CLIP_INCLUDED 16 #define AGG_RASTERIZER_SL_CLIP_INCLUDED 18 #include "agg_clip_liang_barsky.h" 25 poly_max_coord = (1 << 30) - 1
31 typedef int coord_type;
32 static AGG_INLINE
int mul_div(
double a,
double b,
double c)
34 return iround(a * b / c);
36 static int xi(
int v) {
return v; }
37 static int yi(
int v) {
return v; }
38 static int upscale(
double v) {
return iround(v * poly_subpixel_scale); }
39 static int downscale(
int v) {
return v; }
45 typedef int coord_type;
46 static AGG_INLINE
int mul_div(
double a,
double b,
double c)
50 static int xi(
int v) {
return v; }
51 static int yi(
int v) {
return v; }
52 static int upscale(
double v)
56 static int downscale(
int v) {
return v; }
62 typedef int coord_type;
63 static AGG_INLINE
int mul_div(
double a,
double b,
double c)
65 return iround(a * b / c);
67 static int xi(
int v) {
return v * 3; }
68 static int yi(
int v) {
return v; }
69 static int upscale(
double v) {
return iround(v * poly_subpixel_scale); }
70 static int downscale(
int v) {
return v; }
76 typedef double coord_type;
77 static AGG_INLINE
double mul_div(
double a,
double b,
double c)
81 static int xi(
double v) {
return iround(v * poly_subpixel_scale); }
82 static int yi(
double v) {
return iround(v * poly_subpixel_scale); }
83 static double upscale(
double v) {
return v; }
84 static double downscale(
int v) {
return v / double(poly_subpixel_scale); }
90 typedef double coord_type;
91 static AGG_INLINE
double mul_div(
double a,
double b,
double c)
95 static int xi(
double v) {
return iround(v * poly_subpixel_scale * 3); }
96 static int yi(
double v) {
return iround(v * poly_subpixel_scale); }
97 static double upscale(
double v) {
return v; }
98 static double downscale(
int v) {
return v / double(poly_subpixel_scale); }
109 typedef Conv conv_type;
110 typedef typename Conv::coord_type coord_type;
123 void reset_clipping()
129 void clip_box(coord_type x1, coord_type y1, coord_type x2, coord_type y2)
131 m_clip_box = rect_type(x1, y1, x2, y2);
132 m_clip_box.normalize();
137 void move_to(coord_type x1, coord_type y1)
141 if(m_clipping) m_f1 = clipping_flags(x1, y1, m_clip_box);
146 template<
class Rasterizer>
147 AGG_INLINE
void line_clip_y(Rasterizer& ras,
148 coord_type x1, coord_type y1,
149 coord_type x2, coord_type y2,
150 unsigned f1,
unsigned f2)
const 157 ras.line(Conv::xi(x1), Conv::yi(y1), Conv::xi(x2), Conv::yi(y2));
174 tx1 = x1 + Conv::mul_div(m_clip_box.y1-y1, x2-x1, y2-y1);
180 tx1 = x1 + Conv::mul_div(m_clip_box.y2-y1, x2-x1, y2-y1);
186 tx2 = x1 + Conv::mul_div(m_clip_box.y1-y1, x2-x1, y2-y1);
192 tx2 = x1 + Conv::mul_div(m_clip_box.y2-y1, x2-x1, y2-y1);
195 ras.line(Conv::xi(tx1), Conv::yi(ty1),
196 Conv::xi(tx2), Conv::yi(ty2));
203 template<
class Rasterizer>
204 void line_to(Rasterizer& ras, coord_type x2, coord_type y2)
208 unsigned f2 = clipping_flags(x2, y2, m_clip_box);
210 if((m_f1 & 10) == (f2 & 10) && (m_f1 & 10) != 0)
219 coord_type x1 = m_x1;
220 coord_type y1 = m_y1;
225 switch(((f1 & 5) << 1) | (f2 & 5))
228 line_clip_y(ras, x1, y1, x2, y2, f1, f2);
232 y3 = y1 + Conv::mul_div(m_clip_box.x2-x1, y2-y1, x2-x1);
233 f3 = clipping_flags_y(y3, m_clip_box);
234 line_clip_y(ras, x1, y1, m_clip_box.x2, y3, f1, f3);
235 line_clip_y(ras, m_clip_box.x2, y3, m_clip_box.x2, y2, f3, f2);
239 y3 = y1 + Conv::mul_div(m_clip_box.x2-x1, y2-y1, x2-x1);
240 f3 = clipping_flags_y(y3, m_clip_box);
241 line_clip_y(ras, m_clip_box.x2, y1, m_clip_box.x2, y3, f1, f3);
242 line_clip_y(ras, m_clip_box.x2, y3, x2, y2, f3, f2);
246 line_clip_y(ras, m_clip_box.x2, y1, m_clip_box.x2, y2, f1, f2);
250 y3 = y1 + Conv::mul_div(m_clip_box.x1-x1, y2-y1, x2-x1);
251 f3 = clipping_flags_y(y3, m_clip_box);
252 line_clip_y(ras, x1, y1, m_clip_box.x1, y3, f1, f3);
253 line_clip_y(ras, m_clip_box.x1, y3, m_clip_box.x1, y2, f3, f2);
257 y3 = y1 + Conv::mul_div(m_clip_box.x2-x1, y2-y1, x2-x1);
258 y4 = y1 + Conv::mul_div(m_clip_box.x1-x1, y2-y1, x2-x1);
259 f3 = clipping_flags_y(y3, m_clip_box);
260 f4 = clipping_flags_y(y4, m_clip_box);
261 line_clip_y(ras, m_clip_box.x2, y1, m_clip_box.x2, y3, f1, f3);
262 line_clip_y(ras, m_clip_box.x2, y3, m_clip_box.x1, y4, f3, f4);
263 line_clip_y(ras, m_clip_box.x1, y4, m_clip_box.x1, y2, f4, f2);
267 y3 = y1 + Conv::mul_div(m_clip_box.x1-x1, y2-y1, x2-x1);
268 f3 = clipping_flags_y(y3, m_clip_box);
269 line_clip_y(ras, m_clip_box.x1, y1, m_clip_box.x1, y3, f1, f3);
270 line_clip_y(ras, m_clip_box.x1, y3, x2, y2, f3, f2);
274 y3 = y1 + Conv::mul_div(m_clip_box.x1-x1, y2-y1, x2-x1);
275 y4 = y1 + Conv::mul_div(m_clip_box.x2-x1, y2-y1, x2-x1);
276 f3 = clipping_flags_y(y3, m_clip_box);
277 f4 = clipping_flags_y(y4, m_clip_box);
278 line_clip_y(ras, m_clip_box.x1, y1, m_clip_box.x1, y3, f1, f3);
279 line_clip_y(ras, m_clip_box.x1, y3, m_clip_box.x2, y4, f3, f4);
280 line_clip_y(ras, m_clip_box.x2, y4, m_clip_box.x2, y2, f4, f2);
284 line_clip_y(ras, m_clip_box.x1, y1, m_clip_box.x1, y2, f1, f2);
291 ras.line(Conv::xi(m_x1), Conv::yi(m_y1),
292 Conv::xi(x2), Conv::yi(y2));
300 rect_type m_clip_box;
315 typedef int coord_type;
319 void reset_clipping() {}
320 void clip_box(coord_type, coord_type, coord_type, coord_type) {}
321 void move_to(coord_type x1, coord_type y1) { m_x1 = x1; m_y1 = y1; }
323 template<
class Rasterizer>
324 void line_to(Rasterizer& ras, coord_type x2, coord_type y2)
326 ras.line(m_x1, m_y1, x2, y2);