00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef AGG_BASICS_INCLUDED
00017 #define AGG_BASICS_INCLUDED
00018
00022 namespace agg
00023 {
00024
00025 typedef signed char int8;
00026 typedef unsigned char int8u;
00027 typedef signed short int16;
00028 typedef unsigned short int16u;
00029 typedef signed int int32;
00030 typedef unsigned int int32u;
00031
00032
00033
00034 typedef unsigned char cover_type;
00035 enum
00036 {
00037 cover_shift = 8,
00038 cover_size = 1 << cover_shift,
00039 cover_mask = cover_size - 1,
00040 cover_none = 0,
00041 cover_full = cover_mask
00042 };
00043
00044
00045
00046 const double pi = 3.14159265358979323846;
00047
00048
00049 inline double deg2rad(double deg)
00050 {
00051 return deg * pi / 180.0;
00052 }
00053
00054
00055 inline double rad2deg(double rad)
00056 {
00057 return rad * 180.0 / pi;
00058 }
00059
00060
00061 template<class T> struct rect_base
00062 {
00063 typedef rect_base<T> self_type;
00064 T x1;
00065 T y1;
00066 T x2;
00067 T y2;
00068
00069 rect_base() {}
00070 rect_base(T x1_, T y1_, T x2_, T y2_) :
00071 x1(x1_), y1(y1_), x2(x2_), y2(y2_) {}
00072
00073 const self_type& normalize()
00074 {
00075 T t;
00076 if(x1 > x2) { t = x1; x1 = x2; x2 = t; }
00077 if(y1 > y2) { t = y1; y1 = y2; y2 = t; }
00078 return *this;
00079 }
00080
00081 bool clip(const self_type& r)
00082 {
00083 if(x2 > r.x2) x2 = r.x2;
00084 if(y2 > r.y2) y2 = r.y2;
00085 if(x1 < r.x1) x1 = r.x1;
00086 if(y1 < r.y1) y1 = r.y1;
00087 return x1 <= x2 && y1 <= y2;
00088 }
00089
00090 bool is_valid() const
00091 {
00092 return x1 <= x2 && y1 <= y2;
00093 }
00094 };
00095
00096
00097 template<class Rect>
00098 inline Rect intersect_rectangles(const Rect& r1, const Rect& r2)
00099 {
00100 Rect r = r1;
00101
00102
00103
00104
00105
00106
00107 if(r.x2 > r2.x2) r.x2 = r2.x2;
00108 if(r.y2 > r2.y2) r.y2 = r2.y2;
00109 if(r.x1 < r2.x1) r.x1 = r2.x1;
00110 if(r.y1 < r2.y1) r.y1 = r2.y1;
00111 return r;
00112 }
00113
00114
00115
00116 template<class Rect>
00117 inline Rect unite_rectangles(const Rect& r1, const Rect& r2)
00118 {
00119 Rect r = r1;
00120 if(r.x2 < r2.x2) r.x2 = r2.x2;
00121 if(r.y2 < r2.y2) r.y2 = r2.y2;
00122 if(r.x1 > r2.x1) r.x1 = r2.x1;
00123 if(r.y1 > r2.y1) r.y1 = r2.y1;
00124 return r;
00125 }
00126
00127 typedef rect_base<int> rect;
00128 typedef rect_base<double> rect_d;
00129
00130
00131 enum path_commands_e
00132 {
00133 path_cmd_stop = 0,
00134 path_cmd_move_to = 1,
00135 path_cmd_line_to = 2,
00136 path_cmd_curve3 = 3,
00137 path_cmd_curve4 = 4,
00138 path_cmd_end_poly = 6,
00139 path_cmd_mask = 0x0F
00140 };
00141
00142
00143 enum path_flags_e
00144 {
00145 path_flags_none = 0,
00146 path_flags_ccw = 0x10,
00147 path_flags_cw = 0x20,
00148 path_flags_close = 0x40,
00149 path_flags_mask = 0xF0
00150 };
00151
00152
00153 inline bool is_vertex(unsigned c)
00154 {
00155 return c >= path_cmd_move_to && c < path_cmd_end_poly;
00156 }
00157
00158
00159 inline bool is_stop(unsigned c)
00160 {
00161 return c == path_cmd_stop;
00162 }
00163
00164
00165 inline bool is_move_to(unsigned c)
00166 {
00167 return c == path_cmd_move_to;
00168 }
00169
00170
00171 inline bool is_line_to(unsigned c)
00172 {
00173 return c == path_cmd_line_to;
00174 }
00175
00176
00177 inline bool is_curve(unsigned c)
00178 {
00179 return c == path_cmd_curve3 || c == path_cmd_curve4;
00180 }
00181
00182
00183 inline bool is_curve3(unsigned c)
00184 {
00185 return c == path_cmd_curve3;
00186 }
00187
00188
00189 inline bool is_curve4(unsigned c)
00190 {
00191 return c == path_cmd_curve4;
00192 }
00193
00194
00195 inline bool is_end_poly(unsigned c)
00196 {
00197 return (c & path_cmd_mask) == path_cmd_end_poly;
00198 }
00199
00200
00201 inline bool is_close(unsigned c)
00202 {
00203 return (c & ~(path_flags_cw | path_flags_ccw)) ==
00204 (path_cmd_end_poly | path_flags_close);
00205 }
00206
00207
00208 inline bool is_next_poly(unsigned c)
00209 {
00210 return is_stop(c) || is_move_to(c) || is_end_poly(c);
00211 }
00212
00213
00214 inline bool is_cw(unsigned c)
00215 {
00216 return (c & path_flags_cw) != 0;
00217 }
00218
00219
00220 inline bool is_ccw(unsigned c)
00221 {
00222 return (c & path_flags_ccw) != 0;
00223 }
00224
00225
00226 inline bool is_oriented(unsigned c)
00227 {
00228 return (c & (path_flags_cw | path_flags_ccw)) != 0;
00229 }
00230
00231
00232 inline bool is_closed(unsigned c)
00233 {
00234 return (c & path_flags_close) != 0;
00235 }
00236
00237
00238 inline unsigned get_close_flag(unsigned c)
00239 {
00240 return c & path_flags_close;
00241 }
00242
00243
00244 inline unsigned clear_orientation(unsigned c)
00245 {
00246 return c & ~(path_flags_cw | path_flags_ccw);
00247 }
00248
00249
00250 inline unsigned get_orientation(unsigned c)
00251 {
00252 return c & (path_flags_cw | path_flags_ccw);
00253 }
00254
00255
00256 inline unsigned set_orientation(unsigned c, unsigned o)
00257 {
00258 return clear_orientation(c) | o;
00259 }
00260
00261
00262 struct point_type
00263 {
00264 double x, y;
00265
00266 point_type() {}
00267 point_type(double x_, double y_) : x(x_), y(y_) {}
00268 };
00269
00270
00271 struct vertex_type
00272 {
00273 double x, y;
00274 unsigned cmd;
00275
00276 vertex_type() {}
00277 vertex_type(double x_, double y_, unsigned cmd_) :
00278 x(x_), y(y_), cmd(cmd_) {}
00279 };
00280
00281
00282 }
00283
00284
00285 #endif
00286