Home | History | Annotate | Download | only in agg23
      1 
      2 //----------------------------------------------------------------------------
      3 // Anti-Grain Geometry - Version 2.3
      4 // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
      5 //
      6 // Permission to copy, use, modify, sell and distribute this software
      7 // is granted provided this copyright notice appears in all copies.
      8 // This software is provided "as is" without express or implied
      9 // warranty, and with no claim as to its suitability for any purpose.
     10 //
     11 //----------------------------------------------------------------------------
     12 // Contact: mcseem (at) antigrain.com
     13 //          mcseemagg (at) yahoo.com
     14 //          http://www.antigrain.com
     15 //----------------------------------------------------------------------------
     16 #ifndef AGG_BASICS_INCLUDED
     17 #define AGG_BASICS_INCLUDED
     18 #ifndef AGG_INT8
     19 #define AGG_INT8 signed char
     20 #endif
     21 #ifndef AGG_INT8U
     22 #define AGG_INT8U unsigned char
     23 #endif
     24 #ifndef AGG_INT16
     25 #define AGG_INT16 short
     26 #endif
     27 #ifndef AGG_INT16U
     28 #define AGG_INT16U unsigned short
     29 #endif
     30 #ifndef AGG_INT32
     31 #define AGG_INT32 int
     32 #endif
     33 #ifndef AGG_INT32U
     34 #define AGG_INT32U unsigned
     35 #endif
     36 #ifndef AGG_INT64
     37 #define AGG_INT64 signed long long
     38 #endif
     39 #ifndef AGG_INT64U
     40 #define AGG_INT64U unsigned long long
     41 #endif
     42 #define AGG_INLINE inline
     43 
     44 #include "core/include/fxcrt/fx_system.h"  // For FX_FLOAT
     45 
     46 namespace agg
     47 {
     48 typedef AGG_INT8   int8;
     49 typedef AGG_INT8U  int8u;
     50 typedef AGG_INT16  int16;
     51 typedef AGG_INT16U int16u;
     52 typedef AGG_INT32  int32;
     53 typedef AGG_INT32U int32u;
     54 typedef AGG_INT64  int64;
     55 typedef AGG_INT64U int64u;
     56 typedef unsigned char cover_type;
     57 enum cover_scale_e {
     58     cover_shift = 8,
     59     cover_size  = 1 << cover_shift,
     60     cover_mask  = cover_size - 1,
     61     cover_none  = 0,
     62     cover_full  = cover_mask
     63 };
     64 template<class T> struct rect_base  {
     65     typedef rect_base<T> self_type;
     66     T x1;
     67     T y1;
     68     T x2;
     69     T y2;
     70     rect_base() {}
     71     rect_base(T x1_, T y1_, T x2_, T y2_) :
     72         x1(x1_), y1(y1_), x2(x2_), y2(y2_) {}
     73     const self_type& normalize()
     74     {
     75         T t;
     76         if(x1 > x2) {
     77             t = x1;
     78             x1 = x2;
     79             x2 = t;
     80         }
     81         if(y1 > y2) {
     82             t = y1;
     83             y1 = y2;
     84             y2 = t;
     85         }
     86         return *this;
     87     }
     88     bool clip(const self_type& r)
     89     {
     90         if(x2 > r.x2) {
     91             x2 = r.x2;
     92         }
     93         if(y2 > r.y2) {
     94             y2 = r.y2;
     95         }
     96         if(x1 < r.x1) {
     97             x1 = r.x1;
     98         }
     99         if(y1 < r.y1) {
    100             y1 = r.y1;
    101         }
    102         return x1 <= x2 && y1 <= y2;
    103     }
    104     bool is_valid() const
    105     {
    106         return x1 <= x2 && y1 <= y2;
    107     }
    108 };
    109 template<class Rect>
    110 inline Rect intersect_rectangles(const Rect& r1, const Rect& r2)
    111 {
    112     Rect r = r1;
    113     if(r.x2 > r2.x2) {
    114         r.x2 = r2.x2;
    115     }
    116     if(r.y2 > r2.y2) {
    117         r.y2 = r2.y2;
    118     }
    119     if(r.x1 < r2.x1) {
    120         r.x1 = r2.x1;
    121     }
    122     if(r.y1 < r2.y1) {
    123         r.y1 = r2.y1;
    124     }
    125     return r;
    126 }
    127 template<class Rect>
    128 inline Rect unite_rectangles(const Rect& r1, const Rect& r2)
    129 {
    130     Rect r = r1;
    131     if(r.x2 < r2.x2) {
    132         r.x2 = r2.x2;
    133     }
    134     if(r.y2 < r2.y2) {
    135         r.y2 = r2.y2;
    136     }
    137     if(r.x1 > r2.x1) {
    138         r.x1 = r2.x1;
    139     }
    140     if(r.y1 > r2.y1) {
    141         r.y1 = r2.y1;
    142     }
    143     return r;
    144 }
    145 typedef rect_base<int>    rect;
    146 typedef rect_base<FX_FLOAT> rect_d;
    147 enum path_commands_e {
    148     path_cmd_stop     = 0,
    149     path_cmd_move_to  = 1,
    150     path_cmd_line_to  = 2,
    151     path_cmd_curve3   = 3,
    152     path_cmd_curve4   = 4,
    153     path_cmd_curveN   = 5,
    154     path_cmd_catrom   = 6,
    155     path_cmd_ubspline = 7,
    156     path_cmd_end_poly = 0x0F,
    157     path_cmd_mask     = 0x0F
    158 };
    159 enum path_flags_e {
    160     path_flags_none  = 0,
    161     path_flags_ccw   = 0x10,
    162     path_flags_cw    = 0x20,
    163     path_flags_close = 0x40,
    164     path_flags_jr	 = 0x80,
    165     path_flags_mask  = 0xF0
    166 };
    167 inline bool is_vertex(unsigned c)
    168 {
    169     c &= ~path_flags_jr;
    170     return c >= path_cmd_move_to && c < path_cmd_end_poly;
    171 }
    172 inline bool is_drawing(unsigned c)
    173 {
    174     c &= ~path_flags_jr;
    175     return c >= path_cmd_line_to && c < path_cmd_end_poly;
    176 }
    177 inline bool is_stop(unsigned c)
    178 {
    179     c &= ~path_flags_jr;
    180     return c == path_cmd_stop;
    181 }
    182 inline bool is_move_to(unsigned c)
    183 {
    184     c &= ~path_flags_jr;
    185     return c == path_cmd_move_to;
    186 }
    187 inline bool is_line_to(unsigned c)
    188 {
    189     c &= ~path_flags_jr;
    190     return c == path_cmd_line_to;
    191 }
    192 inline bool is_curve(unsigned c)
    193 {
    194     c &= ~path_flags_jr;
    195     return c == path_cmd_curve3 || c == path_cmd_curve4;
    196 }
    197 inline bool is_curve3(unsigned c)
    198 {
    199     c &= ~path_flags_jr;
    200     return c == path_cmd_curve3;
    201 }
    202 inline bool is_curve4(unsigned c)
    203 {
    204     c &= ~path_flags_jr;
    205     return c == path_cmd_curve4;
    206 }
    207 inline bool is_end_poly(unsigned c)
    208 {
    209     c &= ~path_flags_jr;
    210     return (c & path_cmd_mask) == path_cmd_end_poly;
    211 }
    212 inline bool is_close(unsigned c)
    213 {
    214     c &= ~path_flags_jr;
    215     return (c & ~(path_flags_cw | path_flags_ccw)) ==
    216            (path_cmd_end_poly | path_flags_close);
    217 }
    218 inline bool is_next_poly(unsigned c)
    219 {
    220     c &= ~path_flags_jr;
    221     return is_stop(c) || is_move_to(c) || is_end_poly(c);
    222 }
    223 inline bool is_cw(unsigned c)
    224 {
    225     c &= ~path_flags_jr;
    226     return (c & path_flags_cw) != 0;
    227 }
    228 inline bool is_ccw(unsigned c)
    229 {
    230     c &= ~path_flags_jr;
    231     return (c & path_flags_ccw) != 0;
    232 }
    233 inline bool is_oriented(unsigned c)
    234 {
    235     c &= ~path_flags_jr;
    236     return (c & (path_flags_cw | path_flags_ccw)) != 0;
    237 }
    238 inline bool is_closed(unsigned c)
    239 {
    240     c &= ~path_flags_jr;
    241     return (c & path_flags_close) != 0;
    242 }
    243 inline unsigned get_close_flag(unsigned c)
    244 {
    245     c &= ~path_flags_jr;
    246     return c & path_flags_close;
    247 }
    248 inline unsigned clear_orientation(unsigned c)
    249 {
    250     c &= ~path_flags_jr;
    251     return c & ~(path_flags_cw | path_flags_ccw);
    252 }
    253 inline unsigned get_orientation(unsigned c)
    254 {
    255     c &= ~path_flags_jr;
    256     return c & (path_flags_cw | path_flags_ccw);
    257 }
    258 inline unsigned set_orientation(unsigned c, unsigned o)
    259 {
    260     c &= ~path_flags_jr;
    261     return clear_orientation(c) | o;
    262 }
    263 struct point_type  {
    264     FX_FLOAT x, y;
    265     unsigned flag;
    266     point_type() {}
    267     point_type(FX_FLOAT x_, FX_FLOAT y_, unsigned flag_ = 0) : x(x_), y(y_), flag(flag_) {}
    268 };
    269 struct point_type_flag : public point_type {
    270     unsigned flag;
    271     point_type_flag()
    272     {
    273         flag = 0;
    274     }
    275     point_type_flag(FX_FLOAT x_, FX_FLOAT y_, unsigned flag_ = 0) : point_type(x_, y_), flag(flag_) {}
    276 };
    277 struct vertex_type  {
    278     FX_FLOAT   x, y;
    279     unsigned cmd;
    280     vertex_type() {}
    281     vertex_type(FX_FLOAT x_, FX_FLOAT y_, unsigned cmd_) :
    282         x(x_), y(y_), cmd(cmd_) {}
    283 };
    284 }
    285 #endif
    286