예제 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        internal bool ValueChange(float x, float y)
        {
            if (CurrentIndex.IsValid())
            {
                var m_path = Paths[CurrentIndex.BlockIndex];
                var item   = m_path[CurrentIndex.ItemIndex];
                item.ValueChange(CurrentIndex.PartIndex, x, y);
                if (item.IsC() && CurrentIndex.PartIndex == 2)
                {
                    int nextindex = CurrentIndex.ItemIndex + 1;
                    if (nextindex >= m_path.Count)
                    {
                        nextindex = 0;
                    }
                    SvgPathItem next = m_path[nextindex];
                    if (next.IsZ())
                    {
                        next = m_path[0];
                        if (next.IsM())
                        {
                            next.ValueChange(0, x, y);
                            nextindex = 1;
                            next      = m_path[nextindex];
                        }
                    }
                    if (next.IsC())
                    {
                        next.ValueChange(0, x, y);
                    }
                }

                return(true);
            }
            return(false);
        }
예제 #2
0
        internal static void SetPreviusPoint(List <SvgPathItem> path, int index, Vector2 p1)
        {
            SvgPathItem pre = null;
            Vector2?    pm  = null;

            index--;
            if (index < 0)
            {
                index = path.Count - 1;
            }
            pre = path[index];
            if (pre.IsM())
            {
                pm = pre.GetPoint();
                pre.SetPoint(p1);
            }
            if (pre.IsZ())
            {
                index--;
                pre = path[index];
            }
            if (pm == null)
            {
                pre.SetPoint(p1);
            }
            else
            {
                var p = pre.GetPoint();
                if (p == pm)
                {
                    pre.SetPoint(p1);
                }
            }
        }
예제 #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="path"></param>
        /// <param name="index">自分のindex</param>
        /// <param name="step"></param>
        /// <returns></returns>
        internal bool RoundCorner(List <SvgPathItem> path, int index, float step)
        {
            SvgPathItem b1 = path[index - 1]; // 自分はCなので最低Mは存在する。
            var         p1 = b1.GetPoint();
            var         p3 = GetPoint();
            SvgPathItem b2 = null;

            if (index >= 2)
            {
                b2 = path[index - 2];
            }
            else
            {
                var item = path[path.Count - 1];
                if (item.IsZ())
                {
                    b2 = path[path.Count - 2];
                    var p = b2.GetPoint();
                    if (p == p1)
                    {
                        if (b2.IsL())
                        {
                            b2 = null;
                        }
                    }
                }
            }
            if (b2 == null)
            {
                return(false);
            }
            var         p2 = b2.GetPoint();
            SvgPathItem n1 = null;

            if (index <= path.Count - 2)
            {
                n1 = path[index + 1];
                if (n1.IsZ())
                {
                    n1 = path[0];
                    var p = n1.GetPoint();
                    if (p == p3)
                    {
                        n1 = path[1];
                        if (!n1.IsL())
                        {
                            return(false);
                        }
                    }
                }
            }
            else
            {
                return(false);
            }
            // 交点求める公式より
            var   p4  = n1.GetPoint();
            float dev = (p2.Y - p1.Y) * (p4.X - p3.X) - (p2.X - p1.X) * (p4.Y - p3.Y);

            if (dev == 0)
            {
                return(false);
            }
            float d1 = p3.Y * p4.X - p3.X * p4.Y;
            float d2 = p1.Y * p2.X - p1.X * p2.Y;
            float x  = d1 * (p2.X - p1.X) - d2 * (p4.X - p3.X);

            x /= dev;
            float y = d1 * (p2.Y - p1.Y) - d2 * (p4.Y - p3.Y);

            y /= dev;



            if (RoundSub(new Vector2(x, y), p2, p4, ref p1, ref p3, step))
            {
                SvgPathData.SetPreviusPoint(path, index, p1);
                SvgPathData.SetSameNextPoint(path, index);
                return(true);
            }
            return(false);
        }