Exemplo n.º 1
0
 public static Affine NewRotationDeg(double degree, double rotationCenterX, double rotationCenterY)
 {
     return(Affine.New(AffinePlan.Translate(-rotationCenterX, -rotationCenterY),
                       AffinePlan.RotateDeg(degree),
                       AffinePlan.Translate(rotationCenterX, rotationCenterY)
                       ));
 }
Exemplo n.º 2
0
 public static Affine NewRotation(double angRad, double rotationCenterX, double rotationCenterY)
 {
     return(Affine.New(AffinePlan.Translate(-rotationCenterX, -rotationCenterY),
                       AffinePlan.Rotate(angRad),
                       AffinePlan.Translate(rotationCenterX, rotationCenterY)
                       ));
 }
Exemplo n.º 3
0
        private Affine(int pcount, ref AffinePlan p0, ref AffinePlan p1, ref AffinePlan p2, ref AffinePlan p3, ref AffinePlan p4, params AffinePlan[] creationPlans)
        {
            //-----------------------
            //start with identity matrix
            _elems      = AffineMat.Iden;//copy
            _isIdenHint = true;
            //-----------------------
            switch (pcount)
            {
            case 0:
                return;

            case 1:
                BuildAff(ref p0);
                break;

            case 2:
                BuildAff(ref p0);
                BuildAff(ref p1);
                break;

            case 3:
                BuildAff(ref p0);
                BuildAff(ref p1);
                BuildAff(ref p2);
                break;

            case 4:
                BuildAff(ref p0);
                BuildAff(ref p1);
                BuildAff(ref p2);
                BuildAff(ref p3);
                break;

            case 5:
                BuildAff(ref p0);
                BuildAff(ref p1);
                BuildAff(ref p2);
                BuildAff(ref p3);
                BuildAff(ref p4);
                break;

            default:
                BuildAff(ref p0);
                BuildAff(ref p1);
                BuildAff(ref p2);
                BuildAff(ref p3);
                BuildAff(ref p4);
                if (creationPlans != null)
                {
                    for (int i = 0; i < creationPlans.Length; ++i)
                    {
                        BuildAff(ref creationPlans[i]);
                    }
                }
                break;
            }
        }
Exemplo n.º 4
0
        public void BuildFromAffinePlans(AffinePlan[] creationPlans)
        {
            //-----------------------
            //start with identity matrix
            this = AffineMat.Iden;//copy from iden
            bool isIdenHint = true;

            if (creationPlans == null)
            {
                return;
            }
            //-----------------------
            int j = creationPlans.Length;

            for (int i = 0; i < j; ++i)
            {
                AffinePlan plan = creationPlans[i];
                switch (plan.cmd)
                {
                case AffineMatrixCommand.None:
                    break;

                case AffineMatrixCommand.Rotate:

                    isIdenHint = false;
                    this.Rotate(plan.x);

                    break;

                case AffineMatrixCommand.Scale:

                    isIdenHint = false;
                    this.Scale(plan.x, plan.y);

                    break;

                case AffineMatrixCommand.Translate:

                    isIdenHint = false;
                    this.Translate(plan.x, plan.y);

                    break;

                case AffineMatrixCommand.Skew:
                    isIdenHint = false;
                    this.Skew(plan.x, plan.y);
                    break;

                case AffineMatrixCommand.Invert:
                    isIdenHint = false;
                    this.Invert();
                    break;

                default:
                    throw new NotSupportedException();
                }
            }
        }
Exemplo n.º 5
0
        private Affine(Affine copyFrom, AffinePlan creationPlan)
        {
            _elems = copyFrom._elems;
            //-----------------------
            switch (creationPlan.cmd)
            {
            default:
            {
                throw new NotSupportedException();
            }

            case AffineMatrixCommand.None:
                _isIdenHint = copyFrom._isIdenHint;
                break;

            case AffineMatrixCommand.Rotate:
                _isIdenHint = false;
                _elems.Rotate(creationPlan.x);

                break;

            case AffineMatrixCommand.Scale:
                _isIdenHint = false;
                _elems.Scale(creationPlan.x, creationPlan.y);

                break;

            case AffineMatrixCommand.Skew:
                _isIdenHint = false;
                _elems.Skew(creationPlan.x, creationPlan.y);

                break;

            case AffineMatrixCommand.Translate:
                _isIdenHint = false;
                _elems.Translate(creationPlan.x, creationPlan.y);

                break;

            case AffineMatrixCommand.Invert:
                _isIdenHint = false;
                _elems.Invert();
                break;
            }
        }
Exemplo n.º 6
0
        void BuildAff(ref AffinePlan plan)
        {
            switch (plan.cmd)
            {
            case AffineMatrixCommand.None:
                break;

            case AffineMatrixCommand.Rotate:

                _isIdenHint = false;
                _elems.Rotate(plan.x);
                break;

            case AffineMatrixCommand.Scale:
                _isIdenHint = false;
                _elems.Scale(plan.x, plan.y);
                break;

            case AffineMatrixCommand.Translate:
                _isIdenHint = false;
                _elems.Translate(plan.x, plan.y);
                break;

            case AffineMatrixCommand.Skew:
                _isIdenHint = false;
                _elems.Skew(plan.x, plan.y);
                break;

            case AffineMatrixCommand.Invert:
                _isIdenHint = false;
                _elems.Invert();
                break;

            default:
                throw new NotSupportedException();
            }
        }
Exemplo n.º 7
0
        //--------------------------------------------------------------------
        public void init(double x0, double y0,
                         double rx, double ry,
                         double angle,
                         bool large_arc_flag,
                         bool sweep_flag,
                         double x2, double y2)
        {
            m_radii_ok = true;

            if (rx < 0.0)
            {
                rx = -rx;
            }
            if (ry < 0.0)
            {
                ry = -rx;
            }

            // Calculate the middle point between
            // the current and the final points
            //------------------------
            double dx2 = (x0 - x2) / 2.0;
            double dy2 = (y0 - y2) / 2.0;

            double cos_a = Math.Cos(angle);
            double sin_a = Math.Sin(angle);

            // Calculate (x1, y1)
            //------------------------
            double x1 = cos_a * dx2 + sin_a * dy2;
            double y1 = -sin_a * dx2 + cos_a * dy2;

            // Ensure radii are large enough
            //------------------------
            double prx = rx * rx;
            double pry = ry * ry;
            double px1 = x1 * x1;
            double py1 = y1 * y1;

            // Check that radii are large enough
            //------------------------
            double radii_check = px1 / prx + py1 / pry;

            if (radii_check > 1.0)
            {
                rx  = Math.Sqrt(radii_check) * rx;
                ry  = Math.Sqrt(radii_check) * ry;
                prx = rx * rx;
                pry = ry * ry;
                if (radii_check > 10.0)
                {
                    m_radii_ok = false;
                }
            }

            // Calculate (cx1, cy1)
            //------------------------
            double sign = (large_arc_flag == sweep_flag) ? -1.0 : 1.0;
            double sq   = (prx * pry - prx * py1 - pry * px1) / (prx * py1 + pry * px1);
            double coef = sign * Math.Sqrt((sq < 0) ? 0 : sq);
            double cx1  = coef * ((rx * y1) / ry);
            double cy1  = coef * -((ry * x1) / rx);

            //
            // Calculate (cx, cy) from (cx1, cy1)
            //------------------------
            double sx2 = (x0 + x2) / 2.0;
            double sy2 = (y0 + y2) / 2.0;
            double cx  = sx2 + (cos_a * cx1 - sin_a * cy1);
            double cy  = sy2 + (sin_a * cx1 + cos_a * cy1);

            // Calculate the start_angle (angle1) and the sweep_angle (dangle)
            //------------------------
            double ux = (x1 - cx1) / rx;
            double uy = (y1 - cy1) / ry;
            double vx = (-x1 - cx1) / rx;
            double vy = (-y1 - cy1) / ry;
            double p, n;

            // Calculate the angle start
            //------------------------
            n    = Math.Sqrt(ux * ux + uy * uy);
            p    = ux; // (1 * ux) + (0 * uy)
            sign = (uy < 0) ? -1.0 : 1.0;
            double v = p / n;

            if (v < -1.0)
            {
                v = -1.0;
            }
            if (v > 1.0)
            {
                v = 1.0;
            }
            double start_angle = sign * Math.Acos(v);

            // Calculate the sweep angle
            //------------------------
            n    = Math.Sqrt((ux * ux + uy * uy) * (vx * vx + vy * vy));
            p    = ux * vx + uy * vy;
            sign = (ux * vy - uy * vx < 0) ? -1.0 : 1.0;
            v    = p / n;
            if (v < -1.0)
            {
                v = -1.0;
            }
            if (v > 1.0)
            {
                v = 1.0;
            }
            double sweep_angle = sign * Math.Acos(v);

            if (!sweep_flag && sweep_angle > 0)
            {
                sweep_angle -= Math.PI * 2.0;
            }
            else
            if (sweep_flag && sweep_angle < 0)
            {
                sweep_angle += Math.PI * 2.0;
            }

            // We can now build and transform the resulting arc
            //------------------------
            m_arc.init(0.0, 0.0, rx, ry, start_angle, sweep_angle);

            Affine mtx = Affine.NewMatix(
                AffinePlan.Rotate(angle),
                AffinePlan.Translate(cx, cy)
                );

            for (int i = 2; i < m_arc.m_num_vertices - 2; i += 2)
            {
                mtx.Transform(ref m_arc.m_vertices[i], ref m_arc.m_vertices[i + 1]);
            }

            // We must make sure that the starting and ending points
            // exactly coincide with the initial (x0,y0) and (x2,y2)
            m_arc.m_vertices[0] = x0;
            m_arc.m_vertices[1] = y0;
            if (m_arc.m_num_vertices > 2)
            {
                m_arc.m_vertices[m_arc.m_num_vertices - 2] = x2;
                m_arc.m_vertices[m_arc.m_num_vertices - 1] = y2;
            }
        }
Exemplo n.º 8
0
 public static Affine NewMatix(AffinePlan creationPlan)
 {
     return(new Affine(IdentityMatrix, creationPlan));
 }
Exemplo n.º 9
0
 public static Affine NewMatix(AffinePlan p0, AffinePlan p1, AffinePlan p2, AffinePlan p3, AffinePlan p4)
 {
     return(new Affine(5, ref p0, ref p1, ref p2, ref p3, ref p4, null));
 }
Exemplo n.º 10
0
        public static Affine NewMatix(AffinePlan p0, AffinePlan p1, AffinePlan p2, AffinePlan p3)
        {
            AffinePlan p_empty = new AffinePlan();

            return(new Affine(4, ref p0, ref p1, ref p2, ref p3, ref p_empty, null));
        }
Exemplo n.º 11
0
 public Affine CreateTranslation(double x, double y)
 {
     return(new Affine(this, AffinePlan.Translate(x, y)));
 }
Exemplo n.º 12
0
 public static Affine New(AffinePlan plan)
 {
     return(new Affine(IdentityMatrix, plan));
 }
Exemplo n.º 13
0
        public static Affine New(AffinePlan p0, AffinePlan p1, AffinePlan p2)
        {
            AffinePlan p_empty = new AffinePlan();

            return(new Affine(3, ref p0, ref p1, ref p2, ref p_empty, ref p_empty, null));
        }