コード例 #1
0
ファイル: MathStroke.cs プロジェクト: GeroL/MOSA-Project
 public MathStroke()
 {
     m_width = 0.5;
     m_width_abs = 0.5;
     m_width_eps = 0.5 / 1024.0;
     m_width_sign = 1;
     m_miter_limit = 4.0;
     m_inner_miter_limit = 1.01;
     m_approx_scale = 1.0;
     m_line_cap = ELineCap.butt_cap;
     m_line_join = ELineJoin.miter_join;
     m_inner_join = EInnerJoin.inner_miter;
 }
コード例 #2
0
ファイル: MathStroke.cs プロジェクト: davidleon/MOSA-Project
 public MathStroke()
 {
     m_width             = 0.5;
     m_width_abs         = 0.5;
     m_width_eps         = 0.5 / 1024.0;
     m_width_sign        = 1;
     m_miter_limit       = 4.0;
     m_inner_miter_limit = 1.01;
     m_approx_scale      = 1.0;
     m_line_cap          = ELineCap.butt_cap;
     m_line_join         = ELineJoin.miter_join;
     m_inner_join        = EInnerJoin.inner_miter;
 }
コード例 #3
0
ファイル: MathStroke.cs プロジェクト: GeroL/MOSA-Project
        void CalculateMiter(IVertexDest vc,
						VertexDistance v0,
						VertexDistance v1,
						VertexDistance v2,
						double dx1, double dy1,
						double dx2, double dy2,
						ELineJoin lj,
						double mlimit,
						double dbevel)
        {
            double xi = v1.x;
            double yi = v1.y;
            double di = 1;
            double lim = m_width_abs * mlimit;
            bool miter_limit_exceeded = true; // Assume the worst
            bool intersection_failed = true; // Assume the worst

            if (PictorMath.CalculateIntersection(v0.x + dx1, v0.y - dy1,
                                 v1.x + dx1, v1.y - dy1,
                                 v1.x + dx2, v1.y - dy2,
                                 v2.x + dx2, v2.y - dy2,
                                 out xi, out yi))
            {
                // Calculation of the intersection succeeded
                //---------------------
                di = PictorMath.CalculateDistance(v1.x, v1.y, xi, yi);
                if (di <= lim)
                {
                    // Inside the miter limit
                    //---------------------
                    AddVertex(vc, xi, yi);
                    miter_limit_exceeded = false;
                }
                intersection_failed = false;
            }
            else
            {
                // Calculation of the intersection failed, most probably
                // the three points lie one straight Line.
                // First check if v0 and v2 lie on the opposite sides of vector:
                // (v1.x, v1.y) -> (v1.x+dx1, v1.y-dy1), that is, the perpendicular
                // to the Line determined by vertices v0 and v1.
                // This condition determines whether the next Line segments continues
                // the previous one or goes back.
                //----------------
                double x2 = v1.x + dx1;
                double y2 = v1.y - dy1;
                if ((PictorMath.CrossProduct(v0.x, v0.y, v1.x, v1.y, x2, y2) < 0.0) ==
                   (PictorMath.CrossProduct(v1.x, v1.y, v2.x, v2.y, x2, y2) < 0.0))
                {
                    // This case means that the next segment continues
                    // the previous one (straight Line)
                    //-----------------
                    AddVertex(vc, v1.x + dx1, v1.y - dy1);
                    miter_limit_exceeded = false;
                }
            }

            if (miter_limit_exceeded)
            {
                // Miter limit exceeded
                //------------------------
                switch (lj)
                {
                    case ELineJoin.miter_join_revert:
                        // For the compatibility with SVG, PDF, etc,
                        // we use a simple bevel join instead of
                        // "smart" bevel
                        //-------------------
                        AddVertex(vc, v1.x + dx1, v1.y - dy1);
                        AddVertex(vc, v1.x + dx2, v1.y - dy2);
                        break;

                    case ELineJoin.miter_join_round:
                        CalculateArc(vc, v1.x, v1.y, dx1, -dy1, dx2, -dy2);
                        break;

                    default:
                        // If no miter-revert, Calculate new dx1, dy1, dx2, dy2
                        //----------------
                        if (intersection_failed)
                        {
                            mlimit *= m_width_sign;
                            AddVertex(vc, v1.x + dx1 + dy1 * mlimit,
                                           v1.y - dy1 + dx1 * mlimit);
                            AddVertex(vc, v1.x + dx2 - dy2 * mlimit,
                                           v1.y - dy2 - dx2 * mlimit);
                        }
                        else
                        {
                            double x1 = v1.x + dx1;
                            double y1 = v1.y - dy1;
                            double x2 = v1.x + dx2;
                            double y2 = v1.y - dy2;
                            di = (lim - dbevel) / (di - dbevel);
                            AddVertex(vc, x1 + (xi - x1) * di,
                                           y1 + (yi - y1) * di);
                            AddVertex(vc, x2 + (xi - x2) * di,
                                           y2 + (yi - y2) * di);
                        }
                        break;
                }
            }
        }
コード例 #4
0
ファイル: MathStroke.cs プロジェクト: GeroL/MOSA-Project
 public void LineJoin(ELineJoin lj)
 {
     m_line_join = lj;
 }
コード例 #5
0
ファイル: MathStroke.cs プロジェクト: davidleon/MOSA-Project
 public void LineJoin(ELineJoin lj)
 {
     m_line_join = lj;
 }
コード例 #6
0
ファイル: MathStroke.cs プロジェクト: davidleon/MOSA-Project
        void CalculateMiter(IVertexDest vc,
                            VertexDistance v0,
                            VertexDistance v1,
                            VertexDistance v2,
                            double dx1, double dy1,
                            double dx2, double dy2,
                            ELineJoin lj,
                            double mlimit,
                            double dbevel)
        {
            double xi  = v1.x;
            double yi  = v1.y;
            double di  = 1;
            double lim = m_width_abs * mlimit;
            bool   miter_limit_exceeded = true;          // Assume the worst
            bool   intersection_failed  = true;          // Assume the worst

            if (PictorMath.CalculateIntersection(v0.x + dx1, v0.y - dy1,
                                                 v1.x + dx1, v1.y - dy1,
                                                 v1.x + dx2, v1.y - dy2,
                                                 v2.x + dx2, v2.y - dy2,
                                                 out xi, out yi))
            {
                // Calculation of the intersection succeeded
                //---------------------
                di = PictorMath.CalculateDistance(v1.x, v1.y, xi, yi);
                if (di <= lim)
                {
                    // Inside the miter limit
                    //---------------------
                    AddVertex(vc, xi, yi);
                    miter_limit_exceeded = false;
                }
                intersection_failed = false;
            }
            else
            {
                // Calculation of the intersection failed, most probably
                // the three points lie one straight Line.
                // First check if v0 and v2 lie on the opposite sides of vector:
                // (v1.x, v1.y) -> (v1.x+dx1, v1.y-dy1), that is, the perpendicular
                // to the Line determined by vertices v0 and v1.
                // This condition determines whether the next Line segments continues
                // the previous one or goes back.
                //----------------
                double x2 = v1.x + dx1;
                double y2 = v1.y - dy1;
                if ((PictorMath.CrossProduct(v0.x, v0.y, v1.x, v1.y, x2, y2) < 0.0) ==
                    (PictorMath.CrossProduct(v1.x, v1.y, v2.x, v2.y, x2, y2) < 0.0))
                {
                    // This case means that the next segment continues
                    // the previous one (straight Line)
                    //-----------------
                    AddVertex(vc, v1.x + dx1, v1.y - dy1);
                    miter_limit_exceeded = false;
                }
            }

            if (miter_limit_exceeded)
            {
                // Miter limit exceeded
                //------------------------
                switch (lj)
                {
                case ELineJoin.miter_join_revert:
                    // For the compatibility with SVG, PDF, etc,
                    // we use a simple bevel join instead of
                    // "smart" bevel
                    //-------------------
                    AddVertex(vc, v1.x + dx1, v1.y - dy1);
                    AddVertex(vc, v1.x + dx2, v1.y - dy2);
                    break;

                case ELineJoin.miter_join_round:
                    CalculateArc(vc, v1.x, v1.y, dx1, -dy1, dx2, -dy2);
                    break;

                default:
                    // If no miter-revert, Calculate new dx1, dy1, dx2, dy2
                    //----------------
                    if (intersection_failed)
                    {
                        mlimit *= m_width_sign;
                        AddVertex(vc, v1.x + dx1 + dy1 * mlimit,
                                  v1.y - dy1 + dx1 * mlimit);
                        AddVertex(vc, v1.x + dx2 - dy2 * mlimit,
                                  v1.y - dy2 - dx2 * mlimit);
                    }
                    else
                    {
                        double x1 = v1.x + dx1;
                        double y1 = v1.y - dy1;
                        double x2 = v1.x + dx2;
                        double y2 = v1.y - dy2;
                        di = (lim - dbevel) / (di - dbevel);
                        AddVertex(vc, x1 + (xi - x1) * di,
                                  y1 + (yi - y1) * di);
                        AddVertex(vc, x2 + (xi - x2) * di,
                                  y2 + (yi - y2) * di);
                    }
                    break;
                }
            }
        }