update dev300-m58
[ooovba.git] / agg / inc / agg_line_aa_basics.h
blob71433cb9642b748d8ff46c0fa130279a93a1635e
1 //----------------------------------------------------------------------------
2 // Anti-Grain Geometry - Version 2.3
3 // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
4 //
5 // Permission to copy, use, modify, sell and distribute this software
6 // is granted provided this copyright notice appears in all copies.
7 // This software is provided "as is" without express or implied
8 // warranty, and with no claim as to its suitability for any purpose.
9 //
10 //----------------------------------------------------------------------------
11 // Contact: mcseem@antigrain.com
12 // mcseemagg@yahoo.com
13 // http://www.antigrain.com
14 //----------------------------------------------------------------------------
15 #ifndef AGG_LINE_AA_BASICS_INCLUDED
16 #define AGG_LINE_AA_BASICS_INCLUDED
18 #include <stdlib.h>
19 #include "agg_basics.h"
21 namespace agg
24 // See Implementation agg_line_aa_basics.cpp
26 //-------------------------------------------------------------------------
27 enum
29 line_subpixel_shift = 8, //----line_subpixel_shift
30 line_subpixel_size = 1 << line_subpixel_shift, //----line_subpixel_size
31 line_subpixel_mask = line_subpixel_size - 1 //----line_subpixel_mask
34 //-------------------------------------------------------------------------
35 enum
37 line_mr_subpixel_shift = 4, //----line_mr_subpixel_shift
38 line_mr_subpixel_size = 1 << line_mr_subpixel_shift, //----line_mr_subpixel_size
39 line_mr_subpixel_mask = line_mr_subpixel_size - 1 //----line_mr_subpixel_mask
42 //------------------------------------------------------------------line_mr
43 inline int line_mr(int x)
45 return x >> ((int)line_subpixel_shift - (int)line_mr_subpixel_shift);
48 //-------------------------------------------------------------------line_hr
49 inline int line_hr(int x)
51 return x << ((int)line_subpixel_shift - (int)line_mr_subpixel_shift);
54 //---------------------------------------------------------------line_dbl_hr
55 inline int line_dbl_hr(int x)
57 return x << line_subpixel_shift;
60 //---------------------------------------------------------------line_coord
61 inline int line_coord(double x)
63 return int(x * line_subpixel_size);
66 //==========================================================line_parameters
67 struct line_parameters
69 //---------------------------------------------------------------------
70 line_parameters() {}
71 line_parameters(int x1_, int y1_, int x2_, int y2_, int len_) :
72 x1(x1_), y1(y1_), x2(x2_), y2(y2_),
73 dx(abs(x2_ - x1_)),
74 dy(abs(y2_ - y1_)),
75 sx((x2_ > x1_) ? 1 : -1),
76 sy((y2_ > y1_) ? 1 : -1),
77 vertical(dy >= dx),
78 inc(vertical ? sy : sx),
79 len(len_),
80 octant((sy & 4) | (sx & 2) | int(vertical))
84 //---------------------------------------------------------------------
85 unsigned orthogonal_quadrant() const { return s_orthogonal_quadrant[octant]; }
86 unsigned diagonal_quadrant() const { return s_diagonal_quadrant[octant]; }
88 //---------------------------------------------------------------------
89 bool same_orthogonal_quadrant(const line_parameters& lp) const
91 return s_orthogonal_quadrant[octant] == s_orthogonal_quadrant[lp.octant];
94 //---------------------------------------------------------------------
95 bool same_diagonal_quadrant(const line_parameters& lp) const
97 return s_diagonal_quadrant[octant] == s_diagonal_quadrant[lp.octant];
100 //---------------------------------------------------------------------
101 int x1, y1, x2, y2, dx, dy, sx, sy;
102 bool vertical;
103 int inc;
104 int len;
105 int octant;
107 //---------------------------------------------------------------------
108 static int8u s_orthogonal_quadrant[8];
109 static int8u s_diagonal_quadrant[8];
114 // See Implementation agg_line_aa_basics.cpp
116 //----------------------------------------------------------------bisectrix
117 void bisectrix(const line_parameters& l1,
118 const line_parameters& l2,
119 int* x, int* y);
122 //-------------------------------------------fix_degenerate_bisectrix_start
123 void inline fix_degenerate_bisectrix_start(const line_parameters& lp,
124 int* x, int* y)
126 int d = int((double(*x - lp.x2) * double(lp.y2 - lp.y1) -
127 double(*y - lp.y2) * double(lp.x2 - lp.x1)) / lp.len);
128 if(d < line_subpixel_size)
130 *x = lp.x1 + (lp.y2 - lp.y1);
131 *y = lp.y1 - (lp.x2 - lp.x1);
136 //---------------------------------------------fix_degenerate_bisectrix_end
137 void inline fix_degenerate_bisectrix_end(const line_parameters& lp,
138 int* x, int* y)
140 int d = int((double(*x - lp.x2) * double(lp.y2 - lp.y1) -
141 double(*y - lp.y2) * double(lp.x2 - lp.x1)) / lp.len);
142 if(d < line_subpixel_size)
144 *x = lp.x2 + (lp.y2 - lp.y1);
145 *y = lp.y2 - (lp.x2 - lp.x1);
152 #endif