139241fe2SDarkWyrm //---------------------------------------------------------------------------- 2e39da397SStephan Aßmus // Anti-Grain Geometry - Version 2.4 3e39da397SStephan 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 19e39da397SStephan Aßmus #include <math.h> 20e39da397SStephan Aßmus #include "agg_config.h" 21e39da397SStephan Aßmus 22e39da397SStephan Aßmus //---------------------------------------------------------AGG_CUSTOM_ALLOCATOR 23e39da397SStephan Aßmus #ifdef AGG_CUSTOM_ALLOCATOR 24e39da397SStephan Aßmus #include "agg_allocator.h" 25e39da397SStephan Aßmus #else 26e39da397SStephan Aßmus namespace agg 27e39da397SStephan Aßmus { 28e39da397SStephan Aßmus // The policy of all AGG containers and memory allocation strategy 29e39da397SStephan Aßmus // in general is that no allocated data requires explicit construction. 30e39da397SStephan Aßmus // It means that the allocator can be really simple; you can even 31e39da397SStephan Aßmus // replace new/delete to malloc/free. The constructors and destructors 32e39da397SStephan Aßmus // won't be called in this case, however everything will remain working. 33e39da397SStephan Aßmus // The second argument of deallocate() is the size of the allocated 34e39da397SStephan Aßmus // block. You can use this information if you wish. 35e39da397SStephan Aßmus //------------------------------------------------------------pod_allocator 36e39da397SStephan Aßmus template<class T> struct pod_allocator 37e39da397SStephan Aßmus { allocatepod_allocator38e39da397SStephan Aßmus static T* allocate(unsigned num) { return new T [num]; } deallocatepod_allocator39e39da397SStephan Aßmus static void deallocate(T* ptr, unsigned) { delete [] ptr; } 40e39da397SStephan Aßmus }; 41e39da397SStephan Aßmus 42e39da397SStephan Aßmus // Single object allocator. It's also can be replaced with your custom 43e39da397SStephan Aßmus // allocator. The difference is that it can only allocate a single 44e39da397SStephan Aßmus // object and the constructor and destructor must be called. 45e39da397SStephan Aßmus // In AGG there is no need to allocate an array of objects with 46e39da397SStephan Aßmus // calling their constructors (only single ones). So that, if you 47e39da397SStephan Aßmus // replace these new/delete to malloc/free make sure that the in-place 48e39da397SStephan Aßmus // new is called and take care of calling the destructor too. 49e39da397SStephan Aßmus //------------------------------------------------------------obj_allocator 50e39da397SStephan Aßmus template<class T> struct obj_allocator 51e39da397SStephan Aßmus { allocateobj_allocator52e39da397SStephan Aßmus static T* allocate() { return new T; } deallocateobj_allocator53e39da397SStephan Aßmus static void deallocate(T* ptr) { delete ptr; } 54e39da397SStephan Aßmus }; 55e39da397SStephan Aßmus } 56e39da397SStephan Aßmus #endif 57e39da397SStephan Aßmus 58e39da397SStephan Aßmus 59e39da397SStephan Aßmus //-------------------------------------------------------- Default basic types 60e39da397SStephan Aßmus // 61e39da397SStephan Aßmus // If the compiler has different capacity of the basic types you can redefine 62e39da397SStephan Aßmus // them via the compiler command line or by generating agg_config.h that is 63e39da397SStephan Aßmus // empty by default. 64e39da397SStephan Aßmus // 65e39da397SStephan Aßmus #ifndef AGG_INT8 66e39da397SStephan Aßmus #define AGG_INT8 signed char 67e39da397SStephan Aßmus #endif 68e39da397SStephan Aßmus 69e39da397SStephan Aßmus #ifndef AGG_INT8U 70e39da397SStephan Aßmus #define AGG_INT8U unsigned char 71e39da397SStephan Aßmus #endif 72e39da397SStephan Aßmus 73e39da397SStephan Aßmus #ifndef AGG_INT16 74e39da397SStephan Aßmus #define AGG_INT16 short 75e39da397SStephan Aßmus #endif 76e39da397SStephan Aßmus 77e39da397SStephan Aßmus #ifndef AGG_INT16U 78e39da397SStephan Aßmus #define AGG_INT16U unsigned short 79e39da397SStephan Aßmus #endif 80e39da397SStephan Aßmus 81e39da397SStephan Aßmus #ifndef AGG_INT32 82e39da397SStephan Aßmus #define AGG_INT32 int 83e39da397SStephan Aßmus #endif 84e39da397SStephan Aßmus 85e39da397SStephan Aßmus #ifndef AGG_INT32U 86e39da397SStephan Aßmus #define AGG_INT32U unsigned 87e39da397SStephan Aßmus #endif 88e39da397SStephan Aßmus 89e39da397SStephan Aßmus #ifndef AGG_INT64 90e39da397SStephan Aßmus #if defined(_MSC_VER) || defined(__BORLANDC__) 91e39da397SStephan Aßmus #define AGG_INT64 signed __int64 92e39da397SStephan Aßmus #else 93e39da397SStephan Aßmus #define AGG_INT64 signed long long 94e39da397SStephan Aßmus #endif 95e39da397SStephan Aßmus #endif 96e39da397SStephan Aßmus 97e39da397SStephan Aßmus #ifndef AGG_INT64U 98e39da397SStephan Aßmus #if defined(_MSC_VER) || defined(__BORLANDC__) 99e39da397SStephan Aßmus #define AGG_INT64U unsigned __int64 100e39da397SStephan Aßmus #else 101e39da397SStephan Aßmus #define AGG_INT64U unsigned long long 102e39da397SStephan Aßmus #endif 103e39da397SStephan Aßmus #endif 104e39da397SStephan Aßmus 105e39da397SStephan Aßmus //------------------------------------------------ Some fixes for MS Visual C++ 106e39da397SStephan Aßmus #if defined(_MSC_VER) 107e39da397SStephan Aßmus #pragma warning(disable:4786) // Identifier was truncated... 108e39da397SStephan Aßmus #endif 109e39da397SStephan Aßmus 110e39da397SStephan Aßmus #if defined(_MSC_VER) 111e39da397SStephan Aßmus #define AGG_INLINE __forceinline 112e39da397SStephan Aßmus #else 113e39da397SStephan Aßmus #define AGG_INLINE inline 114e39da397SStephan Aßmus #endif 115e39da397SStephan Aßmus 11639241fe2SDarkWyrm namespace agg 11739241fe2SDarkWyrm { 11839241fe2SDarkWyrm //------------------------------------------------------------------------- 119e39da397SStephan Aßmus typedef AGG_INT8 int8; //----int8 120e39da397SStephan Aßmus typedef AGG_INT8U int8u; //----int8u 121e39da397SStephan Aßmus typedef AGG_INT16 int16; //----int16 122e39da397SStephan Aßmus typedef AGG_INT16U int16u; //----int16u 123e39da397SStephan Aßmus typedef AGG_INT32 int32; //----int32 124e39da397SStephan Aßmus typedef AGG_INT32U int32u; //----int32u 125e39da397SStephan Aßmus typedef AGG_INT64 int64; //----int64 126e39da397SStephan Aßmus typedef AGG_INT64U int64u; //----int64u 12739241fe2SDarkWyrm 128e39da397SStephan Aßmus #if defined(AGG_FISTP) 129e39da397SStephan Aßmus #pragma warning(push) 130e39da397SStephan Aßmus #pragma warning(disable : 4035) //Disable warning "no return value" iround(double v)131e39da397SStephan Aßmus AGG_INLINE int iround(double v) //-------iround 132e39da397SStephan Aßmus { 133e39da397SStephan Aßmus int t; 134e39da397SStephan Aßmus __asm fld qword ptr [v] 135e39da397SStephan Aßmus __asm fistp dword ptr [t] 136e39da397SStephan Aßmus __asm mov eax, dword ptr [t] 137e39da397SStephan Aßmus } uround(double v)138e39da397SStephan Aßmus AGG_INLINE unsigned uround(double v) //-------uround 139e39da397SStephan Aßmus { 140e39da397SStephan Aßmus unsigned t; 141e39da397SStephan Aßmus __asm fld qword ptr [v] 142e39da397SStephan Aßmus __asm fistp dword ptr [t] 143e39da397SStephan Aßmus __asm mov eax, dword ptr [t] 144e39da397SStephan Aßmus } 145e39da397SStephan Aßmus #pragma warning(pop) ifloor(double v)146*8cc5325aSAlexander von Gluck IV AGG_INLINE int ifloor(double v) 147*8cc5325aSAlexander von Gluck IV { 148*8cc5325aSAlexander von Gluck IV return int(floor(v)); 149*8cc5325aSAlexander von Gluck IV } ufloor(double v)150e39da397SStephan Aßmus AGG_INLINE unsigned ufloor(double v) //-------ufloor 151e39da397SStephan Aßmus { 152e39da397SStephan Aßmus return unsigned(floor(v)); 153e39da397SStephan Aßmus } iceil(double v)154*8cc5325aSAlexander von Gluck IV AGG_INLINE int iceil(double v) 155*8cc5325aSAlexander von Gluck IV { 156*8cc5325aSAlexander von Gluck IV return int(ceil(v)); 157*8cc5325aSAlexander von Gluck IV } uceil(double v)158e39da397SStephan Aßmus AGG_INLINE unsigned uceil(double v) //--------uceil 159e39da397SStephan Aßmus { 160e39da397SStephan Aßmus return unsigned(ceil(v)); 161e39da397SStephan Aßmus } 162e39da397SStephan Aßmus #elif defined(AGG_QIFIST) iround(double v)163e39da397SStephan Aßmus AGG_INLINE int iround(double v) 164e39da397SStephan Aßmus { 165e39da397SStephan Aßmus return int(v); 166e39da397SStephan Aßmus } uround(double v)167e39da397SStephan Aßmus AGG_INLINE int uround(double v) 168e39da397SStephan Aßmus { 169e39da397SStephan Aßmus return unsigned(v); 170e39da397SStephan Aßmus } ifloor(double v)171*8cc5325aSAlexander von Gluck IV AGG_INLINE int ifloor(double v) 172*8cc5325aSAlexander von Gluck IV { 173*8cc5325aSAlexander von Gluck IV return int(floor(v)); 174*8cc5325aSAlexander von Gluck IV } ufloor(double v)175e39da397SStephan Aßmus AGG_INLINE unsigned ufloor(double v) 176e39da397SStephan Aßmus { 177e39da397SStephan Aßmus return unsigned(floor(v)); 178e39da397SStephan Aßmus } iceil(double v)179*8cc5325aSAlexander von Gluck IV AGG_INLINE int iceil(double v) 180*8cc5325aSAlexander von Gluck IV { 181*8cc5325aSAlexander von Gluck IV return int(ceil(v)); 182*8cc5325aSAlexander von Gluck IV } uceil(double v)183e39da397SStephan Aßmus AGG_INLINE unsigned uceil(double v) 184e39da397SStephan Aßmus { 185e39da397SStephan Aßmus return unsigned(ceil(v)); 186e39da397SStephan Aßmus } 187e39da397SStephan Aßmus #else iround(double v)188e39da397SStephan Aßmus AGG_INLINE int iround(double v) 189e39da397SStephan Aßmus { 190e39da397SStephan Aßmus return int((v < 0.0) ? v - 0.5 : v + 0.5); 191e39da397SStephan Aßmus } uround(double v)192e39da397SStephan Aßmus AGG_INLINE int uround(double v) 193e39da397SStephan Aßmus { 194e39da397SStephan Aßmus return unsigned(v + 0.5); 195e39da397SStephan Aßmus } ifloor(double v)196*8cc5325aSAlexander von Gluck IV AGG_INLINE int ifloor(double v) 197*8cc5325aSAlexander von Gluck IV { 198*8cc5325aSAlexander von Gluck IV int i = int(v); 199*8cc5325aSAlexander von Gluck IV return i - (i > v); 200*8cc5325aSAlexander von Gluck IV } ufloor(double v)201e39da397SStephan Aßmus AGG_INLINE unsigned ufloor(double v) 202e39da397SStephan Aßmus { 203e39da397SStephan Aßmus return unsigned(v); 204e39da397SStephan Aßmus } iceil(double v)205*8cc5325aSAlexander von Gluck IV AGG_INLINE int iceil(double v) 206*8cc5325aSAlexander von Gluck IV { 207*8cc5325aSAlexander von Gluck IV return int(ceil(v)); 208*8cc5325aSAlexander von Gluck IV } uceil(double v)209e39da397SStephan Aßmus AGG_INLINE unsigned uceil(double v) 210e39da397SStephan Aßmus { 211e39da397SStephan Aßmus return unsigned(ceil(v)); 212e39da397SStephan Aßmus } 213e39da397SStephan Aßmus #endif 214e39da397SStephan Aßmus 215e39da397SStephan Aßmus //---------------------------------------------------------------saturation 216e39da397SStephan Aßmus template<int Limit> struct saturation 217e39da397SStephan Aßmus { iroundsaturation218e39da397SStephan Aßmus AGG_INLINE static int iround(double v) 219e39da397SStephan Aßmus { 220e39da397SStephan Aßmus if(v < double(-Limit)) return -Limit; 221e39da397SStephan Aßmus if(v > double( Limit)) return Limit; 222e39da397SStephan Aßmus return agg::iround(v); 223e39da397SStephan Aßmus } 224e39da397SStephan Aßmus }; 225e39da397SStephan Aßmus 226e39da397SStephan Aßmus //------------------------------------------------------------------mul_one 227e39da397SStephan Aßmus template<unsigned Shift> struct mul_one 228e39da397SStephan Aßmus { mulmul_one229e39da397SStephan Aßmus AGG_INLINE static unsigned mul(unsigned a, unsigned b) 230e39da397SStephan Aßmus { 231*8cc5325aSAlexander von Gluck IV unsigned q = a * b + (1 << (Shift-1)); 232e39da397SStephan Aßmus return (q + (q >> Shift)) >> Shift; 233e39da397SStephan Aßmus } 234e39da397SStephan Aßmus }; 23539241fe2SDarkWyrm 23639241fe2SDarkWyrm //------------------------------------------------------------------------- 23739241fe2SDarkWyrm typedef unsigned char cover_type; //----cover_type 238e39da397SStephan Aßmus enum cover_scale_e 23939241fe2SDarkWyrm { 24039241fe2SDarkWyrm cover_shift = 8, //----cover_shift 24139241fe2SDarkWyrm cover_size = 1 << cover_shift, //----cover_size 24239241fe2SDarkWyrm cover_mask = cover_size - 1, //----cover_mask 24339241fe2SDarkWyrm cover_none = 0, //----cover_none 24439241fe2SDarkWyrm cover_full = cover_mask //----cover_full 24539241fe2SDarkWyrm }; 24639241fe2SDarkWyrm 247e39da397SStephan Aßmus //----------------------------------------------------poly_subpixel_scale_e 248e39da397SStephan Aßmus // These constants determine the subpixel accuracy, to be more precise, 249e39da397SStephan Aßmus // the number of bits of the fractional part of the coordinates. 250e39da397SStephan Aßmus // The possible coordinate capacity in bits can be calculated by formula: 251e39da397SStephan Aßmus // sizeof(int) * 8 - poly_subpixel_shift, i.e, for 32-bit integers and 252e39da397SStephan Aßmus // 8-bits fractional part the capacity is 24 bits. 253e39da397SStephan Aßmus enum poly_subpixel_scale_e 254e39da397SStephan Aßmus { 255e39da397SStephan Aßmus poly_subpixel_shift = 8, //----poly_subpixel_shift 256e39da397SStephan Aßmus poly_subpixel_scale = 1<<poly_subpixel_shift, //----poly_subpixel_scale 257*8cc5325aSAlexander von Gluck IV poly_subpixel_mask = poly_subpixel_scale-1 //----poly_subpixel_mask 258e39da397SStephan Aßmus }; 259e39da397SStephan Aßmus 260e39da397SStephan Aßmus //----------------------------------------------------------filling_rule_e 261e39da397SStephan Aßmus enum filling_rule_e 262e39da397SStephan Aßmus { 263e39da397SStephan Aßmus fill_non_zero, 264e39da397SStephan Aßmus fill_even_odd 265e39da397SStephan Aßmus }; 26639241fe2SDarkWyrm 26739241fe2SDarkWyrm //-----------------------------------------------------------------------pi 26839241fe2SDarkWyrm const double pi = 3.14159265358979323846; 26939241fe2SDarkWyrm 27039241fe2SDarkWyrm //------------------------------------------------------------------deg2rad deg2rad(double deg)27139241fe2SDarkWyrm inline double deg2rad(double deg) 27239241fe2SDarkWyrm { 27339241fe2SDarkWyrm return deg * pi / 180.0; 27439241fe2SDarkWyrm } 27539241fe2SDarkWyrm 27639241fe2SDarkWyrm //------------------------------------------------------------------rad2deg rad2deg(double rad)27739241fe2SDarkWyrm inline double rad2deg(double rad) 27839241fe2SDarkWyrm { 27939241fe2SDarkWyrm return rad * 180.0 / pi; 28039241fe2SDarkWyrm } 28139241fe2SDarkWyrm 28239241fe2SDarkWyrm //----------------------------------------------------------------rect_base 28339241fe2SDarkWyrm template<class T> struct rect_base 28439241fe2SDarkWyrm { 285*8cc5325aSAlexander von Gluck IV typedef T value_type; 28639241fe2SDarkWyrm typedef rect_base<T> self_type; 287*8cc5325aSAlexander von Gluck IV T x1, y1, x2, y2; 28839241fe2SDarkWyrm rect_baserect_base28939241fe2SDarkWyrm rect_base() {} rect_baserect_base29039241fe2SDarkWyrm rect_base(T x1_, T y1_, T x2_, T y2_) : 29139241fe2SDarkWyrm x1(x1_), y1(y1_), x2(x2_), y2(y2_) {} 29239241fe2SDarkWyrm initrect_base293*8cc5325aSAlexander von Gluck IV void init(T x1_, T y1_, T x2_, T y2_) 294*8cc5325aSAlexander von Gluck IV { 295*8cc5325aSAlexander von Gluck IV x1 = x1_; y1 = y1_; x2 = x2_; y2 = y2_; 296*8cc5325aSAlexander von Gluck IV } 297*8cc5325aSAlexander von Gluck IV normalizerect_base29839241fe2SDarkWyrm const self_type& normalize() 29939241fe2SDarkWyrm { 30039241fe2SDarkWyrm T t; 30139241fe2SDarkWyrm if(x1 > x2) { t = x1; x1 = x2; x2 = t; } 30239241fe2SDarkWyrm if(y1 > y2) { t = y1; y1 = y2; y2 = t; } 30339241fe2SDarkWyrm return *this; 30439241fe2SDarkWyrm } 30539241fe2SDarkWyrm cliprect_base30639241fe2SDarkWyrm bool clip(const self_type& r) 30739241fe2SDarkWyrm { 30839241fe2SDarkWyrm if(x2 > r.x2) x2 = r.x2; 30939241fe2SDarkWyrm if(y2 > r.y2) y2 = r.y2; 31039241fe2SDarkWyrm if(x1 < r.x1) x1 = r.x1; 31139241fe2SDarkWyrm if(y1 < r.y1) y1 = r.y1; 31239241fe2SDarkWyrm return x1 <= x2 && y1 <= y2; 31339241fe2SDarkWyrm } 31439241fe2SDarkWyrm is_validrect_base31539241fe2SDarkWyrm bool is_valid() const 31639241fe2SDarkWyrm { 31739241fe2SDarkWyrm return x1 <= x2 && y1 <= y2; 31839241fe2SDarkWyrm } 319*8cc5325aSAlexander von Gluck IV hit_testrect_base320*8cc5325aSAlexander von Gluck IV bool hit_test(T x, T y) const 321*8cc5325aSAlexander von Gluck IV { 322*8cc5325aSAlexander von Gluck IV return (x >= x1 && x <= x2 && y >= y1 && y <= y2); 323*8cc5325aSAlexander von Gluck IV } 324*8cc5325aSAlexander von Gluck IV overlapsrect_base325*8cc5325aSAlexander von Gluck IV bool overlaps(const self_type& r) const 326*8cc5325aSAlexander von Gluck IV { 327*8cc5325aSAlexander von Gluck IV return !(r.x1 > x2 || r.x2 < x1 328*8cc5325aSAlexander von Gluck IV || r.y1 > y2 || r.y2 < y1); 329*8cc5325aSAlexander von Gluck IV } 33039241fe2SDarkWyrm }; 33139241fe2SDarkWyrm 33239241fe2SDarkWyrm //-----------------------------------------------------intersect_rectangles 33339241fe2SDarkWyrm template<class Rect> intersect_rectangles(const Rect & r1,const Rect & r2)33439241fe2SDarkWyrm inline Rect intersect_rectangles(const Rect& r1, const Rect& r2) 33539241fe2SDarkWyrm { 33639241fe2SDarkWyrm Rect r = r1; 33739241fe2SDarkWyrm 33839241fe2SDarkWyrm // First process x2,y2 because the other order 33939241fe2SDarkWyrm // results in Internal Compiler Error under 34039241fe2SDarkWyrm // Microsoft Visual C++ .NET 2003 69462-335-0000007-18038 in 34139241fe2SDarkWyrm // case of "Maximize Speed" optimization option. 34239241fe2SDarkWyrm //----------------- 34339241fe2SDarkWyrm if(r.x2 > r2.x2) r.x2 = r2.x2; 34439241fe2SDarkWyrm if(r.y2 > r2.y2) r.y2 = r2.y2; 34539241fe2SDarkWyrm if(r.x1 < r2.x1) r.x1 = r2.x1; 34639241fe2SDarkWyrm if(r.y1 < r2.y1) r.y1 = r2.y1; 34739241fe2SDarkWyrm return r; 34839241fe2SDarkWyrm } 34939241fe2SDarkWyrm 35039241fe2SDarkWyrm 35139241fe2SDarkWyrm //---------------------------------------------------------unite_rectangles 35239241fe2SDarkWyrm template<class Rect> unite_rectangles(const Rect & r1,const Rect & r2)35339241fe2SDarkWyrm inline Rect unite_rectangles(const Rect& r1, const Rect& r2) 35439241fe2SDarkWyrm { 35539241fe2SDarkWyrm Rect r = r1; 35639241fe2SDarkWyrm if(r.x2 < r2.x2) r.x2 = r2.x2; 35739241fe2SDarkWyrm if(r.y2 < r2.y2) r.y2 = r2.y2; 35839241fe2SDarkWyrm if(r.x1 > r2.x1) r.x1 = r2.x1; 35939241fe2SDarkWyrm if(r.y1 > r2.y1) r.y1 = r2.y1; 36039241fe2SDarkWyrm return r; 36139241fe2SDarkWyrm } 36239241fe2SDarkWyrm 363e39da397SStephan Aßmus typedef rect_base<int> rect_i; //----rect_i 364e39da397SStephan Aßmus typedef rect_base<float> rect_f; //----rect_f 36539241fe2SDarkWyrm typedef rect_base<double> rect_d; //----rect_d 36639241fe2SDarkWyrm 36739241fe2SDarkWyrm //---------------------------------------------------------path_commands_e 36839241fe2SDarkWyrm enum path_commands_e 36939241fe2SDarkWyrm { 37039241fe2SDarkWyrm path_cmd_stop = 0, //----path_cmd_stop 37139241fe2SDarkWyrm path_cmd_move_to = 1, //----path_cmd_move_to 37239241fe2SDarkWyrm path_cmd_line_to = 2, //----path_cmd_line_to 37339241fe2SDarkWyrm path_cmd_curve3 = 3, //----path_cmd_curve3 37439241fe2SDarkWyrm path_cmd_curve4 = 4, //----path_cmd_curve4 375e39da397SStephan Aßmus path_cmd_curveN = 5, //----path_cmd_curveN 376e39da397SStephan Aßmus path_cmd_catrom = 6, //----path_cmd_catrom 377e39da397SStephan Aßmus path_cmd_ubspline = 7, //----path_cmd_ubspline 378e39da397SStephan Aßmus path_cmd_end_poly = 0x0F, //----path_cmd_end_poly 37939241fe2SDarkWyrm path_cmd_mask = 0x0F //----path_cmd_mask 38039241fe2SDarkWyrm }; 38139241fe2SDarkWyrm 38239241fe2SDarkWyrm //------------------------------------------------------------path_flags_e 38339241fe2SDarkWyrm enum path_flags_e 38439241fe2SDarkWyrm { 38539241fe2SDarkWyrm path_flags_none = 0, //----path_flags_none 38639241fe2SDarkWyrm path_flags_ccw = 0x10, //----path_flags_ccw 38739241fe2SDarkWyrm path_flags_cw = 0x20, //----path_flags_cw 38839241fe2SDarkWyrm path_flags_close = 0x40, //----path_flags_close 38939241fe2SDarkWyrm path_flags_mask = 0xF0 //----path_flags_mask 39039241fe2SDarkWyrm }; 39139241fe2SDarkWyrm 39239241fe2SDarkWyrm //---------------------------------------------------------------is_vertex is_vertex(unsigned c)39339241fe2SDarkWyrm inline bool is_vertex(unsigned c) 39439241fe2SDarkWyrm { 39539241fe2SDarkWyrm return c >= path_cmd_move_to && c < path_cmd_end_poly; 39639241fe2SDarkWyrm } 39739241fe2SDarkWyrm 398e39da397SStephan Aßmus //--------------------------------------------------------------is_drawing is_drawing(unsigned c)399e39da397SStephan Aßmus inline bool is_drawing(unsigned c) 400e39da397SStephan Aßmus { 401e39da397SStephan Aßmus return c >= path_cmd_line_to && c < path_cmd_end_poly; 402e39da397SStephan Aßmus } 403e39da397SStephan Aßmus 40439241fe2SDarkWyrm //-----------------------------------------------------------------is_stop is_stop(unsigned c)40539241fe2SDarkWyrm inline bool is_stop(unsigned c) 40639241fe2SDarkWyrm { 40739241fe2SDarkWyrm return c == path_cmd_stop; 40839241fe2SDarkWyrm } 40939241fe2SDarkWyrm 41039241fe2SDarkWyrm //--------------------------------------------------------------is_move_to is_move_to(unsigned c)41139241fe2SDarkWyrm inline bool is_move_to(unsigned c) 41239241fe2SDarkWyrm { 41339241fe2SDarkWyrm return c == path_cmd_move_to; 41439241fe2SDarkWyrm } 41539241fe2SDarkWyrm 41639241fe2SDarkWyrm //--------------------------------------------------------------is_line_to is_line_to(unsigned c)41739241fe2SDarkWyrm inline bool is_line_to(unsigned c) 41839241fe2SDarkWyrm { 41939241fe2SDarkWyrm return c == path_cmd_line_to; 42039241fe2SDarkWyrm } 42139241fe2SDarkWyrm 42239241fe2SDarkWyrm //----------------------------------------------------------------is_curve is_curve(unsigned c)42339241fe2SDarkWyrm inline bool is_curve(unsigned c) 42439241fe2SDarkWyrm { 42539241fe2SDarkWyrm return c == path_cmd_curve3 || c == path_cmd_curve4; 42639241fe2SDarkWyrm } 42739241fe2SDarkWyrm 42839241fe2SDarkWyrm //---------------------------------------------------------------is_curve3 is_curve3(unsigned c)42939241fe2SDarkWyrm inline bool is_curve3(unsigned c) 43039241fe2SDarkWyrm { 43139241fe2SDarkWyrm return c == path_cmd_curve3; 43239241fe2SDarkWyrm } 43339241fe2SDarkWyrm 43439241fe2SDarkWyrm //---------------------------------------------------------------is_curve4 is_curve4(unsigned c)43539241fe2SDarkWyrm inline bool is_curve4(unsigned c) 43639241fe2SDarkWyrm { 43739241fe2SDarkWyrm return c == path_cmd_curve4; 43839241fe2SDarkWyrm } 43939241fe2SDarkWyrm 44039241fe2SDarkWyrm //-------------------------------------------------------------is_end_poly is_end_poly(unsigned c)44139241fe2SDarkWyrm inline bool is_end_poly(unsigned c) 44239241fe2SDarkWyrm { 44339241fe2SDarkWyrm return (c & path_cmd_mask) == path_cmd_end_poly; 44439241fe2SDarkWyrm } 44539241fe2SDarkWyrm 44639241fe2SDarkWyrm //----------------------------------------------------------------is_close is_close(unsigned c)44739241fe2SDarkWyrm inline bool is_close(unsigned c) 44839241fe2SDarkWyrm { 44939241fe2SDarkWyrm return (c & ~(path_flags_cw | path_flags_ccw)) == 45039241fe2SDarkWyrm (path_cmd_end_poly | path_flags_close); 45139241fe2SDarkWyrm } 45239241fe2SDarkWyrm 45339241fe2SDarkWyrm //------------------------------------------------------------is_next_poly is_next_poly(unsigned c)45439241fe2SDarkWyrm inline bool is_next_poly(unsigned c) 45539241fe2SDarkWyrm { 45639241fe2SDarkWyrm return is_stop(c) || is_move_to(c) || is_end_poly(c); 45739241fe2SDarkWyrm } 45839241fe2SDarkWyrm 45939241fe2SDarkWyrm //-------------------------------------------------------------------is_cw is_cw(unsigned c)46039241fe2SDarkWyrm inline bool is_cw(unsigned c) 46139241fe2SDarkWyrm { 46239241fe2SDarkWyrm return (c & path_flags_cw) != 0; 46339241fe2SDarkWyrm } 46439241fe2SDarkWyrm 46539241fe2SDarkWyrm //------------------------------------------------------------------is_ccw is_ccw(unsigned c)46639241fe2SDarkWyrm inline bool is_ccw(unsigned c) 46739241fe2SDarkWyrm { 46839241fe2SDarkWyrm return (c & path_flags_ccw) != 0; 46939241fe2SDarkWyrm } 47039241fe2SDarkWyrm 47139241fe2SDarkWyrm //-------------------------------------------------------------is_oriented is_oriented(unsigned c)47239241fe2SDarkWyrm inline bool is_oriented(unsigned c) 47339241fe2SDarkWyrm { 47439241fe2SDarkWyrm return (c & (path_flags_cw | path_flags_ccw)) != 0; 47539241fe2SDarkWyrm } 47639241fe2SDarkWyrm 47739241fe2SDarkWyrm //---------------------------------------------------------------is_closed is_closed(unsigned c)47839241fe2SDarkWyrm inline bool is_closed(unsigned c) 47939241fe2SDarkWyrm { 48039241fe2SDarkWyrm return (c & path_flags_close) != 0; 48139241fe2SDarkWyrm } 48239241fe2SDarkWyrm 48339241fe2SDarkWyrm //----------------------------------------------------------get_close_flag get_close_flag(unsigned c)48439241fe2SDarkWyrm inline unsigned get_close_flag(unsigned c) 48539241fe2SDarkWyrm { 48639241fe2SDarkWyrm return c & path_flags_close; 48739241fe2SDarkWyrm } 48839241fe2SDarkWyrm 48939241fe2SDarkWyrm //-------------------------------------------------------clear_orientation clear_orientation(unsigned c)49039241fe2SDarkWyrm inline unsigned clear_orientation(unsigned c) 49139241fe2SDarkWyrm { 49239241fe2SDarkWyrm return c & ~(path_flags_cw | path_flags_ccw); 49339241fe2SDarkWyrm } 49439241fe2SDarkWyrm 49539241fe2SDarkWyrm //---------------------------------------------------------get_orientation get_orientation(unsigned c)49639241fe2SDarkWyrm inline unsigned get_orientation(unsigned c) 49739241fe2SDarkWyrm { 49839241fe2SDarkWyrm return c & (path_flags_cw | path_flags_ccw); 49939241fe2SDarkWyrm } 50039241fe2SDarkWyrm 50139241fe2SDarkWyrm //---------------------------------------------------------set_orientation set_orientation(unsigned c,unsigned o)50239241fe2SDarkWyrm inline unsigned set_orientation(unsigned c, unsigned o) 50339241fe2SDarkWyrm { 50439241fe2SDarkWyrm return clear_orientation(c) | o; 50539241fe2SDarkWyrm } 50639241fe2SDarkWyrm 507e39da397SStephan Aßmus //--------------------------------------------------------------point_base 508e39da397SStephan Aßmus template<class T> struct point_base 50939241fe2SDarkWyrm { 510e39da397SStephan Aßmus typedef T value_type; 511e39da397SStephan Aßmus T x,y; point_basepoint_base512e39da397SStephan Aßmus point_base() {} point_basepoint_base513e39da397SStephan Aßmus point_base(T x_, T y_) : x(x_), y(y_) {} 51439241fe2SDarkWyrm }; 515e39da397SStephan Aßmus typedef point_base<int> point_i; //-----point_i 516e39da397SStephan Aßmus typedef point_base<float> point_f; //-----point_f 517e39da397SStephan Aßmus typedef point_base<double> point_d; //-----point_d 51839241fe2SDarkWyrm 519e39da397SStephan Aßmus //-------------------------------------------------------------vertex_base 520e39da397SStephan Aßmus template<class T> struct vertex_base 52139241fe2SDarkWyrm { 522e39da397SStephan Aßmus typedef T value_type; 523e39da397SStephan Aßmus T x,y; 52439241fe2SDarkWyrm unsigned cmd; vertex_basevertex_base525e39da397SStephan Aßmus vertex_base() {} vertex_basevertex_base526e39da397SStephan Aßmus vertex_base(T x_, T y_, unsigned cmd_) : x(x_), y(y_), cmd(cmd_) {} 52739241fe2SDarkWyrm }; 528e39da397SStephan Aßmus typedef vertex_base<int> vertex_i; //-----vertex_i 529e39da397SStephan Aßmus typedef vertex_base<float> vertex_f; //-----vertex_f 530e39da397SStephan Aßmus typedef vertex_base<double> vertex_d; //-----vertex_d 53139241fe2SDarkWyrm 532*8cc5325aSAlexander von Gluck IV //----------------------------------------------------------------row_info 533*8cc5325aSAlexander von Gluck IV template<class T> struct row_info 534*8cc5325aSAlexander von Gluck IV { 535*8cc5325aSAlexander von Gluck IV int x1, x2; 536*8cc5325aSAlexander von Gluck IV T* ptr; row_inforow_info537*8cc5325aSAlexander von Gluck IV row_info() {} row_inforow_info538*8cc5325aSAlexander von Gluck IV row_info(int x1_, int x2_, T* ptr_) : x1(x1_), x2(x2_), ptr(ptr_) {} 539*8cc5325aSAlexander von Gluck IV }; 540*8cc5325aSAlexander von Gluck IV 541*8cc5325aSAlexander von Gluck IV //----------------------------------------------------------const_row_info 542*8cc5325aSAlexander von Gluck IV template<class T> struct const_row_info 543*8cc5325aSAlexander von Gluck IV { 544*8cc5325aSAlexander von Gluck IV int x1, x2; 545*8cc5325aSAlexander von Gluck IV const T* ptr; const_row_infoconst_row_info546*8cc5325aSAlexander von Gluck IV const_row_info() {} const_row_infoconst_row_info547*8cc5325aSAlexander von Gluck IV const_row_info(int x1_, int x2_, const T* ptr_) : 548*8cc5325aSAlexander von Gluck IV x1(x1_), x2(x2_), ptr(ptr_) {} 549*8cc5325aSAlexander von Gluck IV }; 550*8cc5325aSAlexander von Gluck IV 551*8cc5325aSAlexander von Gluck IV //------------------------------------------------------------is_equal_eps is_equal_eps(T v1,T v2,T epsilon)552*8cc5325aSAlexander von Gluck IV template<class T> inline bool is_equal_eps(T v1, T v2, T epsilon) 553*8cc5325aSAlexander von Gluck IV { 554*8cc5325aSAlexander von Gluck IV return fabs(v1 - v2) <= double(epsilon); 555*8cc5325aSAlexander von Gluck IV } 55639241fe2SDarkWyrm } 55739241fe2SDarkWyrm 55839241fe2SDarkWyrm 55939241fe2SDarkWyrm #endif 56039241fe2SDarkWyrm 561