16 #ifndef AGG_BASICS_INCLUDED 17 #define AGG_BASICS_INCLUDED 20 #include "agg_config.h" 23 #ifdef AGG_CUSTOM_ALLOCATOR 24 #include "agg_allocator.h" 38 static T* allocate(
unsigned num) {
return new T [num]; }
39 static void deallocate(T* ptr,
unsigned) {
delete [] ptr; }
52 static T* allocate() {
return new T; }
53 static void deallocate(T* ptr) {
delete ptr; }
66 #define AGG_INT8 signed char 70 #define AGG_INT8U unsigned char 74 #define AGG_INT16 short 78 #define AGG_INT16U unsigned short 86 #define AGG_INT32U unsigned 90 #if defined(_MSC_VER) || defined(__BORLANDC__) 91 #define AGG_INT64 signed __int64 93 #define AGG_INT64 signed long long 98 #if defined(_MSC_VER) || defined(__BORLANDC__) 99 #define AGG_INT64U unsigned __int64 101 #define AGG_INT64U unsigned long long 106 #if defined(_MSC_VER) 107 #pragma warning(disable:4786) // Identifier was truncated... 110 #if defined(_MSC_VER) 111 #define AGG_INLINE __forceinline 113 #define AGG_INLINE inline 119 typedef AGG_INT8 int8;
120 typedef AGG_INT8U int8u;
121 typedef AGG_INT16 int16;
122 typedef AGG_INT16U int16u;
123 typedef AGG_INT32 int32;
124 typedef AGG_INT32U int32u;
125 typedef AGG_INT64 int64;
126 typedef AGG_INT64U int64u;
128 #if defined(AGG_FISTP) 129 #pragma warning(push) 130 #pragma warning(disable : 4035) //Disable warning "no return value" 131 AGG_INLINE
int iround(
double v)
134 __asm fld qword ptr [v]
135 __asm fistp dword ptr [t]
136 __asm mov eax, dword ptr [t]
138 AGG_INLINE
unsigned uround(
double v)
141 __asm fld qword ptr [v]
142 __asm fistp dword ptr [t]
143 __asm mov eax, dword ptr [t]
146 AGG_INLINE
int ifloor(
double v)
148 return int(floor(v));
150 AGG_INLINE
unsigned ufloor(
double v)
152 return unsigned(floor(v));
154 AGG_INLINE
int iceil(
double v)
158 AGG_INLINE
unsigned uceil(
double v)
160 return unsigned(ceil(v));
162 #elif defined(AGG_QIFIST) 163 AGG_INLINE
int iround(
double v)
167 AGG_INLINE
int uround(
double v)
171 AGG_INLINE
int ifloor(
double v)
173 return int(std::floor(v));
175 AGG_INLINE
unsigned ufloor(
double v)
177 return unsigned(std::floor(v));
179 AGG_INLINE
int iceil(
double v)
181 return int(std::ceil(v));
183 AGG_INLINE
unsigned uceil(
double v)
185 return unsigned(std::ceil(v));
188 AGG_INLINE
int iround(
double v)
190 return int((v < 0.0) ? v - 0.5 : v + 0.5);
192 AGG_INLINE
int uround(
double v)
194 return unsigned(v + 0.5);
196 AGG_INLINE
int ifloor(
double v)
201 AGG_INLINE
unsigned ufloor(
double v)
205 AGG_INLINE
int iceil(
double v)
207 return int(std::ceil(v));
209 AGG_INLINE
unsigned uceil(
double v)
211 return unsigned(std::ceil(v));
218 AGG_INLINE
static int iround(
double v)
220 if(v <
double(-Limit))
return -Limit;
221 if(v >
double( Limit))
return Limit;
222 return agg::iround(v);
229 AGG_INLINE
static unsigned mul(
unsigned a,
unsigned b)
231 unsigned q = a * b + (1 << (Shift-1));
232 return (q + (q >> Shift)) >> Shift;
237 typedef unsigned char cover_type;
241 cover_size = 1 << cover_shift,
242 cover_mask = cover_size - 1,
244 cover_full = cover_mask
253 enum poly_subpixel_scale_e
255 poly_subpixel_shift = 8,
256 poly_subpixel_scale = 1<<poly_subpixel_shift,
257 poly_subpixel_mask = poly_subpixel_scale-1
268 const double pi = 3.14159265358979323846;
271 inline double deg2rad(
double deg)
273 return deg * pi / 180.0;
277 inline double rad2deg(
double rad)
279 return rad * 180.0 / pi;
285 typedef T value_type;
291 x1(x1_), y1(y1_), x2(x2_), y2(y2_) {}
293 void init(T x1_, T y1_, T x2_, T y2_)
295 x1 = x1_; y1 = y1_; x2 = x2_; y2 = y2_;
298 const self_type& normalize()
301 if(x1 > x2) { t = x1; x1 = x2; x2 = t; }
302 if(y1 > y2) { t = y1; y1 = y2; y2 = t; }
306 bool clip(
const self_type& r)
308 if(x2 > r.x2) x2 = r.x2;
309 if(y2 > r.y2) y2 = r.y2;
310 if(x1 < r.x1) x1 = r.x1;
311 if(y1 < r.y1) y1 = r.y1;
312 return x1 <= x2 && y1 <= y2;
315 bool is_valid()
const 317 return x1 <= x2 && y1 <= y2;
320 bool hit_test(T x, T y)
const 322 return (x >= x1 && x <= x2 && y >= y1 && y <= y2);
325 bool overlaps(
const self_type& r)
const 327 return !(r.x1 > x2 || r.x2 < x1
328 || r.y1 > y2 || r.y2 < y1);
334 inline Rect intersect_rectangles(
const Rect& r1,
const Rect& r2)
343 if(r.x2 > r2.x2) r.x2 = r2.x2;
344 if(r.y2 > r2.y2) r.y2 = r2.y2;
345 if(r.x1 < r2.x1) r.x1 = r2.x1;
346 if(r.y1 < r2.y1) r.y1 = r2.y1;
353 inline Rect unite_rectangles(
const Rect& r1,
const Rect& r2)
356 if(r.x2 < r2.x2) r.x2 = r2.x2;
357 if(r.y2 < r2.y2) r.y2 = r2.y2;
358 if(r.x1 > r2.x1) r.x1 = r2.x1;
359 if(r.y1 > r2.y1) r.y1 = r2.y1;
371 path_cmd_move_to = 1,
372 path_cmd_line_to = 2,
377 path_cmd_ubspline = 7,
378 path_cmd_end_poly = 0x0F,
386 path_flags_ccw = 0x10,
387 path_flags_cw = 0x20,
388 path_flags_close = 0x40,
389 path_flags_mask = 0xF0
393 inline bool is_vertex(
unsigned c)
395 return c >= path_cmd_move_to && c < path_cmd_end_poly;
399 inline bool is_drawing(
unsigned c)
401 return c >= path_cmd_line_to && c < path_cmd_end_poly;
405 inline bool is_stop(
unsigned c)
407 return c == path_cmd_stop;
411 inline bool is_move_to(
unsigned c)
413 return c == path_cmd_move_to;
417 inline bool is_line_to(
unsigned c)
419 return c == path_cmd_line_to;
423 inline bool is_curve(
unsigned c)
425 return c == path_cmd_curve3 || c == path_cmd_curve4;
429 inline bool is_curve3(
unsigned c)
431 return c == path_cmd_curve3;
435 inline bool is_curve4(
unsigned c)
437 return c == path_cmd_curve4;
441 inline bool is_end_poly(
unsigned c)
443 return (c & path_cmd_mask) == path_cmd_end_poly;
447 inline bool is_close(
unsigned c)
449 return (c & ~(path_flags_cw | path_flags_ccw)) ==
450 (path_cmd_end_poly | path_flags_close);
454 inline bool is_next_poly(
unsigned c)
456 return is_stop(c) || is_move_to(c) || is_end_poly(c);
460 inline bool is_cw(
unsigned c)
462 return (c & path_flags_cw) != 0;
466 inline bool is_ccw(
unsigned c)
468 return (c & path_flags_ccw) != 0;
472 inline bool is_oriented(
unsigned c)
474 return (c & (path_flags_cw | path_flags_ccw)) != 0;
478 inline bool is_closed(
unsigned c)
480 return (c & path_flags_close) != 0;
484 inline unsigned get_close_flag(
unsigned c)
486 return c & path_flags_close;
490 inline unsigned clear_orientation(
unsigned c)
492 return c & ~(path_flags_cw | path_flags_ccw);
496 inline unsigned get_orientation(
unsigned c)
498 return c & (path_flags_cw | path_flags_ccw);
502 inline unsigned set_orientation(
unsigned c,
unsigned o)
504 return clear_orientation(c) | o;
510 typedef T value_type;
522 typedef T value_type;
526 vertex_base(T x_, T y_,
unsigned cmd_) : x(x_), y(y_), cmd(cmd_) {}
538 row_info(
int x1_,
int x2_, T* ptr_) : x1(x1_), x2(x2_), ptr(ptr_) {}
548 x1(x1_), x2(x2_), ptr(ptr_) {}
552 template<
class T>
inline bool is_equal_eps(T v1, T v2, T epsilon)
554 bool neg1 = v1 < 0.0;
555 bool neg2 = v2 < 0.0;
558 return std::fabs(v1) < epsilon && std::fabs(v2) < epsilon;
561 std::frexp(v1, &int1);
562 std::frexp(v2, &int2);
563 int min12 = int1 < int2 ? int1 : int2;
565 v1 = std::ldexp(v1, -min12);
566 v2 = std::ldexp(v2, -min12);
568 return std::fabs(v1 - v2) < epsilon;