00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef AGG_SPAN_INTERPOLATOR_LINEAR_INCLUDED
00017 #define AGG_SPAN_INTERPOLATOR_LINEAR_INCLUDED
00018
00019 #include "agg_basics.h"
00020 #include "agg_dda_line.h"
00021 #include "agg_trans_affine.h"
00022
00023 namespace agg
00024 {
00025
00026
00027 template<class Transformer = trans_affine, unsigned SubpixelShift = 8>
00028 class span_interpolator_linear
00029 {
00030 public:
00031 typedef Transformer trans_type;
00032
00033 enum
00034 {
00035 subpixel_shift = SubpixelShift,
00036 subpixel_size = 1 << subpixel_shift
00037 };
00038
00039
00040 span_interpolator_linear() {}
00041 span_interpolator_linear(const trans_type& trans) : m_trans(&trans) {}
00042 span_interpolator_linear(const trans_type& trans,
00043 double x, double y, unsigned len) :
00044 m_trans(&trans)
00045 {
00046 begin(x, y, len);
00047 }
00048
00049
00050 const trans_type& transformer() const { return *m_trans; }
00051 void transformer(const trans_type& trans) { m_trans = &trans; }
00052
00053
00054 void begin(double x, double y, unsigned len)
00055 {
00056 double tx;
00057 double ty;
00058
00059 tx = x;
00060 ty = y;
00061 m_trans->transform(&tx, &ty);
00062 int x1 = int(tx * subpixel_size);
00063 int y1 = int(ty * subpixel_size);
00064
00065 tx = x + len;
00066 ty = y;
00067 m_trans->transform(&tx, &ty);
00068 int x2 = int(tx * subpixel_size);
00069 int y2 = int(ty * subpixel_size);
00070
00071 m_li_x = dda2_line_interpolator(x1, x2, len);
00072 m_li_y = dda2_line_interpolator(y1, y2, len);
00073 }
00074
00075
00076 void operator++()
00077 {
00078 ++m_li_x;
00079 ++m_li_y;
00080 }
00081
00082
00083 void coordinates(int* x, int* y) const
00084 {
00085 *x = m_li_x.y();
00086 *y = m_li_y.y();
00087 }
00088
00089 private:
00090 const trans_type* m_trans;
00091 dda2_line_interpolator m_li_x;
00092 dda2_line_interpolator m_li_y;
00093 };
00094
00095 }
00096
00097
00098
00099 #endif
00100
00101