public static void Bisectrix(LineParameters l1,
                                     LineParameters l2,
                                     out int x, out int y)
        {
            double k  = (double)(l2.len) / (double)(l1.len);
            double tx = l2.x2 - (l2.x1 - l1.x1) * k;
            double ty = l2.y2 - (l2.y1 - l1.y1) * k;

            //All bisectrices must be on the right of the line
            //If the next point is on the left (l1 => l2.2)
            //then the bisectix should be rotated by 180 degrees.
            if ((double)(l2.x2 - l2.x1) * (double)(l2.y1 - l1.y1) <
                (double)(l2.y2 - l2.y1) * (double)(l2.x1 - l1.x1) + 100.0)
            {
                tx -= (tx - l2.x1) * 2.0;
                ty -= (ty - l2.y1) * 2.0;
            }

            // Check if the bisectrix is too short
            double dx = tx - l2.x1;
            double dy = ty - l2.y1;

            if ((int)Math.Sqrt(dx * dx + dy * dy) < SUBPIXEL_SCALE)
            {
                x = (l2.x1 + l2.x1 + (l2.y1 - l1.y1) + (l2.y2 - l2.y1)) >> 1;
                y = (l2.y1 + l2.y1 - (l2.x1 - l1.x1) - (l2.x2 - l2.x1)) >> 1;
                return;
            }

            x = AggMath.iround(tx);
            y = AggMath.iround(ty);
        }
        //---------------------------------------------------------------------

        public DistanceInterpolator3(int x1, int y1, int x2, int y2,
                                     int sx, int sy, int ex, int ey,
                                     int x, int y)
        {
            unchecked
            {
                _dx       = (x2 - x1);
                _dy       = (y2 - y1);
                _dx_start = (LineAA.Mr(sx) - LineAA.Mr(x1));
                _dy_start = (LineAA.Mr(sy) - LineAA.Mr(y1));
                _dx_end   = (LineAA.Mr(ex) - LineAA.Mr(x2));
                _dy_end   = (LineAA.Mr(ey) - LineAA.Mr(y2));
                _dist     = (AggMath.iround((double)(x + LineAA.SUBPIXEL_SCALE / 2 - x2) * (double)(_dy) -
                                            (double)(y + LineAA.SUBPIXEL_SCALE / 2 - y2) * (double)(_dx)));
                _dist_start = ((LineAA.Mr(x + LineAA.SUBPIXEL_SCALE / 2) - LineAA.Mr(sx)) * _dy_start -
                               (LineAA.Mr(y + LineAA.SUBPIXEL_SCALE / 2) - LineAA.Mr(sy)) * _dx_start);
                _dist_end = ((LineAA.Mr(x + LineAA.SUBPIXEL_SCALE / 2) - LineAA.Mr(ex)) * _dy_end -
                             (LineAA.Mr(y + LineAA.SUBPIXEL_SCALE / 2) - LineAA.Mr(ey)) * _dx_end);
                _dx       <<= LineAA.SUBPIXEL_SHIFT;
                _dy       <<= LineAA.SUBPIXEL_SHIFT;
                _dx_start <<= LineAA.MR_SUBPIXEL_SHIFT;
                _dy_start <<= LineAA.MR_SUBPIXEL_SHIFT;
                _dx_end   <<= LineAA.MR_SUBPIXEL_SHIFT;
                _dy_end   <<= LineAA.MR_SUBPIXEL_SHIFT;
            }
        }
Esempio n. 3
0
        //

        public void SetFilterOffset(double dx, double dy)
        {
            _dx_dbl = dx;
            _dy_dbl = dy;
            _dx_int = AggMath.iround(dx * img_subpix_const.SCALE);
            _dy_int = AggMath.iround(dy * img_subpix_const.SCALE);
        }
 //---------------------------------------------------------------------
 public void Setup(double r, double fx, double fy)
 {
     m_r  = AggMath.iround(r * GradientSpanGen.GR_SUBPIX_SCALE);
     m_fx = AggMath.iround(fx * GradientSpanGen.GR_SUBPIX_SCALE);
     m_fy = AggMath.iround(fy * GradientSpanGen.GR_SUBPIX_SCALE);
     UpdateValues();
 }
Esempio n. 5
0
        //----------------------------------------------------------------
        public void Begin(double x, double y, int len)
        {
            // Calculate transformed coordinates at x1,y1
            double xt = x;
            double yt = y;

            m_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;
            m_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;
            m_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;
            m_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;
            m_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;
            m_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
            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);
        }
 public DistanceInterpolator1(int x1, int y1, int x2, int y2, int x, int y)
 {
     _dx   = (x2 - x1);
     _dy   = (y2 - y1);
     _dist = (AggMath.iround((double)(x + LineAA.SUBPIXEL_SCALE / 2 - x2) * (double)(_dy) -
                             (double)(y + LineAA.SUBPIXEL_SCALE / 2 - y2) * (double)(_dx)));
     _dx <<= LineAA.SUBPIXEL_SHIFT;
     _dy <<= LineAA.SUBPIXEL_SHIFT;
 }
        //---------------------------------------------------------------------
        public int Calculate(int x, int y, int d)
        {
            double dx = x - m_fx;
            double dy = y - m_fy;
            double d2 = dx * m_fy - dy * m_fx;
            double d3 = m_r2 * (dx * dx + dy * dy) - d2 * d2;

            return(AggMath.iround((dx * m_fx + dy * m_fy + System.Math.Sqrt(System.Math.Abs(d3))) * m_mul));
        }
        //--------------------------------------------------------------------
        // This function normalizes integer values and corrects the rounding
        // errors. It doesn't do anything with the source floating point values
        // (m_weight_array_dbl), it corrects only integers according to the rule
        // of 1.0 which means that any sum of pixel weights must be equal to 1.0.
        // So, the filter function must produce a graph of the proper shape.
        //--------------------------------------------------------------------
        void Normalize()
        {
            int i;
            int flip = 1;

            for (i = 0; i < (int)ImgSubPixConst.SCALE; i++)
            {
                for (; ;)
                {
                    int sum = 0;
                    int j;
                    for (j = 0; j < _diameter; j++)
                    {
                        sum += _weight_array[j * (int)ImgSubPixConst.SCALE + i];
                    }

                    if (sum == (int)ImgFilterConst.SCALE)
                    {
                        break;
                    }
                    double k = (double)((int)ImgFilterConst.SCALE) / (double)(sum);
                    sum = 0;
                    for (j = 0; j < _diameter; j++)
                    {
                        sum += _weight_array[j * (int)ImgSubPixConst.SCALE + i] =
                            (int)AggMath.iround(_weight_array[j * (int)ImgSubPixConst.SCALE + i] * k);
                    }

                    sum -= (int)ImgFilterConst.SCALE;
                    int inc = (sum > 0) ? -1 : 1;
                    for (j = 0; j < _diameter && sum != 0; j++)
                    {
                        flip ^= 1;
                        int idx = flip != 0 ? _diameter / 2 + j / 2 : _diameter / 2 - j / 2;
                        int v   = _weight_array[idx * (int)ImgSubPixConst.SCALE + i];
                        if (v < (int)ImgFilterConst.SCALE)
                        {
                            _weight_array[idx * (int)ImgSubPixConst.SCALE + i] += (int)inc;
                            sum += inc;
                        }
                    }
                }
            }

            int pivot = _diameter << (ImgSubPixConst.SHIFT - 1);

            for (i = 0; i < pivot; i++)
            {
                _weight_array[pivot + i] = _weight_array[pivot - i];
            }
            int end = (Diameter << ImgSubPixConst.SHIFT) - 1;

            _weight_array[0] = _weight_array[end];
        }
        /// <summary>
        /// fix_degeneration_bisectrix_start
        /// </summary>
        /// <param name="lp"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        public static void FixDegenBisectrixStart(LineParameters lp,
                                                  ref int x, ref int y)
        {
            int d = AggMath.iround(((double)(x - lp.x2) * (double)(lp.y2 - lp.y1) -
                                    (double)(y - lp.y2) * (double)(lp.x2 - lp.x1)) / lp.len);

            if (d < SUBPIXEL_SCALE / 2)
            {
                x = lp.x1 + (lp.y2 - lp.y1);
                y = lp.y1 - (lp.x2 - lp.x1);
            }
        }
        //---------------------------------------------------------------------

        public DistanceInterpolator2(int x1, int y1, int x2, int y2,
                                     int sx, int sy, int x, int y)
        {
            m_dx       = (x2 - x1);
            m_dy       = (y2 - y1);
            m_dx_start = (LineAA.Mr(sx) - LineAA.Mr(x1));
            m_dy_start = (LineAA.Mr(sy) - LineAA.Mr(y1));
            m_dist     = (AggMath.iround((double)(x + LineAA.SUBPIXEL_SCALE / 2 - x2) * (double)(m_dy) -
                                         (double)(y + LineAA.SUBPIXEL_SCALE / 2 - y2) * (double)(m_dx)));
            m_dist_start = ((LineAA.Mr(x + LineAA.SUBPIXEL_SCALE / 2) - LineAA.Mr(sx)) * m_dy_start -
                            (LineAA.Mr(y + LineAA.SUBPIXEL_SCALE / 2) - LineAA.Mr(sy)) * m_dx_start);
            m_dx       <<= LineAA.SUBPIXEL_SHIFT;
            m_dy       <<= LineAA.SUBPIXEL_SHIFT;
            m_dx_start <<= LineAA.MR_SUBPIXEL_SHIFT;
            m_dy_start <<= LineAA.MR_SUBPIXEL_SHIFT;
        }
 public DistanceInterpolator2(int x1, int y1, int x2, int y2,
                              int ex, int ey, int x, int y, int none)
 {
     _dx       = (x2 - x1);
     _dy       = (y2 - y1);
     _dx_start = (LineAA.Mr(ex) - LineAA.Mr(x2));
     _dy_start = (LineAA.Mr(ey) - LineAA.Mr(y2));
     _dist     = (AggMath.iround((double)(x + LineAA.SUBPIXEL_SCALE / 2 - x2) * (double)(_dy) -
                                 (double)(y + LineAA.SUBPIXEL_SCALE / 2 - y2) * (double)(_dx)));
     _dist_start = ((LineAA.Mr(x + LineAA.SUBPIXEL_SCALE / 2) - LineAA.Mr(ex)) * _dy_start -
                    (LineAA.Mr(y + LineAA.SUBPIXEL_SCALE / 2) - LineAA.Mr(ey)) * _dx_start);
     _dx       <<= LineAA.SUBPIXEL_SHIFT;
     _dy       <<= LineAA.SUBPIXEL_SHIFT;
     _dx_start <<= LineAA.MR_SUBPIXEL_SHIFT;
     _dy_start <<= LineAA.MR_SUBPIXEL_SHIFT;
 }
Esempio n. 12
0
            public void Calculate(double y)
            {
                double k = (y - m_y1) * m_1dy;

                if (k < 0.0)
                {
                    k = 0.0;
                }
                if (k > 1.0)
                {
                    k = 1.0;
                }
                m_r = m_r1 + AggMath.iround(m_dr * k);
                m_g = m_g1 + AggMath.iround(m_dg * k);
                m_b = m_b1 + AggMath.iround(m_db * k);
                m_a = m_a1 + AggMath.iround(m_da * k);
                m_x = AggMath.iround((m_x1 + m_dx * k) * (double)SUBPIXEL_SCALE);
            }
Esempio n. 13
0
            public void Calculate(double y)
            {
                double k = (y - _y1) * _1dy;

                if (k < 0.0)
                {
                    k = 0.0;
                }
                if (k > 1.0)
                {
                    k = 1.0;
                }
                _r = _r1 + AggMath.iround(_dr * k);
                _g = _g1 + AggMath.iround(_dg * k);
                _b = _b1 + AggMath.iround(_db * k);
                _a = _a1 + AggMath.iround(_da * k);
                _x = AggMath.iround((_x1 + _dx * k) * (double)SUBPIXEL_SCALE);
            }
Esempio n. 14
0
        public void Reset(ISpanInterpolator inter,
                          IGradientValueCalculator gvc,
                          IGradientColorsProvider m_colorsProvider,
                          double distance)
        {
            _grad0X = _grad0Y = _xoffset = _yoffset = 0;//reset

            _interpolator      = inter;
            _grValueCalculator = gvc;
            _colorsProvider    = m_colorsProvider;
            _dist = AggMath.iround(distance * GR_SUBPIX_SCALE);

            if (_dist < 1)
            {
                _dist = 1;
            }
            _stepRatio = (float)m_colorsProvider.GradientSteps / (float)_dist;
            _xoffset   = _yoffset = 0;//reset
        }
Esempio n. 15
0
        //----------------------------------------------------------------
        public void Begin(double x, double y, int len)
        {
            double tx = x;
            double ty = y;

            _trans.Transform(ref tx, ref ty);
            int x1 = AggMath.iround(tx * SUB_PIXEL_SCALE);
            int y1 = AggMath.iround(ty * SUB_PIXEL_SCALE);

            //
            tx = x + len; //***
            ty = y;       //**
            _trans.Transform(ref tx, ref ty);
            int x2 = AggMath.iround(tx * SUB_PIXEL_SCALE);
            int y2 = AggMath.iround(ty * SUB_PIXEL_SCALE);

            //
            _li_x = new LineInterpolatorDDA2(x1, x2, len);
            _li_y = new LineInterpolatorDDA2(y1, y2, len);
        }
Esempio n. 16
0
        //----------------------------------------------------------------
        public void Begin(double x, double y, int len)
        {
            double tx;
            double ty;

            tx = x;
            ty = y;
            m_trans.Transform(ref tx, ref ty);
            int x1 = AggMath.iround(tx * (double)SUB_PIXEL_SCALE);
            int y1 = AggMath.iround(ty * (double)SUB_PIXEL_SCALE);

            tx = x + len;
            ty = y;
            m_trans.Transform(ref tx, ref ty);
            int x2 = AggMath.iround(tx * (double)SUB_PIXEL_SCALE);
            int y2 = AggMath.iround(ty * (double)SUB_PIXEL_SCALE);

            m_li_x = new LineInterpolatorDDA2(x1, x2, (int)len);
            m_li_y = new LineInterpolatorDDA2(y1, y2, (int)len);
        }
Esempio n. 17
0
        //----------------------------------------------------------------
        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);
        }
Esempio n. 18
0
        //

        public void Rebuild(Imaging.IImageFilterFunc filterFunc, bool normalization = true)
        {
            double r = filterFunc.GetRadius();

            //---------------
            _radius   = r;
            _diameter = AggMath.uceil(r) * 2;
            _start    = -((_diameter / 2) - 1);
            int size = _diameter << ImgSubPixConst.SHIFT;

            if (size > _weight_array.Length)
            {
                _weight_array = new int[size];
            }
            else if (size < _weight_array.Length)
            {
                _weight_array = new int[size];
            }
            //---------------

            int i;
            int pivot = Diameter << (ImgSubPixConst.SHIFT - 1);

            for (i = 0; i < pivot; i++)
            {
                double x = (double)i / (double)ImgSubPixConst.SCALE;
                double y = filterFunc.CalculateWeight(x);
                _weight_array[pivot + i]     =
                    _weight_array[pivot - i] = AggMath.iround(y * ImgFilterConst.SCALE);
            }
            int end = (Diameter << ImgSubPixConst.SHIFT) - 1;

            _weight_array[0] = _weight_array[end];
            if (normalization)
            {
                Normalize();
            }
        }
Esempio n. 19
0
        void Calculate(Imaging.IImageFilter filter, bool normalization)
        {
            double r = filter.GetRadius();

            ReallocLut(r);
            int i;
            int pivot = Diameter << (ImgSubPixConst.SHIFT - 1);

            for (i = 0; i < pivot; i++)
            {
                double x = (double)i / (double)ImgSubPixConst.SCALE;
                double y = filter.CalculateWeight(x);
                _weight_array[pivot + i]     =
                    _weight_array[pivot - i] = AggMath.iround(y * ImgFilterConst.SCALE);
            }
            int end = (Diameter << ImgSubPixConst.SHIFT) - 1;

            _weight_array[0] = _weight_array[end];
            if (normalization)
            {
                Normalize();
            }
        }
 public static int Convert(double x)
 {
     return(AggMath.iround(
                x * LineAA.SUBPIXEL_SCALE,
                LineAA.SUBPIXEL_COORD));
 }
 //---------------------------------
 //from vector clipper
 static int upscale(double v) => AggMath.iround(v * poly_subpix.SCALE);
Esempio n. 22
0
 //----------------------------------------------------------------
 public void ReSync(double xe, double ye, int len)
 {
     m_trans.Transform(ref xe, ref ye);
     m_li_x = new LineInterpolatorDDA2(m_li_x.Y, AggMath.iround(xe * (double)SUB_PIXEL_SCALE), (int)len);
     m_li_y = new LineInterpolatorDDA2(m_li_y.Y, AggMath.iround(ye * (double)SUB_PIXEL_SCALE), (int)len);
 }
Esempio n. 23
0
 //---------------------------------
 //from vector clipper
 static int upscale(double v)
 {
     return(AggMath.iround(v * poly_subpix.SCALE));
 }