1 //---------------------------------------------------------------------------- 2 // Anti-Grain Geometry - Version 2.4 3 // Copyright (C) 2002-2005 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 // 16 // Horizontal span interpolator for use with an arbitrary transformer 17 // The efficiency highly depends on the operations done in the transformer 18 // 19 //---------------------------------------------------------------------------- 20 21 #ifndef AGG_SPAN_INTERPOLATOR_TRANS_INCLUDED 22 #define AGG_SPAN_INTERPOLATOR_TRANS_INCLUDED 23 24 #include "agg_basics.h" 25 26 namespace agg 27 { 28 //=================================================span_interpolator_trans 29 template<class Transformer, unsigned SubpixelShift = 8> 30 class span_interpolator_trans 31 { 32 public: 33 typedef Transformer trans_type; 34 enum subpixel_scale_e 35 { 36 subpixel_shift = SubpixelShift, 37 subpixel_scale = 1 << subpixel_shift 38 }; 39 40 //-------------------------------------------------------------------- span_interpolator_trans()41 span_interpolator_trans() {} span_interpolator_trans(const trans_type & trans)42 span_interpolator_trans(const trans_type& trans) : m_trans(&trans) {} span_interpolator_trans(const trans_type & trans,double x,double y,unsigned)43 span_interpolator_trans(const trans_type& trans, 44 double x, double y, unsigned) : 45 m_trans(&trans) 46 { 47 begin(x, y, 0); 48 } 49 50 //---------------------------------------------------------------- transformer()51 const trans_type& transformer() const { return *m_trans; } transformer(const trans_type & trans)52 void transformer(const trans_type& trans) { m_trans = &trans; } 53 54 //---------------------------------------------------------------- begin(double x,double y,unsigned)55 void begin(double x, double y, unsigned) 56 { 57 m_x = x; 58 m_y = y; 59 m_trans->transform(&x, &y); 60 m_ix = iround(x * subpixel_scale); 61 m_iy = iround(y * subpixel_scale); 62 } 63 64 //---------------------------------------------------------------- 65 void operator++() 66 { 67 m_x += 1.0; 68 double x = m_x; 69 double y = m_y; 70 m_trans->transform(&x, &y); 71 m_ix = iround(x * subpixel_scale); 72 m_iy = iround(y * subpixel_scale); 73 } 74 75 //---------------------------------------------------------------- coordinates(int * x,int * y)76 void coordinates(int* x, int* y) const 77 { 78 *x = m_ix; 79 *y = m_iy; 80 } 81 82 private: 83 const trans_type* m_trans; 84 double m_x; 85 double m_y; 86 int m_ix; 87 int m_iy; 88 }; 89 90 } 91 92 #endif 93