1 //---------------------------------------------------------------------------- 2 // Anti-Grain Geometry (AGG) - Version 2.5 3 // A high quality rendering engine for C++ 4 // Copyright (C) 2002-2006 Maxim Shemanarev 5 // Contact: mcseem@antigrain.com 6 // mcseemagg@yahoo.com 7 // http://antigrain.com 8 // 9 // AGG is free software; you can redistribute it and/or 10 // modify it under the terms of the GNU General Public License 11 // as published by the Free Software Foundation; either version 2 12 // of the License, or (at your option) any later version. 13 // 14 // AGG is distributed in the hope that it will be useful, 15 // but WITHOUT ANY WARRANTY; without even the implied warranty of 16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 // GNU General Public License for more details. 18 // 19 // You should have received a copy of the GNU General Public License 20 // along with AGG; if not, write to the Free Software 21 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 22 // MA 02110-1301, USA. 23 //---------------------------------------------------------------------------- 24 // 25 // Horizontal span interpolator for use with an arbitrary transformer 26 // The efficiency highly depends on the operations done in the transformer 27 // 28 //---------------------------------------------------------------------------- 29 30 #ifndef AGG_SPAN_INTERPOLATOR_TRANS_INCLUDED 31 #define AGG_SPAN_INTERPOLATOR_TRANS_INCLUDED 32 33 #include "agg_basics.h" 34 35 namespace agg 36 { 37 //=================================================span_interpolator_trans 38 template<class Transformer, unsigned SubpixelShift = 8> 39 class span_interpolator_trans 40 { 41 public: 42 typedef Transformer trans_type; 43 enum subpixel_scale_e 44 { 45 subpixel_shift = SubpixelShift, 46 subpixel_scale = 1 << subpixel_shift 47 }; 48 49 //-------------------------------------------------------------------- span_interpolator_trans()50 span_interpolator_trans() {} span_interpolator_trans(const trans_type & trans)51 span_interpolator_trans(const trans_type& trans) : m_trans(&trans) {} span_interpolator_trans(const trans_type & trans,double x,double y,unsigned)52 span_interpolator_trans(const trans_type& trans, 53 double x, double y, unsigned) : 54 m_trans(&trans) 55 { 56 begin(x, y, 0); 57 } 58 59 //---------------------------------------------------------------- transformer()60 const trans_type& transformer() const { return *m_trans; } transformer(const trans_type & trans)61 void transformer(const trans_type& trans) { m_trans = &trans; } 62 63 //---------------------------------------------------------------- begin(double x,double y,unsigned)64 void begin(double x, double y, unsigned) 65 { 66 m_x = x; 67 m_y = y; 68 m_trans->transform(&x, &y); 69 m_ix = iround(x * subpixel_scale); 70 m_iy = iround(y * subpixel_scale); 71 } 72 73 //---------------------------------------------------------------- 74 void operator++() 75 { 76 m_x += 1.0; 77 double x = m_x; 78 double y = m_y; 79 m_trans->transform(&x, &y); 80 m_ix = iround(x * subpixel_scale); 81 m_iy = iround(y * subpixel_scale); 82 } 83 84 //---------------------------------------------------------------- coordinates(int * x,int * y)85 void coordinates(int* x, int* y) const 86 { 87 *x = m_ix; 88 *y = m_iy; 89 } 90 91 private: 92 const trans_type* m_trans; 93 double m_x; 94 double m_y; 95 int m_ix; 96 int m_iy; 97 }; 98 99 } 100 101 #endif 102