1 //---------------------------------------------------------------------------- 2 // Anti-Grain Geometry - Version 2.2 3 // Copyright (C) 2002-2004 Maxim Shemanarev (http://www.antigrain.com) 4 // 5 // Permission to copy, use, modify, sell and distribute this software 6 // is granted provided this copyright notice appears in all copies. 7 // This software is provided "as is" without express or implied 8 // warranty, and with no claim as to its suitability for any purpose. 9 // 10 //---------------------------------------------------------------------------- 11 // Contact: mcseem@antigrain.com 12 // mcseemagg@yahoo.com 13 // http://www.antigrain.com 14 //---------------------------------------------------------------------------- 15 #ifndef AGG_LINE_AA_BASICS_INCLUDED 16 #define AGG_LINE_AA_BASICS_INCLUDED 17 18 #include <stdlib.h> 19 #include "agg_basics.h" 20 21 namespace agg 22 { 23 24 // See Implementation agg_line_aa_basics.cpp 25 26 //------------------------------------------------------------------------- 27 enum 28 { 29 line_subpixel_shift = 8, //----line_subpixel_shift 30 line_subpixel_size = 1 << line_subpixel_shift, //----line_subpixel_size 31 line_subpixel_mask = line_subpixel_size - 1 //----line_subpixel_mask 32 }; 33 34 //------------------------------------------------------------------------- 35 enum 36 { 37 line_mr_subpixel_shift = 4, //----line_mr_subpixel_shift 38 line_mr_subpixel_size = 1 << line_mr_subpixel_shift, //----line_mr_subpixel_size 39 line_mr_subpixel_mask = line_mr_subpixel_size - 1 //----line_mr_subpixel_mask 40 }; 41 42 //------------------------------------------------------------------line_mr 43 inline int line_mr(int x) 44 { 45 return x >> (line_subpixel_shift - line_mr_subpixel_shift); 46 } 47 48 //-------------------------------------------------------------------line_hr 49 inline int line_hr(int x) 50 { 51 return x << (line_subpixel_shift - line_mr_subpixel_shift); 52 } 53 54 //---------------------------------------------------------------line_dbl_hr 55 inline int line_dbl_hr(int x) 56 { 57 return x << line_subpixel_shift; 58 } 59 60 //---------------------------------------------------------------line_coord 61 inline int line_coord(double x) 62 { 63 return int(x * line_subpixel_size); 64 } 65 66 //==========================================================line_parameters 67 struct line_parameters 68 { 69 //--------------------------------------------------------------------- 70 line_parameters() {} 71 line_parameters(int x1_, int y1_, int x2_, int y2_, int len_) : 72 x1(x1_), y1(y1_), x2(x2_), y2(y2_), 73 dx(abs(x2_ - x1_)), 74 dy(abs(y2_ - y1_)), 75 sx((x2_ > x1_) ? 1 : -1), 76 sy((y2_ > y1_) ? 1 : -1), 77 vertical(dy >= dx), 78 inc(vertical ? sy : sx), 79 len(len_), 80 octant((sy & 4) | (sx & 2) | int(vertical)) 81 { 82 } 83 84 //--------------------------------------------------------------------- 85 unsigned orthogonal_quadrant() const { return s_orthogonal_quadrant[octant]; } 86 unsigned diagonal_quadrant() const { return s_diagonal_quadrant[octant]; } 87 88 //--------------------------------------------------------------------- 89 bool same_orthogonal_quadrant(const line_parameters& lp) const 90 { 91 return s_orthogonal_quadrant[octant] == s_orthogonal_quadrant[lp.octant]; 92 } 93 94 //--------------------------------------------------------------------- 95 bool same_diagonal_quadrant(const line_parameters& lp) const 96 { 97 return s_diagonal_quadrant[octant] == s_diagonal_quadrant[lp.octant]; 98 } 99 100 //--------------------------------------------------------------------- 101 int x1, y1, x2, y2, dx, dy, sx, sy; 102 bool vertical; 103 int inc; 104 int len; 105 int octant; 106 107 //--------------------------------------------------------------------- 108 static int8u s_orthogonal_quadrant[8]; 109 static int8u s_diagonal_quadrant[8]; 110 }; 111 112 113 114 // See Implementation agg_line_aa_basics.cpp 115 116 //----------------------------------------------------------------bisectrix 117 void bisectrix(const line_parameters& l1, 118 const line_parameters& l2, 119 int* x, int* y); 120 121 } 122 123 #endif 124