xref: /haiku/headers/libs/agg/agg_span_interpolator_linear.h (revision 93aeb8c3bc3f13cb1f282e3e749258a23790d947)
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 #ifndef AGG_SPAN_INTERPOLATOR_LINEAR_INCLUDED
17 #define AGG_SPAN_INTERPOLATOR_LINEAR_INCLUDED
18 
19 #include "agg_basics.h"
20 #include "agg_dda_line.h"
21 #include "agg_trans_affine.h"
22 
23 namespace agg
24 {
25 
26     //================================================span_interpolator_linear
27     template<class Transformer = trans_affine, unsigned SubpixelShift = 8>
28     class span_interpolator_linear
29     {
30     public:
31         typedef Transformer trans_type;
32 
33         enum
34         {
35             subpixel_shift = SubpixelShift,
36             subpixel_size  = 1 << subpixel_shift
37         };
38 
39         //--------------------------------------------------------------------
40         span_interpolator_linear() {}
41         span_interpolator_linear(const trans_type& trans) : m_trans(&trans) {}
42         span_interpolator_linear(const trans_type& trans,
43                                  double x, double y, unsigned len) :
44             m_trans(&trans)
45         {
46             begin(x, y, len);
47         }
48 
49         //----------------------------------------------------------------
50         const trans_type& transformer() const { return *m_trans; }
51         void transformer(const trans_type& trans) { m_trans = &trans; }
52 
53         //----------------------------------------------------------------
54         void begin(double x, double y, unsigned len)
55         {
56             double tx;
57             double ty;
58 
59             tx = x;
60             ty = y;
61             m_trans->transform(&tx, &ty);
62             int x1 = int(tx * subpixel_size);
63             int y1 = int(ty * subpixel_size);
64 
65             tx = x + len;
66             ty = y;
67             m_trans->transform(&tx, &ty);
68             int x2 = int(tx * subpixel_size);
69             int y2 = int(ty * subpixel_size);
70 
71             m_li_x = dda2_line_interpolator(x1, x2, len);
72             m_li_y = dda2_line_interpolator(y1, y2, len);
73         }
74 
75         //----------------------------------------------------------------
76         void operator++()
77         {
78             ++m_li_x;
79             ++m_li_y;
80         }
81 
82         //----------------------------------------------------------------
83         void coordinates(int* x, int* y) const
84         {
85             *x = m_li_x.y();
86             *y = m_li_y.y();
87         }
88 
89     private:
90         const trans_type* m_trans;
91         dda2_line_interpolator m_li_x;
92         dda2_line_interpolator m_li_y;
93     };
94 
95 }
96 
97 
98 
99 #endif
100 
101 
102