1 //----------------------------------------------------------------------------
2 // Anti-Grain Geometry - Version 2.3
3 // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
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.
10 //----------------------------------------------------------------------------
11 // Contact: mcseem@antigrain.com
12 // mcseemagg@yahoo.com
13 // http://www.antigrain.com
14 //----------------------------------------------------------------------------
15 #ifndef AGG_SPAN_SUBDIV_ADAPTOR_INCLUDED
16 #define AGG_SPAN_SUBDIV_ADAPTOR_INCLUDED
18 #include "agg_basics.h"
23 //=================================================span_subdiv_adaptor
24 template<class Interpolator
, unsigned SubpixelShift
= 8>
25 class span_subdiv_adaptor
28 typedef Interpolator interpolator_type
;
29 typedef typename
interpolator_type::trans_type trans_type
;
33 subpixel_shift
= SubpixelShift
,
34 subpixel_size
= 1 << subpixel_shift
38 //----------------------------------------------------------------
39 span_subdiv_adaptor() :
41 m_subdiv_size(1 << m_subdiv_shift
),
42 m_subdiv_mask(m_subdiv_size
- 1) {}
44 span_subdiv_adaptor(interpolator_type
& interpolator
,
45 unsigned subdiv_shift
= 4) :
46 m_subdiv_shift(subdiv_shift
),
47 m_subdiv_size(1 << m_subdiv_shift
),
48 m_subdiv_mask(m_subdiv_size
- 1),
49 m_interpolator(&interpolator
) {}
51 span_subdiv_adaptor(interpolator_type
& interpolator
,
52 double x
, double y
, unsigned len
,
53 unsigned subdiv_shift
= 4) :
54 m_subdiv_shift(subdiv_shift
),
55 m_subdiv_size(1 << m_subdiv_shift
),
56 m_subdiv_mask(m_subdiv_size
- 1),
57 m_interpolator(&interpolator
)
63 //----------------------------------------------------------------
64 const interpolator_type
& interpolator() const { return *m_interpolator
; }
65 void interpolator(interpolator_type
& intr
) { m_interpolator
= &intr
; }
67 //----------------------------------------------------------------
68 const trans_type
& transformer() const
70 return *m_interpolator
->transformer();
72 void transformer(const trans_type
& trans
)
74 m_interpolator
->transformer(trans
);
77 //----------------------------------------------------------------
78 unsigned subdiv_shift() const { return m_subdiv_shift
; }
79 void subdiv_shift(unsigned shift
)
81 m_subdiv_shift
= shift
;
82 m_subdiv_size
= 1 << m_subdiv_shift
;
83 m_subdiv_mask
= m_subdiv_size
- 1;
86 //----------------------------------------------------------------
87 void begin(double x
, double y
, unsigned len
)
90 m_src_x
= int(x
* subpixel_size
) + subpixel_size
;
93 if(len
> m_subdiv_size
) len
= m_subdiv_size
;
94 m_interpolator
->begin(x
, y
, len
);
97 //----------------------------------------------------------------
101 if(m_pos
>= m_subdiv_size
)
103 unsigned len
= m_len
;
104 if(len
> m_subdiv_size
) len
= m_subdiv_size
;
105 m_interpolator
->resynchronize(double(m_src_x
) / double(subpixel_size
) + len
,
110 m_src_x
+= subpixel_size
;
115 //----------------------------------------------------------------
116 void coordinates(int* x
, int* y
) const
118 m_interpolator
->coordinates(x
, y
);
121 //----------------------------------------------------------------
122 void local_scale(int* x
, int* y
) const
124 m_interpolator
->local_scale(x
, y
);
129 unsigned m_subdiv_shift
;
130 unsigned m_subdiv_size
;
131 unsigned m_subdiv_mask
;
132 interpolator_type
* m_interpolator
;