예제 #1
0
        //----------------------------------------------------------------
        public void Begin(double x, double y, int len)
        {
            // Calculate transformed coordinates at x1,y1
            double xt = x;
            double yt = y;

            _trans_dir.Transform(ref xt, ref yt);
            int    x1 = AggMath.iround(xt * SUBPIXEL_SCALE);
            int    y1 = AggMath.iround(yt * SUBPIXEL_SCALE);
            double dx;
            double dy;
            double delta = 1 / (double)SUBPIXEL_SCALE;

            // Calculate scale by X at x1,y1
            dx = xt + delta;
            dy = yt;
            _trans_inv.Transform(ref dx, ref dy);
            dx -= x;
            dy -= y;
            int sx1 = (int)AggMath.uround(SUBPIXEL_SCALE / Math.Sqrt(dx * dx + dy * dy)) >> SUBPIXEL_SHIFT;

            // Calculate scale by Y at x1,y1
            dx = xt;
            dy = yt + delta;
            _trans_inv.Transform(ref dx, ref dy);
            dx -= x;
            dy -= y;
            int sy1 = (int)AggMath.uround(SUBPIXEL_SCALE / Math.Sqrt(dx * dx + dy * dy)) >> SUBPIXEL_SHIFT;

            // Calculate transformed coordinates at x2,y2
            x += len;
            xt = x;
            yt = y;
            _trans_dir.Transform(ref xt, ref yt);
            int x2 = AggMath.iround(xt * SUBPIXEL_SCALE);
            int y2 = AggMath.iround(yt * SUBPIXEL_SCALE);

            // Calculate scale by X at x2,y2
            dx = xt + delta;
            dy = yt;
            _trans_inv.Transform(ref dx, ref dy);
            dx -= x;
            dy -= y;
            int sx2 = (int)AggMath.uround(SUBPIXEL_SCALE / Math.Sqrt(dx * dx + dy * dy)) >> SUBPIXEL_SHIFT;

            // Calculate scale by Y at x2,y2
            dx = xt;
            dy = yt + delta;
            _trans_inv.Transform(ref dx, ref dy);
            dx -= x;
            dy -= y;
            int sy2 = (int)AggMath.uround(SUBPIXEL_SCALE / Math.Sqrt(dx * dx + dy * dy)) >> SUBPIXEL_SHIFT;

            // Initialize the interpolators
            _coord_x = new LineInterpolatorDDA2(x1, x2, len);
            _coord_y = new LineInterpolatorDDA2(y1, y2, len);
            _scale_x = new LineInterpolatorDDA2(sx1, sx2, len);
            _scale_y = new LineInterpolatorDDA2(sy1, sy2, len);
        }
예제 #2
0
        //--------------------------------------------------------------------
        public LineInterpolatorBresenham(int x1, int y1, int x2, int y2)
        {
            m_x1_lr = (line_lr(x1));
            m_y1_lr = (line_lr(y1));
            m_x2_lr = (line_lr(x2));
            m_y2_lr = (line_lr(y2));
            m_ver   = (Math.Abs(m_x2_lr - m_x1_lr) < Math.Abs(m_y2_lr - m_y1_lr));
            if (m_ver)
            {
                m_len = (int)Math.Abs(m_y2_lr - m_y1_lr);
            }
            else
            {
                m_len = (int)Math.Abs(m_x2_lr - m_x1_lr);
            }

            m_inc          = (m_ver ? ((y2 > y1) ? 1 : -1) : ((x2 > x1) ? 1 : -1));
            m_interpolator = new LineInterpolatorDDA2(m_ver ? x1 : y1,
                                                      m_ver ? x2 : y2,
                                                      (int)m_len);
        }
예제 #3
0
        //--------------------------------------------------------------------
        public LineInterpolatorBresenham(int x1, int y1, int x2, int y2)
        {
            _x1_lr = (line_lr(x1));
            _y1_lr = (line_lr(y1));
            _x2_lr = (line_lr(x2));
            _y2_lr = (line_lr(y2));
            _ver   = (Math.Abs(_x2_lr - _x1_lr) < Math.Abs(_y2_lr - _y1_lr));
            if (_ver)
            {
                _len = (int)Math.Abs(_y2_lr - _y1_lr);
            }
            else
            {
                _len = (int)Math.Abs(_x2_lr - _x1_lr);
            }

            _inc          = (_ver ? ((y2 > y1) ? 1 : -1) : ((x2 > x1) ? 1 : -1));
            _interpolator = new LineInterpolatorDDA2(_ver ? x1 : y1,
                                                     _ver ? x2 : y2,
                                                     _len);
        }
        //----------------------------------------------------------------
        public void ReSync(double xe, double ye, int len)
        {
            // Assume x1,y1 are equal to the ones at the previous end point
            int x1  = m_coord_x.Y;
            int y1  = m_coord_y.Y;
            int sx1 = m_scale_x.Y;
            int sy1 = m_scale_y.Y;
            // Calculate transformed coordinates at x2,y2
            double xt = xe;
            double yt = ye;

            m_trans_dir.Transform(ref xt, ref yt);
            int    x2    = AggMath.iround(xt * SUBPIXEL_SCALE);
            int    y2    = AggMath.iround(yt * SUBPIXEL_SCALE);
            double delta = 1 / (double)SUBPIXEL_SCALE;
            double dx;
            double dy;

            // Calculate scale by X at x2,y2
            dx = xt + delta;
            dy = yt;
            m_trans_inv.Transform(ref dx, ref dy);
            dx -= xe;
            dy -= ye;
            int sx2 = (int)AggMath.uround(SUBPIXEL_SCALE / Math.Sqrt(dx * dx + dy * dy)) >> SUBPIXEL_SHIFT;

            // Calculate scale by Y at x2,y2
            dx = xt;
            dy = yt + delta;
            m_trans_inv.Transform(ref dx, ref dy);
            dx -= xe;
            dy -= ye;
            int sy2 = (int)AggMath.uround(SUBPIXEL_SCALE / Math.Sqrt(dx * dx + dy * dy)) >> SUBPIXEL_SHIFT;

            // Initialize the interpolators
            m_coord_x = new LineInterpolatorDDA2(x1, x2, (int)len);
            m_coord_y = new LineInterpolatorDDA2(y1, y2, (int)len);
            m_scale_x = new LineInterpolatorDDA2(sx1, sx2, (int)len);
            m_scale_y = new LineInterpolatorDDA2(sy1, sy2, (int)len);
        }