//private void BuildPatturnInfo()
        //{
        //    List<PointLink> backPl = new List<PointLink>(this.linkData);
        //    Dictionary<int, int> dic = new Dictionary<int, int>();

        //    this.infoData = new List<PatturnInfo>();

        //    int index = 0;

        //    for (int i = 0; i < backPl.Count; i++)
        //    {
        //        bool f = false;

        //        for (int j = 0; j < backPl.Count; j++)
        //        {
        //            bool flg = false;

        //            if (i == j)
        //            {
        //                continue;
        //            }

        //            PointLink p1 = backPl[i];

        //            while (p1 != null)
        //            {
        //                PointLink p2 = backPl[j];

        //                while (p2 != null)
        //                {
        //                    if (Math.Abs(p1.Point.X - p2.Point.X) <= 1 && Math.Abs(p1.Point.Y - p2.Point.Y) <= 1)
        //                    {

        //                        flg = true;
        //                        f = true;

        //                        break;
        //                    }

        //                    p2 = p2.Next;
        //                }

        //                if (flg)
        //                {
        //                    if (!dic.ContainsKey(i) && !dic.ContainsKey(j))
        //                    {
        //                        dic[i] = index;
        //                        dic[j] = dic[i];
        //                        index++;
        //                    }
        //                    else if (dic.ContainsKey(i) && dic.ContainsKey(j))
        //                    {
        //                        int from = 0;
        //                        int to = 0;

        //                        if (dic[i] < dic[j])
        //                        {
        //                            from = dic[j];
        //                            to = dic[i];
        //                            dic[j] = dic[i];

        //                        }
        //                        else
        //                        {
        //                            from = dic[i];
        //                            to = dic[j];
        //                            dic[i] = dic[j];
        //                        }

        //                        int[] keys = dic.Keys.ToArray();
        //                        foreach (int key in keys)
        //                        {
        //                            if (dic[key] == from)
        //                            {
        //                                dic[key] = to;
        //                            }
        //                        }
        //                    }
        //                    else if (!dic.ContainsKey(i))
        //                    {
        //                        dic[i] = dic[j];
        //                    }
        //                    else
        //                    {
        //                        dic[j] = dic[i];
        //                    }
        //                    break;
        //                }

        //                p1 = p1.Next;
        //            }

        //        }

        //        if (!f)
        //        {
        //            dic[i] = index;
        //            index++;
        //        }
        //    }

        //    this.infoData = new List<PatturnInfo>();

        //    if (dic.Count > 0)
        //    {
        //        index = 0;

        //        int[] keys = dic.Keys.ToArray();

        //        while (true)
        //        {

        //            List<PointLink> l = new List<PointLink>();

        //            for (int i = 0; i < keys.Length; i++)
        //            {
        //                if (dic[i] == index)
        //                {
        //                    l.Add(this.linkData[i]);
        //                }
        //            }

        //            if (l.Count == 0)
        //            {
        //                break;
        //            }

        //            PatturnInfo pi = new PatturnInfo(l);

        //            this.infoData.Add(pi);

        //            index++;
        //        }
        //    }
        //}

        private void SplitPointLink()
        {
            List <PointLink> lnk = new List <PointLink>(this.linkData);

            foreach (PointLink pl in lnk)
            {
                if (pl.Length < 3)
                {
                    continue;
                }

                int       d = pl.LineType;
                PointLink p = pl;

                while (p != null)
                {
                    if (p.LineType != d)
                    {
                        //分割
                        this.linkData.Add(p.Split()[1]);

                        d = p.LineType;
                    }

                    p = p.Next;
                }
            }
        }
Esempio n. 2
0
        public void Link(PointLink p)
        {
            this.end.next = p;
            p.prev        = this.end;
            p.start       = this.start;
            this.end      = p.end;

            int len = 0;

            PointLink pl = this.start;

            while (pl != null)
            {
                len++;
                pl = pl.next;
            }

            pl = this.start;

            while (pl != null)
            {
                pl.length = len;
                pl.end    = this.end;
                pl.start  = this.start;

                pl = pl.next;
            }
        }
Esempio n. 3
0
 public PointLink(int x, int y)
 {
     this.point  = new Point(x, y);
     this.start  = this;
     this.end    = this;
     this.length = 1;
 }
        private void InitPointLink()
        {
            this.linkData = new List <PointLink>();

            for (int y = 0; y < this.thinData.GetLength(1); y++)
            {
                for (int x = 0; x < this.thinData.GetLength(0); x++)
                {
                    if (this.thinData[x, y] == '■')
                    {
                        PointLink pl = new PointLink(x, y);
                        this.linkData.Add(pl);
                    }
                }
            }
        }
        private void SetDirection()
        {
            foreach (PointLink pl in this.linkData)
            {
                if (pl.Length == 2)
                {
                    Point p1 = pl.Start.Point;
                    Point p2 = pl.End.Point;

                    int type = DirectionUtil.GetDirection(p1, p2);

                    pl.Start.LineType = type;
                    pl.End.LineType   = type;
                }
                else if (pl.Length > 2)
                {
                    PointLink p = pl.Next;
                    while (p != null)
                    {
                        if (p.Next != null)
                        {
                            Point p1 = p.Prev.Point;
                            Point p2 = p.Next.Point;

                            int type = DirectionUtil.GetDirection(p1, p2);

                            p.LineType = type;
                            //p.Next.LineType = type;
                            //p.Next.Next.LineType = type;

                            p = p.Next;
                        }
                        else
                        {
                            p = null;
                        }
                    }

                    pl.Start.LineType = pl.Start.Next.LineType;
                    pl.End.LineType   = pl.End.Prev.LineType;
                }
            }
        }
Esempio n. 6
0
        public PointLink Reverse()
        {
            PointLink pr;

            pr = this.start;

            //Debug.WriteLine("前");

            while (pr != null)
            {
                //Debug.WriteLine(pr.ToString());
                pr = pr.next;
            }

            pr = this.end;

            while (pr != null)
            {
                PointLink p = pr.end;
                pr.end   = pr.start;
                pr.start = p;

                p       = pr.next;
                pr.next = pr.prev;
                pr.prev = p;

                pr = pr.next;
            }

            //Debug.WriteLine("後");
            pr = this.start;
            while (pr != null)
            {
                //Debug.WriteLine(pr.ToString());
                pr = pr.next;
            }

            return(this.start);
        }
        private void BuildPatturn()
        {
            this.patturn = new char[this.thinData.GetLength(0) - 2, this.thinData.GetLength(1) - 2];

            for (int y = 0; y < this.patturn.GetLength(1); y++)
            {
                for (int x = 0; x < this.patturn.GetLength(0); x++)
                {
                    this.patturn[x, y] = ' ';
                }
            }

            foreach (PointLink pl in this.linkData)
            {
                PointLink p = pl;

                while (p != null)
                {
                    this.patturn[p.Point.X - 1, p.Point.Y - 1] = p.LineType.ToString()[0];
                    p = p.Next;
                }
            }
        }
        public string showtables(char tmp)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("オリジナル ");
            sb.Append(tmp);
            sb.Append("\r\n");

            for (int y = 0; y < this.normalData.GetLength(1); y++)
            {
                for (int x = 0; x < this.normalData.GetLength(0); x++)
                {
                    sb.Append(this.normalData[x, y]);
                }

                sb.Append("\r\n");
            }

            sb.Append("\r\n");

            sb.Append("細線化\r\n");

            for (int y = 0; y < this.thinData.GetLength(1); y++)
            {
                for (int x = 0; x < this.thinData.GetLength(0); x++)
                {
                    sb.Append(this.thinData[x, y]);
                }

                sb.Append("\r\n");
            }

            sb.Append("\r\n");

            char[,] c = (char[, ]) this.thinData.Clone();

            foreach (PointLink pl in this.linkData)
            {
                PointLink p = pl;

                while (p != null)
                {
                    c[p.Point.X, p.Point.Y] = Strings.StrConv(p.LineType.ToString(), VbStrConv.Wide, 0)[0];
                    p = p.Next;
                }
            }

            sb.Append("方向\r\n");

            for (int y = 0; y < c.GetLength(1); y++)
            {
                for (int x = 0; x < c.GetLength(0); x++)
                {
                    sb.Append(c[x, y]);
                }

                sb.Append("\r\n");
            }

            sb.Append("\r\n");

            string[,] s = new string[c.GetLength(0), c.GetLength(1)];



            for (int i = 0; i < this.linkData.Count; i++)
            {
                PointLink p = this.linkData[i];

                while (p != null)
                {
                    if (i < 10)
                    {
                        s[p.Point.X, p.Point.Y] = Strings.StrConv(i.ToString(), VbStrConv.Wide, 0);
                    }
                    else
                    {
                        s[p.Point.X, p.Point.Y] = Convert.ToString(i);
                    }
                    p = p.Next;
                }
            }

            sb.Append("インデックス\r\n");

            for (int y = 0; y < c.GetLength(1); y++)
            {
                for (int x = 0; x < c.GetLength(0); x++)
                {
                    if (s[x, y] != null)
                    {
                        sb.Append(s[x, y]);
                    }
                    else
                    {
                        sb.Append("□");
                    }
                }

                sb.Append("\r\n");
            }

            sb.Append("\r\n");

            return(sb.ToString());
        }
        private void ConnectPointLink()
        {
            while (true)
            {
                bool flg = false;

                //縦のみ,横のみ,斜めまででチェック
                Point[] ps = new Point[] { new Point(0, 1), new Point(1, 0), new Point(1, 1) };

                foreach (Point p in ps)
                {
                    for (int i = 0; i < this.linkData.Count; i++)
                    {
                        for (int j = 0; j < this.linkData.Count; j++)
                        {
                            if (i == j)
                            {
                                continue;
                            }

                            PointLink p1 = this.linkData[i];
                            PointLink p2 = this.linkData[j];



                            if (Math.Abs(p1.End.Point.X - p2.Start.Point.X) <= p.X && Math.Abs(p1.End.Point.Y - p2.Start.Point.Y) <= p.Y)
                            {
                                //EndとStartの連結
                                flg = true;
                            }
                            else if (Math.Abs(p1.Start.Point.X - p2.Start.Point.X) <= p.X && Math.Abs(p1.Start.Point.Y - p2.Start.Point.Y) <= p.Y)
                            {
                                //StartとStartの連結
                                PointLink pl = p1.Reverse();
                                this.linkData.Remove(p1);
                                p1 = pl;
                                this.linkData.Add(p1);
                                flg = true;
                            }
                            else if (Math.Abs(p1.End.Point.X - p2.End.Point.X) <= p.X && Math.Abs(p1.End.Point.Y - p2.End.Point.Y) <= p.Y)
                            {
                                //EndとEndの連結
                                PointLink pl = p2.Reverse();
                                this.linkData.Remove(p2);
                                p2 = pl;
                                this.linkData.Add(p2);
                                flg = true;
                            }

                            if (flg)
                            {
                                p1.End.Link(p2.Start);
                                this.linkData.Remove(p2);
                                flg = true;
                                goto ReTry;
                            }
                        }
                    }
                }

ReTry:

                if (!flg)
                {
                    break;
                }
            }

            for (int i = 0; i < this.linkData.Count; i++)
            {
                PointLink pl = this.linkData[i];

                if (pl.Start.Point.Y > pl.End.Point.Y ||
                    (pl.Start.Point.Y == pl.End.Point.Y && pl.Start.Point.X > pl.End.Point.X))
                {
                    this.linkData[i] = pl.Reverse();
                }
            }

            this.linkData.Sort(new Sorter());
        }
Esempio n. 10
0
        public PointLink[] Split()
        {
            PointLink p1 = this.start;
            PointLink p2 = this;

            p1.end       = p2.prev;
            p2.prev.end  = p2.prev;
            p2.prev.next = null;

            p2.start     = p2;
            p2.prev      = null;
            p2.end.start = p2;

            PointLink tmp = p1;

            //Debug.WriteLine("");

            //Debug.WriteLine(this);

            //Debug.WriteLine("");

            int len = 0;

            while (tmp != null)
            {
                len++;
                tmp = tmp.next;
            }

            tmp = p1;
            while (tmp != null)
            {
                tmp.length = len;
                tmp.end    = tmp.start.end;

                //Debug.WriteLine(tmp);

                tmp = tmp.next;
            }

            tmp = p2;

            //Debug.WriteLine("");

            len = 0;
            while (tmp != null)
            {
                len++;
                tmp = tmp.next;
            }

            tmp = p2;
            while (tmp != null)
            {
                tmp.length = len;
                tmp.start  = p2.start;

                //Debug.WriteLine(tmp);

                tmp = tmp.next;
            }


            return(new PointLink[] { p1, p2 });
        }