xref: /haiku/headers/libs/agg/agg_basics.h (revision e39da397f5ff79f2db9f9a3ddf1852b6710578af)
139241fe2SDarkWyrm //----------------------------------------------------------------------------
2*e39da397SStephan Aßmus // Anti-Grain Geometry - Version 2.4
3*e39da397SStephan Aßmus // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
439241fe2SDarkWyrm //
539241fe2SDarkWyrm // Permission to copy, use, modify, sell and distribute this software
639241fe2SDarkWyrm // is granted provided this copyright notice appears in all copies.
739241fe2SDarkWyrm // This software is provided "as is" without express or implied
839241fe2SDarkWyrm // warranty, and with no claim as to its suitability for any purpose.
939241fe2SDarkWyrm //
1039241fe2SDarkWyrm //----------------------------------------------------------------------------
1139241fe2SDarkWyrm // Contact: mcseem@antigrain.com
1239241fe2SDarkWyrm //          mcseemagg@yahoo.com
1339241fe2SDarkWyrm //          http://www.antigrain.com
1439241fe2SDarkWyrm //----------------------------------------------------------------------------
1539241fe2SDarkWyrm 
1639241fe2SDarkWyrm #ifndef AGG_BASICS_INCLUDED
1739241fe2SDarkWyrm #define AGG_BASICS_INCLUDED
1839241fe2SDarkWyrm 
19*e39da397SStephan Aßmus #include <math.h>
20*e39da397SStephan Aßmus #include "agg_config.h"
21*e39da397SStephan Aßmus 
22*e39da397SStephan Aßmus //---------------------------------------------------------AGG_CUSTOM_ALLOCATOR
23*e39da397SStephan Aßmus #ifdef AGG_CUSTOM_ALLOCATOR
24*e39da397SStephan Aßmus #include "agg_allocator.h"
25*e39da397SStephan Aßmus #else
26*e39da397SStephan Aßmus namespace agg
27*e39da397SStephan Aßmus {
28*e39da397SStephan Aßmus     // The policy of all AGG containers and memory allocation strategy
29*e39da397SStephan Aßmus     // in general is that no allocated data requires explicit construction.
30*e39da397SStephan Aßmus     // It means that the allocator can be really simple; you can even
31*e39da397SStephan Aßmus     // replace new/delete to malloc/free. The constructors and destructors
32*e39da397SStephan Aßmus     // won't be called in this case, however everything will remain working.
33*e39da397SStephan Aßmus     // The second argument of deallocate() is the size of the allocated
34*e39da397SStephan Aßmus     // block. You can use this information if you wish.
35*e39da397SStephan Aßmus     //------------------------------------------------------------pod_allocator
36*e39da397SStephan Aßmus     template<class T> struct pod_allocator
37*e39da397SStephan Aßmus     {
38*e39da397SStephan Aßmus         static T*   allocate(unsigned num)       { return new T [num]; }
39*e39da397SStephan Aßmus         static void deallocate(T* ptr, unsigned) { delete [] ptr;      }
40*e39da397SStephan Aßmus     };
41*e39da397SStephan Aßmus 
42*e39da397SStephan Aßmus     // Single object allocator. It's also can be replaced with your custom
43*e39da397SStephan Aßmus     // allocator. The difference is that it can only allocate a single
44*e39da397SStephan Aßmus     // object and the constructor and destructor must be called.
45*e39da397SStephan Aßmus     // In AGG there is no need to allocate an array of objects with
46*e39da397SStephan Aßmus     // calling their constructors (only single ones). So that, if you
47*e39da397SStephan Aßmus     // replace these new/delete to malloc/free make sure that the in-place
48*e39da397SStephan Aßmus     // new is called and take care of calling the destructor too.
49*e39da397SStephan Aßmus     //------------------------------------------------------------obj_allocator
50*e39da397SStephan Aßmus     template<class T> struct obj_allocator
51*e39da397SStephan Aßmus     {
52*e39da397SStephan Aßmus         static T*   allocate()         { return new T; }
53*e39da397SStephan Aßmus         static void deallocate(T* ptr) { delete ptr;   }
54*e39da397SStephan Aßmus     };
55*e39da397SStephan Aßmus }
56*e39da397SStephan Aßmus #endif
57*e39da397SStephan Aßmus 
58*e39da397SStephan Aßmus 
59*e39da397SStephan Aßmus //-------------------------------------------------------- Default basic types
60*e39da397SStephan Aßmus //
61*e39da397SStephan Aßmus // If the compiler has different capacity of the basic types you can redefine
62*e39da397SStephan Aßmus // them via the compiler command line or by generating agg_config.h that is
63*e39da397SStephan Aßmus // empty by default.
64*e39da397SStephan Aßmus //
65*e39da397SStephan Aßmus #ifndef AGG_INT8
66*e39da397SStephan Aßmus #define AGG_INT8 signed char
67*e39da397SStephan Aßmus #endif
68*e39da397SStephan Aßmus 
69*e39da397SStephan Aßmus #ifndef AGG_INT8U
70*e39da397SStephan Aßmus #define AGG_INT8U unsigned char
71*e39da397SStephan Aßmus #endif
72*e39da397SStephan Aßmus 
73*e39da397SStephan Aßmus #ifndef AGG_INT16
74*e39da397SStephan Aßmus #define AGG_INT16 short
75*e39da397SStephan Aßmus #endif
76*e39da397SStephan Aßmus 
77*e39da397SStephan Aßmus #ifndef AGG_INT16U
78*e39da397SStephan Aßmus #define AGG_INT16U unsigned short
79*e39da397SStephan Aßmus #endif
80*e39da397SStephan Aßmus 
81*e39da397SStephan Aßmus #ifndef AGG_INT32
82*e39da397SStephan Aßmus #define AGG_INT32 int
83*e39da397SStephan Aßmus #endif
84*e39da397SStephan Aßmus 
85*e39da397SStephan Aßmus #ifndef AGG_INT32U
86*e39da397SStephan Aßmus #define AGG_INT32U unsigned
87*e39da397SStephan Aßmus #endif
88*e39da397SStephan Aßmus 
89*e39da397SStephan Aßmus #ifndef AGG_INT64
90*e39da397SStephan Aßmus #if defined(_MSC_VER) || defined(__BORLANDC__)
91*e39da397SStephan Aßmus #define AGG_INT64 signed __int64
92*e39da397SStephan Aßmus #else
93*e39da397SStephan Aßmus #define AGG_INT64 signed long long
94*e39da397SStephan Aßmus #endif
95*e39da397SStephan Aßmus #endif
96*e39da397SStephan Aßmus 
97*e39da397SStephan Aßmus #ifndef AGG_INT64U
98*e39da397SStephan Aßmus #if defined(_MSC_VER) || defined(__BORLANDC__)
99*e39da397SStephan Aßmus #define AGG_INT64U unsigned __int64
100*e39da397SStephan Aßmus #else
101*e39da397SStephan Aßmus #define AGG_INT64U unsigned long long
102*e39da397SStephan Aßmus #endif
103*e39da397SStephan Aßmus #endif
104*e39da397SStephan Aßmus 
105*e39da397SStephan Aßmus //------------------------------------------------ Some fixes for MS Visual C++
106*e39da397SStephan Aßmus #if defined(_MSC_VER)
107*e39da397SStephan Aßmus #pragma warning(disable:4786) // Identifier was truncated...
108*e39da397SStephan Aßmus #endif
109*e39da397SStephan Aßmus 
110*e39da397SStephan Aßmus #if defined(_MSC_VER)
111*e39da397SStephan Aßmus #define AGG_INLINE __forceinline
112*e39da397SStephan Aßmus #else
113*e39da397SStephan Aßmus #define AGG_INLINE inline
114*e39da397SStephan Aßmus #endif
115*e39da397SStephan Aßmus 
11639241fe2SDarkWyrm namespace agg
11739241fe2SDarkWyrm {
11839241fe2SDarkWyrm     //-------------------------------------------------------------------------
119*e39da397SStephan Aßmus     typedef AGG_INT8   int8;         //----int8
120*e39da397SStephan Aßmus     typedef AGG_INT8U  int8u;        //----int8u
121*e39da397SStephan Aßmus     typedef AGG_INT16  int16;        //----int16
122*e39da397SStephan Aßmus     typedef AGG_INT16U int16u;       //----int16u
123*e39da397SStephan Aßmus     typedef AGG_INT32  int32;        //----int32
124*e39da397SStephan Aßmus     typedef AGG_INT32U int32u;       //----int32u
125*e39da397SStephan Aßmus     typedef AGG_INT64  int64;        //----int64
126*e39da397SStephan Aßmus     typedef AGG_INT64U int64u;       //----int64u
12739241fe2SDarkWyrm 
128*e39da397SStephan Aßmus #if defined(AGG_FISTP)
129*e39da397SStephan Aßmus #pragma warning(push)
130*e39da397SStephan Aßmus #pragma warning(disable : 4035) //Disable warning "no return value"
131*e39da397SStephan Aßmus     AGG_INLINE int iround(double v)              //-------iround
132*e39da397SStephan Aßmus     {
133*e39da397SStephan Aßmus         int t;
134*e39da397SStephan Aßmus         __asm fld   qword ptr [v]
135*e39da397SStephan Aßmus         __asm fistp dword ptr [t]
136*e39da397SStephan Aßmus         __asm mov eax, dword ptr [t]
137*e39da397SStephan Aßmus     }
138*e39da397SStephan Aßmus     AGG_INLINE unsigned uround(double v)         //-------uround
139*e39da397SStephan Aßmus     {
140*e39da397SStephan Aßmus         unsigned t;
141*e39da397SStephan Aßmus         __asm fld   qword ptr [v]
142*e39da397SStephan Aßmus         __asm fistp dword ptr [t]
143*e39da397SStephan Aßmus         __asm mov eax, dword ptr [t]
144*e39da397SStephan Aßmus     }
145*e39da397SStephan Aßmus #pragma warning(pop)
146*e39da397SStephan Aßmus     AGG_INLINE unsigned ufloor(double v)         //-------ufloor
147*e39da397SStephan Aßmus     {
148*e39da397SStephan Aßmus         return unsigned(floor(v));
149*e39da397SStephan Aßmus     }
150*e39da397SStephan Aßmus     AGG_INLINE unsigned uceil(double v)          //--------uceil
151*e39da397SStephan Aßmus     {
152*e39da397SStephan Aßmus         return unsigned(ceil(v));
153*e39da397SStephan Aßmus     }
154*e39da397SStephan Aßmus #elif defined(AGG_QIFIST)
155*e39da397SStephan Aßmus     AGG_INLINE int iround(double v)
156*e39da397SStephan Aßmus     {
157*e39da397SStephan Aßmus         return int(v);
158*e39da397SStephan Aßmus     }
159*e39da397SStephan Aßmus     AGG_INLINE int uround(double v)
160*e39da397SStephan Aßmus     {
161*e39da397SStephan Aßmus         return unsigned(v);
162*e39da397SStephan Aßmus     }
163*e39da397SStephan Aßmus     AGG_INLINE unsigned ufloor(double v)
164*e39da397SStephan Aßmus     {
165*e39da397SStephan Aßmus         return unsigned(floor(v));
166*e39da397SStephan Aßmus     }
167*e39da397SStephan Aßmus     AGG_INLINE unsigned uceil(double v)
168*e39da397SStephan Aßmus     {
169*e39da397SStephan Aßmus         return unsigned(ceil(v));
170*e39da397SStephan Aßmus     }
171*e39da397SStephan Aßmus #else
172*e39da397SStephan Aßmus     AGG_INLINE int iround(double v)
173*e39da397SStephan Aßmus     {
174*e39da397SStephan Aßmus         return int((v < 0.0) ? v - 0.5 : v + 0.5);
175*e39da397SStephan Aßmus     }
176*e39da397SStephan Aßmus     AGG_INLINE int uround(double v)
177*e39da397SStephan Aßmus     {
178*e39da397SStephan Aßmus         return unsigned(v + 0.5);
179*e39da397SStephan Aßmus     }
180*e39da397SStephan Aßmus     AGG_INLINE unsigned ufloor(double v)
181*e39da397SStephan Aßmus     {
182*e39da397SStephan Aßmus         return unsigned(v);
183*e39da397SStephan Aßmus     }
184*e39da397SStephan Aßmus     AGG_INLINE unsigned uceil(double v)
185*e39da397SStephan Aßmus     {
186*e39da397SStephan Aßmus         return unsigned(ceil(v));
187*e39da397SStephan Aßmus     }
188*e39da397SStephan Aßmus #endif
189*e39da397SStephan Aßmus 
190*e39da397SStephan Aßmus     //---------------------------------------------------------------saturation
191*e39da397SStephan Aßmus     template<int Limit> struct saturation
192*e39da397SStephan Aßmus     {
193*e39da397SStephan Aßmus         AGG_INLINE static int iround(double v)
194*e39da397SStephan Aßmus         {
195*e39da397SStephan Aßmus             if(v < double(-Limit)) return -Limit;
196*e39da397SStephan Aßmus             if(v > double( Limit)) return  Limit;
197*e39da397SStephan Aßmus             return agg::iround(v);
198*e39da397SStephan Aßmus         }
199*e39da397SStephan Aßmus     };
200*e39da397SStephan Aßmus 
201*e39da397SStephan Aßmus     //------------------------------------------------------------------mul_one
202*e39da397SStephan Aßmus     template<unsigned Shift> struct mul_one
203*e39da397SStephan Aßmus     {
204*e39da397SStephan Aßmus         AGG_INLINE static unsigned mul(unsigned a, unsigned b)
205*e39da397SStephan Aßmus         {
206*e39da397SStephan Aßmus             register unsigned q = a * b + (1 << (Shift-1));
207*e39da397SStephan Aßmus             return (q + (q >> Shift)) >> Shift;
208*e39da397SStephan Aßmus         }
209*e39da397SStephan Aßmus     };
21039241fe2SDarkWyrm 
21139241fe2SDarkWyrm     //-------------------------------------------------------------------------
21239241fe2SDarkWyrm     typedef unsigned char cover_type;    //----cover_type
213*e39da397SStephan Aßmus     enum cover_scale_e
21439241fe2SDarkWyrm     {
21539241fe2SDarkWyrm         cover_shift = 8,                 //----cover_shift
21639241fe2SDarkWyrm         cover_size  = 1 << cover_shift,  //----cover_size
21739241fe2SDarkWyrm         cover_mask  = cover_size - 1,    //----cover_mask
21839241fe2SDarkWyrm         cover_none  = 0,                 //----cover_none
21939241fe2SDarkWyrm         cover_full  = cover_mask         //----cover_full
22039241fe2SDarkWyrm     };
22139241fe2SDarkWyrm 
222*e39da397SStephan Aßmus     //----------------------------------------------------poly_subpixel_scale_e
223*e39da397SStephan Aßmus     // These constants determine the subpixel accuracy, to be more precise,
224*e39da397SStephan Aßmus     // the number of bits of the fractional part of the coordinates.
225*e39da397SStephan Aßmus     // The possible coordinate capacity in bits can be calculated by formula:
226*e39da397SStephan Aßmus     // sizeof(int) * 8 - poly_subpixel_shift, i.e, for 32-bit integers and
227*e39da397SStephan Aßmus     // 8-bits fractional part the capacity is 24 bits.
228*e39da397SStephan Aßmus     enum poly_subpixel_scale_e
229*e39da397SStephan Aßmus     {
230*e39da397SStephan Aßmus         poly_subpixel_shift = 8,                      //----poly_subpixel_shift
231*e39da397SStephan Aßmus         poly_subpixel_scale = 1<<poly_subpixel_shift, //----poly_subpixel_scale
232*e39da397SStephan Aßmus         poly_subpixel_mask  = poly_subpixel_scale-1,  //----poly_subpixel_mask
233*e39da397SStephan Aßmus     };
234*e39da397SStephan Aßmus 
235*e39da397SStephan Aßmus     //----------------------------------------------------------filling_rule_e
236*e39da397SStephan Aßmus     enum filling_rule_e
237*e39da397SStephan Aßmus     {
238*e39da397SStephan Aßmus         fill_non_zero,
239*e39da397SStephan Aßmus         fill_even_odd
240*e39da397SStephan Aßmus     };
24139241fe2SDarkWyrm 
24239241fe2SDarkWyrm     //-----------------------------------------------------------------------pi
24339241fe2SDarkWyrm     const double pi = 3.14159265358979323846;
24439241fe2SDarkWyrm 
24539241fe2SDarkWyrm     //------------------------------------------------------------------deg2rad
24639241fe2SDarkWyrm     inline double deg2rad(double deg)
24739241fe2SDarkWyrm     {
24839241fe2SDarkWyrm         return deg * pi / 180.0;
24939241fe2SDarkWyrm     }
25039241fe2SDarkWyrm 
25139241fe2SDarkWyrm     //------------------------------------------------------------------rad2deg
25239241fe2SDarkWyrm     inline double rad2deg(double rad)
25339241fe2SDarkWyrm     {
25439241fe2SDarkWyrm         return rad * 180.0 / pi;
25539241fe2SDarkWyrm     }
25639241fe2SDarkWyrm 
25739241fe2SDarkWyrm     //----------------------------------------------------------------rect_base
25839241fe2SDarkWyrm     template<class T> struct rect_base
25939241fe2SDarkWyrm     {
26039241fe2SDarkWyrm         typedef rect_base<T> self_type;
26139241fe2SDarkWyrm         T x1;
26239241fe2SDarkWyrm         T y1;
26339241fe2SDarkWyrm         T x2;
26439241fe2SDarkWyrm         T y2;
26539241fe2SDarkWyrm 
26639241fe2SDarkWyrm         rect_base() {}
26739241fe2SDarkWyrm         rect_base(T x1_, T y1_, T x2_, T y2_) :
26839241fe2SDarkWyrm             x1(x1_), y1(y1_), x2(x2_), y2(y2_) {}
26939241fe2SDarkWyrm 
27039241fe2SDarkWyrm         const self_type& normalize()
27139241fe2SDarkWyrm         {
27239241fe2SDarkWyrm             T t;
27339241fe2SDarkWyrm             if(x1 > x2) { t = x1; x1 = x2; x2 = t; }
27439241fe2SDarkWyrm             if(y1 > y2) { t = y1; y1 = y2; y2 = t; }
27539241fe2SDarkWyrm             return *this;
27639241fe2SDarkWyrm         }
27739241fe2SDarkWyrm 
27839241fe2SDarkWyrm         bool clip(const self_type& r)
27939241fe2SDarkWyrm         {
28039241fe2SDarkWyrm             if(x2 > r.x2) x2 = r.x2;
28139241fe2SDarkWyrm             if(y2 > r.y2) y2 = r.y2;
28239241fe2SDarkWyrm             if(x1 < r.x1) x1 = r.x1;
28339241fe2SDarkWyrm             if(y1 < r.y1) y1 = r.y1;
28439241fe2SDarkWyrm             return x1 <= x2 && y1 <= y2;
28539241fe2SDarkWyrm         }
28639241fe2SDarkWyrm 
28739241fe2SDarkWyrm         bool is_valid() const
28839241fe2SDarkWyrm         {
28939241fe2SDarkWyrm             return x1 <= x2 && y1 <= y2;
29039241fe2SDarkWyrm         }
29139241fe2SDarkWyrm     };
29239241fe2SDarkWyrm 
29339241fe2SDarkWyrm     //-----------------------------------------------------intersect_rectangles
29439241fe2SDarkWyrm     template<class Rect>
29539241fe2SDarkWyrm     inline Rect intersect_rectangles(const Rect& r1, const Rect& r2)
29639241fe2SDarkWyrm     {
29739241fe2SDarkWyrm         Rect r = r1;
29839241fe2SDarkWyrm 
29939241fe2SDarkWyrm         // First process x2,y2 because the other order
30039241fe2SDarkWyrm         // results in Internal Compiler Error under
30139241fe2SDarkWyrm         // Microsoft Visual C++ .NET 2003 69462-335-0000007-18038 in
30239241fe2SDarkWyrm         // case of "Maximize Speed" optimization option.
30339241fe2SDarkWyrm         //-----------------
30439241fe2SDarkWyrm         if(r.x2 > r2.x2) r.x2 = r2.x2;
30539241fe2SDarkWyrm         if(r.y2 > r2.y2) r.y2 = r2.y2;
30639241fe2SDarkWyrm         if(r.x1 < r2.x1) r.x1 = r2.x1;
30739241fe2SDarkWyrm         if(r.y1 < r2.y1) r.y1 = r2.y1;
30839241fe2SDarkWyrm         return r;
30939241fe2SDarkWyrm     }
31039241fe2SDarkWyrm 
31139241fe2SDarkWyrm 
31239241fe2SDarkWyrm     //---------------------------------------------------------unite_rectangles
31339241fe2SDarkWyrm     template<class Rect>
31439241fe2SDarkWyrm     inline Rect unite_rectangles(const Rect& r1, const Rect& r2)
31539241fe2SDarkWyrm     {
31639241fe2SDarkWyrm         Rect r = r1;
31739241fe2SDarkWyrm         if(r.x2 < r2.x2) r.x2 = r2.x2;
31839241fe2SDarkWyrm         if(r.y2 < r2.y2) r.y2 = r2.y2;
31939241fe2SDarkWyrm         if(r.x1 > r2.x1) r.x1 = r2.x1;
32039241fe2SDarkWyrm         if(r.y1 > r2.y1) r.y1 = r2.y1;
32139241fe2SDarkWyrm         return r;
32239241fe2SDarkWyrm     }
32339241fe2SDarkWyrm 
324*e39da397SStephan Aßmus     typedef rect_base<int>    rect_i; //----rect_i
325*e39da397SStephan Aßmus     typedef rect_base<float>  rect_f; //----rect_f
32639241fe2SDarkWyrm     typedef rect_base<double> rect_d; //----rect_d
32739241fe2SDarkWyrm 
32839241fe2SDarkWyrm     //---------------------------------------------------------path_commands_e
32939241fe2SDarkWyrm     enum path_commands_e
33039241fe2SDarkWyrm     {
33139241fe2SDarkWyrm         path_cmd_stop     = 0,        //----path_cmd_stop
33239241fe2SDarkWyrm         path_cmd_move_to  = 1,        //----path_cmd_move_to
33339241fe2SDarkWyrm         path_cmd_line_to  = 2,        //----path_cmd_line_to
33439241fe2SDarkWyrm         path_cmd_curve3   = 3,        //----path_cmd_curve3
33539241fe2SDarkWyrm         path_cmd_curve4   = 4,        //----path_cmd_curve4
336*e39da397SStephan Aßmus         path_cmd_curveN   = 5,        //----path_cmd_curveN
337*e39da397SStephan Aßmus         path_cmd_catrom   = 6,        //----path_cmd_catrom
338*e39da397SStephan Aßmus         path_cmd_ubspline = 7,        //----path_cmd_ubspline
339*e39da397SStephan Aßmus         path_cmd_end_poly = 0x0F,     //----path_cmd_end_poly
34039241fe2SDarkWyrm         path_cmd_mask     = 0x0F      //----path_cmd_mask
34139241fe2SDarkWyrm     };
34239241fe2SDarkWyrm 
34339241fe2SDarkWyrm     //------------------------------------------------------------path_flags_e
34439241fe2SDarkWyrm     enum path_flags_e
34539241fe2SDarkWyrm     {
34639241fe2SDarkWyrm         path_flags_none  = 0,         //----path_flags_none
34739241fe2SDarkWyrm         path_flags_ccw   = 0x10,      //----path_flags_ccw
34839241fe2SDarkWyrm         path_flags_cw    = 0x20,      //----path_flags_cw
34939241fe2SDarkWyrm         path_flags_close = 0x40,      //----path_flags_close
35039241fe2SDarkWyrm         path_flags_mask  = 0xF0       //----path_flags_mask
35139241fe2SDarkWyrm     };
35239241fe2SDarkWyrm 
35339241fe2SDarkWyrm     //---------------------------------------------------------------is_vertex
35439241fe2SDarkWyrm     inline bool is_vertex(unsigned c)
35539241fe2SDarkWyrm     {
35639241fe2SDarkWyrm         return c >= path_cmd_move_to && c < path_cmd_end_poly;
35739241fe2SDarkWyrm     }
35839241fe2SDarkWyrm 
359*e39da397SStephan Aßmus     //--------------------------------------------------------------is_drawing
360*e39da397SStephan Aßmus     inline bool is_drawing(unsigned c)
361*e39da397SStephan Aßmus     {
362*e39da397SStephan Aßmus         return c >= path_cmd_line_to && c < path_cmd_end_poly;
363*e39da397SStephan Aßmus     }
364*e39da397SStephan Aßmus 
36539241fe2SDarkWyrm     //-----------------------------------------------------------------is_stop
36639241fe2SDarkWyrm     inline bool is_stop(unsigned c)
36739241fe2SDarkWyrm     {
36839241fe2SDarkWyrm         return c == path_cmd_stop;
36939241fe2SDarkWyrm     }
37039241fe2SDarkWyrm 
37139241fe2SDarkWyrm     //--------------------------------------------------------------is_move_to
37239241fe2SDarkWyrm     inline bool is_move_to(unsigned c)
37339241fe2SDarkWyrm     {
37439241fe2SDarkWyrm         return c == path_cmd_move_to;
37539241fe2SDarkWyrm     }
37639241fe2SDarkWyrm 
37739241fe2SDarkWyrm     //--------------------------------------------------------------is_line_to
37839241fe2SDarkWyrm     inline bool is_line_to(unsigned c)
37939241fe2SDarkWyrm     {
38039241fe2SDarkWyrm         return c == path_cmd_line_to;
38139241fe2SDarkWyrm     }
38239241fe2SDarkWyrm 
38339241fe2SDarkWyrm     //----------------------------------------------------------------is_curve
38439241fe2SDarkWyrm     inline bool is_curve(unsigned c)
38539241fe2SDarkWyrm     {
38639241fe2SDarkWyrm         return c == path_cmd_curve3 || c == path_cmd_curve4;
38739241fe2SDarkWyrm     }
38839241fe2SDarkWyrm 
38939241fe2SDarkWyrm     //---------------------------------------------------------------is_curve3
39039241fe2SDarkWyrm     inline bool is_curve3(unsigned c)
39139241fe2SDarkWyrm     {
39239241fe2SDarkWyrm         return c == path_cmd_curve3;
39339241fe2SDarkWyrm     }
39439241fe2SDarkWyrm 
39539241fe2SDarkWyrm     //---------------------------------------------------------------is_curve4
39639241fe2SDarkWyrm     inline bool is_curve4(unsigned c)
39739241fe2SDarkWyrm     {
39839241fe2SDarkWyrm         return c == path_cmd_curve4;
39939241fe2SDarkWyrm     }
40039241fe2SDarkWyrm 
40139241fe2SDarkWyrm     //-------------------------------------------------------------is_end_poly
40239241fe2SDarkWyrm     inline bool is_end_poly(unsigned c)
40339241fe2SDarkWyrm     {
40439241fe2SDarkWyrm         return (c & path_cmd_mask) == path_cmd_end_poly;
40539241fe2SDarkWyrm     }
40639241fe2SDarkWyrm 
40739241fe2SDarkWyrm     //----------------------------------------------------------------is_close
40839241fe2SDarkWyrm     inline bool is_close(unsigned c)
40939241fe2SDarkWyrm     {
41039241fe2SDarkWyrm         return (c & ~(path_flags_cw | path_flags_ccw)) ==
41139241fe2SDarkWyrm                (path_cmd_end_poly | path_flags_close);
41239241fe2SDarkWyrm     }
41339241fe2SDarkWyrm 
41439241fe2SDarkWyrm     //------------------------------------------------------------is_next_poly
41539241fe2SDarkWyrm     inline bool is_next_poly(unsigned c)
41639241fe2SDarkWyrm     {
41739241fe2SDarkWyrm         return is_stop(c) || is_move_to(c) || is_end_poly(c);
41839241fe2SDarkWyrm     }
41939241fe2SDarkWyrm 
42039241fe2SDarkWyrm     //-------------------------------------------------------------------is_cw
42139241fe2SDarkWyrm     inline bool is_cw(unsigned c)
42239241fe2SDarkWyrm     {
42339241fe2SDarkWyrm         return (c & path_flags_cw) != 0;
42439241fe2SDarkWyrm     }
42539241fe2SDarkWyrm 
42639241fe2SDarkWyrm     //------------------------------------------------------------------is_ccw
42739241fe2SDarkWyrm     inline bool is_ccw(unsigned c)
42839241fe2SDarkWyrm     {
42939241fe2SDarkWyrm         return (c & path_flags_ccw) != 0;
43039241fe2SDarkWyrm     }
43139241fe2SDarkWyrm 
43239241fe2SDarkWyrm     //-------------------------------------------------------------is_oriented
43339241fe2SDarkWyrm     inline bool is_oriented(unsigned c)
43439241fe2SDarkWyrm     {
43539241fe2SDarkWyrm         return (c & (path_flags_cw | path_flags_ccw)) != 0;
43639241fe2SDarkWyrm     }
43739241fe2SDarkWyrm 
43839241fe2SDarkWyrm     //---------------------------------------------------------------is_closed
43939241fe2SDarkWyrm     inline bool is_closed(unsigned c)
44039241fe2SDarkWyrm     {
44139241fe2SDarkWyrm         return (c & path_flags_close) != 0;
44239241fe2SDarkWyrm     }
44339241fe2SDarkWyrm 
44439241fe2SDarkWyrm     //----------------------------------------------------------get_close_flag
44539241fe2SDarkWyrm     inline unsigned get_close_flag(unsigned c)
44639241fe2SDarkWyrm     {
44739241fe2SDarkWyrm         return c & path_flags_close;
44839241fe2SDarkWyrm     }
44939241fe2SDarkWyrm 
45039241fe2SDarkWyrm     //-------------------------------------------------------clear_orientation
45139241fe2SDarkWyrm     inline unsigned clear_orientation(unsigned c)
45239241fe2SDarkWyrm     {
45339241fe2SDarkWyrm         return c & ~(path_flags_cw | path_flags_ccw);
45439241fe2SDarkWyrm     }
45539241fe2SDarkWyrm 
45639241fe2SDarkWyrm     //---------------------------------------------------------get_orientation
45739241fe2SDarkWyrm     inline unsigned get_orientation(unsigned c)
45839241fe2SDarkWyrm     {
45939241fe2SDarkWyrm         return c & (path_flags_cw | path_flags_ccw);
46039241fe2SDarkWyrm     }
46139241fe2SDarkWyrm 
46239241fe2SDarkWyrm     //---------------------------------------------------------set_orientation
46339241fe2SDarkWyrm     inline unsigned set_orientation(unsigned c, unsigned o)
46439241fe2SDarkWyrm     {
46539241fe2SDarkWyrm         return clear_orientation(c) | o;
46639241fe2SDarkWyrm     }
46739241fe2SDarkWyrm 
468*e39da397SStephan Aßmus     //--------------------------------------------------------------point_base
469*e39da397SStephan Aßmus     template<class T> struct point_base
47039241fe2SDarkWyrm     {
471*e39da397SStephan Aßmus         typedef T value_type;
472*e39da397SStephan Aßmus         T x,y;
473*e39da397SStephan Aßmus         point_base() {}
474*e39da397SStephan Aßmus         point_base(T x_, T y_) : x(x_), y(y_) {}
47539241fe2SDarkWyrm     };
476*e39da397SStephan Aßmus     typedef point_base<int>    point_i; //-----point_i
477*e39da397SStephan Aßmus     typedef point_base<float>  point_f; //-----point_f
478*e39da397SStephan Aßmus     typedef point_base<double> point_d; //-----point_d
47939241fe2SDarkWyrm 
480*e39da397SStephan Aßmus     //-------------------------------------------------------------vertex_base
481*e39da397SStephan Aßmus     template<class T> struct vertex_base
48239241fe2SDarkWyrm     {
483*e39da397SStephan Aßmus         typedef T value_type;
484*e39da397SStephan Aßmus         T x,y;
48539241fe2SDarkWyrm         unsigned cmd;
486*e39da397SStephan Aßmus         vertex_base() {}
487*e39da397SStephan Aßmus         vertex_base(T x_, T y_, unsigned cmd_) : x(x_), y(y_), cmd(cmd_) {}
48839241fe2SDarkWyrm     };
489*e39da397SStephan Aßmus     typedef vertex_base<int>    vertex_i; //-----vertex_i
490*e39da397SStephan Aßmus     typedef vertex_base<float>  vertex_f; //-----vertex_f
491*e39da397SStephan Aßmus     typedef vertex_base<double> vertex_d; //-----vertex_d
49239241fe2SDarkWyrm 
49339241fe2SDarkWyrm }
49439241fe2SDarkWyrm 
49539241fe2SDarkWyrm 
49639241fe2SDarkWyrm #endif
49739241fe2SDarkWyrm 
498