Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | Related Pages | Examples

agg_basics.h

00001 //----------------------------------------------------------------------------
00002 // Anti-Grain Geometry - Version 2.2
00003 // Copyright (C) 2002-2004 Maxim Shemanarev (http://www.antigrain.com)
00004 //
00005 // Permission to copy, use, modify, sell and distribute this software 
00006 // is granted provided this copyright notice appears in all copies. 
00007 // This software is provided "as is" without express or implied
00008 // warranty, and with no claim as to its suitability for any purpose.
00009 //
00010 //----------------------------------------------------------------------------
00011 // Contact: mcseem@antigrain.com
00012 //          mcseemagg@yahoo.com
00013 //          http://www.antigrain.com
00014 //----------------------------------------------------------------------------
00015 
00016 #ifndef AGG_BASICS_INCLUDED
00017 #define AGG_BASICS_INCLUDED
00018 
00022 namespace agg
00023 {
00024     //-------------------------------------------------------------------------
00025     typedef signed char    int8;         //----int8
00026     typedef unsigned char  int8u;        //----int8u
00027     typedef signed short   int16;        //----int16
00028     typedef unsigned short int16u;       //----int16u
00029     typedef signed int     int32;        //----int32
00030     typedef unsigned int   int32u;       //----int32u
00031 
00032 
00033     //-------------------------------------------------------------------------
00034     typedef unsigned char cover_type;    //----cover_type
00035     enum
00036     {
00037         cover_shift = 8,                 //----cover_shift
00038         cover_size  = 1 << cover_shift,  //----cover_size 
00039         cover_mask  = cover_size - 1,    //----cover_mask 
00040         cover_none  = 0,                 //----cover_none 
00041         cover_full  = cover_mask         //----cover_full 
00042     };
00043 
00044 
00045     //-----------------------------------------------------------------------pi
00046     const double pi = 3.14159265358979323846;
00047 
00048     //------------------------------------------------------------------deg2rad
00049     inline double deg2rad(double deg)
00050     {
00051         return deg * pi / 180.0;
00052     }
00053 
00054     //------------------------------------------------------------------rad2deg
00055     inline double rad2deg(double rad)
00056     {
00057         return rad * 180.0 / pi;
00058     }
00059  
00060     //----------------------------------------------------------------rect_base
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     //-----------------------------------------------------intersect_rectangles
00097     template<class Rect> 
00098     inline Rect intersect_rectangles(const Rect& r1, const Rect& r2)
00099     {
00100         Rect r = r1;
00101 
00102         // First process x2,y2 because the other order 
00103         // results in Internal Compiler Error under 
00104         // Microsoft Visual C++ .NET 2003 69462-335-0000007-18038 in 
00105         // case of "Maximize Speed" optimization option.
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     //---------------------------------------------------------unite_rectangles
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;   //----rect
00128     typedef rect_base<double> rect_d; //----rect_d
00129 
00130     //---------------------------------------------------------path_commands_e
00131     enum path_commands_e
00132     {
00133         path_cmd_stop     = 0,        //----path_cmd_stop    
00134         path_cmd_move_to  = 1,        //----path_cmd_move_to 
00135         path_cmd_line_to  = 2,        //----path_cmd_line_to 
00136         path_cmd_curve3   = 3,        //----path_cmd_curve3  
00137         path_cmd_curve4   = 4,        //----path_cmd_curve4  
00138         path_cmd_end_poly = 6,        //----path_cmd_end_poly
00139         path_cmd_mask     = 0x0F      //----path_cmd_mask    
00140     };
00141 
00142     //------------------------------------------------------------path_flags_e
00143     enum path_flags_e
00144     {
00145         path_flags_none  = 0,         //----path_flags_none 
00146         path_flags_ccw   = 0x10,      //----path_flags_ccw  
00147         path_flags_cw    = 0x20,      //----path_flags_cw   
00148         path_flags_close = 0x40,      //----path_flags_close
00149         path_flags_mask  = 0xF0       //----path_flags_mask 
00150     };
00151 
00152     //---------------------------------------------------------------is_vertex
00153     inline bool is_vertex(unsigned c)
00154     {
00155         return c >= path_cmd_move_to && c < path_cmd_end_poly;
00156     }
00157 
00158     //-----------------------------------------------------------------is_stop
00159     inline bool is_stop(unsigned c)
00160     { 
00161         return c == path_cmd_stop;
00162     }
00163 
00164     //--------------------------------------------------------------is_move_to
00165     inline bool is_move_to(unsigned c)
00166     {
00167         return c == path_cmd_move_to;
00168     }
00169 
00170     //--------------------------------------------------------------is_line_to
00171     inline bool is_line_to(unsigned c)
00172     {
00173         return c == path_cmd_line_to;
00174     }
00175 
00176     //----------------------------------------------------------------is_curve
00177     inline bool is_curve(unsigned c)
00178     {
00179         return c == path_cmd_curve3 || c == path_cmd_curve4;
00180     }
00181 
00182     //---------------------------------------------------------------is_curve3
00183     inline bool is_curve3(unsigned c)
00184     {
00185         return c == path_cmd_curve3;
00186     }
00187 
00188     //---------------------------------------------------------------is_curve4
00189     inline bool is_curve4(unsigned c)
00190     {
00191         return c == path_cmd_curve4;
00192     }
00193 
00194     //-------------------------------------------------------------is_end_poly
00195     inline bool is_end_poly(unsigned c)
00196     {
00197         return (c & path_cmd_mask) == path_cmd_end_poly;
00198     }
00199 
00200     //----------------------------------------------------------------is_close
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     //------------------------------------------------------------is_next_poly
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     //-------------------------------------------------------------------is_cw
00214     inline bool is_cw(unsigned c)
00215     {
00216         return (c & path_flags_cw) != 0;
00217     }
00218 
00219     //------------------------------------------------------------------is_ccw
00220     inline bool is_ccw(unsigned c)
00221     {
00222         return (c & path_flags_ccw) != 0;
00223     }
00224 
00225     //-------------------------------------------------------------is_oriented
00226     inline bool is_oriented(unsigned c)
00227     {
00228         return (c & (path_flags_cw | path_flags_ccw)) != 0; 
00229     }
00230 
00231     //---------------------------------------------------------------is_closed
00232     inline bool is_closed(unsigned c)
00233     {
00234         return (c & path_flags_close) != 0; 
00235     }
00236 
00237     //----------------------------------------------------------get_close_flag
00238     inline unsigned get_close_flag(unsigned c)
00239     {
00240         return c & path_flags_close; 
00241     }
00242 
00243     //-------------------------------------------------------clear_orientation
00244     inline unsigned clear_orientation(unsigned c)
00245     {
00246         return c & ~(path_flags_cw | path_flags_ccw);
00247     }
00248 
00249     //---------------------------------------------------------get_orientation
00250     inline unsigned get_orientation(unsigned c)
00251     {
00252         return c & (path_flags_cw | path_flags_ccw);
00253     }
00254 
00255     //---------------------------------------------------------set_orientation
00256     inline unsigned set_orientation(unsigned c, unsigned o)
00257     {
00258         return clear_orientation(c) | o;
00259     }
00260 
00261     //--------------------------------------------------------------point_type
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     //-------------------------------------------------------------vertex_type
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 

Generated on Wed Feb 9 11:31:34 2005 for OpenGUI by  doxygen 1.4.0