xref: /haiku/headers/libs/agg/agg_span_interpolator_trans.h (revision 5412911f7f8ca41340b0f5cb928ed9726322ab44)
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 //
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 
35         enum
36         {
37             subpixel_shift = SubpixelShift,
38             subpixel_size  = 1 << subpixel_shift
39         };
40 
41         //--------------------------------------------------------------------
42         span_interpolator_trans() {}
43         span_interpolator_trans(const trans_type& trans) : m_trans(&trans) {}
44         span_interpolator_trans(const trans_type& trans,
45                                 double x, double y, unsigned) :
46             m_trans(&trans)
47         {
48             begin(x, y, 0);
49         }
50 
51         //----------------------------------------------------------------
52         const trans_type& transformer() const { return *m_trans; }
53         void transformer(const trans_type& trans) { m_trans = &trans; }
54 
55         //----------------------------------------------------------------
56         void begin(double x, double y, unsigned)
57         {
58             m_x = x;
59             m_y = y;
60             transform();
61         }
62 
63         //----------------------------------------------------------------
64         void operator++()
65         {
66             m_x += 1.0;
67             transform();
68         }
69 
70         //----------------------------------------------------------------
71         void coordinates(int* x, int* y) const
72         {
73             *x = m_ix;
74             *y = m_iy;
75         }
76 
77     private:
78         //----------------------------------------------------------------
79         void transform()
80         {
81             double x = m_x;
82             double y = m_y;
83             m_trans->transform(&x, &y);
84             m_ix = int(x * subpixel_size);
85             m_iy = int(y * subpixel_size);
86         }
87 
88         const trans_type* m_trans;
89         double            m_x;
90         double            m_y;
91         int               m_ix;
92         int               m_iy;
93     };
94 
95 }
96 
97 #endif
98