Exemple #1
0
        public RDList MostAwayFrom(RDList edges, RDCell cell, object factPool)
        {
            int[] Dist    = edges.Data.Select(e => DistanceOfEdgeAndCell((RDEdge)e, cell)).ToArray();
            int   maxDist = Dist.Max();

            return(new RDList(edges.Data.Where(e => DistanceOfEdgeAndCell((RDEdge)e, cell) == maxDist).ToArray()));
        }
        public void DiagonalNumberPair(string name1, string name2, Dictionary <string, RDElement> dict, object factPool, Rule rule, Action <int> callBack, int callBackID)
        {
            FactPool pool = (FactPool)factPool;

            for (int x = 1; x <= pool.X; ++x)
            {
                for (int y = 1; y <= pool.Y; ++y)
                {
                    if (IsUnfinishedNumberCell(x, y, factPool) && IsUnfinishedNumberCell(x + 1, y + 1, factPool))
                    {
                        dict[name1] = new RDCell(x, y);
                        dict[name2] = new RDCell(x + 1, y + 1);
                        callBack.Invoke(callBackID);
                    }
                    if (IsUnfinishedNumberCell(x, y + 1, factPool) && IsUnfinishedNumberCell(x + 1, y, factPool))
                    {
                        dict[name1] = new RDCell(x, y + 1);
                        dict[name2] = new RDCell(x + 1, y);
                        callBack.Invoke(callBackID);
                    }
                }
            }
            dict.Remove(name1);
            dict.Remove(name2);
        }
        public void NeighborNumberPair(string name1, string name2, Dictionary <string, RDElement> dict, object factPool, Rule rule, Action <int> callBack, int callBackID)
        {
            FactPool pool = (FactPool)factPool;

            for (int x = 1; x <= pool.X; ++x)
            {
                for (int y = 1; y <= pool.Y; ++y)
                {
                    if (IsUnfinishedNumberCell(x, y, factPool) && IsUnfinishedNumberCell(x, y + 1, factPool))
                    {
                        dict[name1] = new RDCell(x, y);
                        dict[name2] = new RDCell(x, y + 1);
                        //Console.WriteLine(x + "," + y + ",y," + pool.Cell[x, y] + pool.Cell[x, y + 1]);
                        callBack.Invoke(callBackID);
                        dict[name1] = new RDCell(x, y + 1);
                        dict[name2] = new RDCell(x, y);
                        //Console.WriteLine(x + "," + y + ",y," + pool.Cell[x, y] + pool.Cell[x, y + 1]);
                        callBack.Invoke(callBackID);
                    }
                    if (IsUnfinishedNumberCell(x, y, factPool) && IsUnfinishedNumberCell(x + 1, y, factPool))
                    {
                        dict[name1] = new RDCell(x, y);
                        dict[name2] = new RDCell(x + 1, y);
                        //Console.WriteLine(x + "," + y + ",x," + pool.Cell[x, y] + pool.Cell[x + 1, y]);
                        callBack.Invoke(callBackID);
                        dict[name1] = new RDCell(x + 1, y);
                        dict[name2] = new RDCell(x, y);
                        //Console.WriteLine(x + "," + y + ",x," + pool.Cell[x, y] + pool.Cell[x + 1, y]);
                        callBack.Invoke(callBackID);
                    }
                }
            }
            dict.Remove(name1);
            dict.Remove(name2);
        }
Exemple #4
0
 public RDList AllEdgesOf(RDCell cell, object factPool)
 {
     return(new RDList(new RDElement[] {
         new RDEdge(cell.X, cell.Y, false),
         new RDEdge(cell.X, cell.Y, true),
         new RDEdge(cell.X + 1, cell.Y, false),
         new RDEdge(cell.X, cell.Y + 1, true)
     }));
 }
Exemple #5
0
        private int DistanceOfEdgeAndCell(RDEdge edge, RDCell cell)
        {
            int x = edge.X * 2, y = edge.Y * 2;

            if (edge.Direction)
            {
                y--;
            }
            else
            {
                x--;
            }
            x -= cell.X * 2;
            y -= cell.Y * 2;
            return(x * x + y * y);
        }
Exemple #6
0
        public RDEdge CommonEdgeOf(RDCell lhs, RDCell rhs, object factPool)
        {
            RDCell a = (lhs.X + lhs.Y < rhs.X + rhs.Y) ? lhs : rhs;
            RDCell b = (lhs.X + lhs.Y < rhs.X + rhs.Y) ? rhs : lhs;

            if (a.X == b.X && a.Y + 1 == b.Y)
            {
                return(new RDEdge(b.X, b.Y, true));
            }
            else if (a.X + 1 == b.X && a.Y == b.Y)
            {
                return(new RDEdge(b.X, b.Y, false));
            }
            else
            {
                throw new Exception("两个Cell没有公共边!");
            }
        }
Exemple #7
0
 public RDBool IsNear(RDEdge edge, RDCell cell, object factPool)
 {
     return(new RDBool((edge.X == cell.X && edge.Y == cell.Y) ||
                       (edge.Direction == true && edge.X == cell.X && edge.Y == cell.Y + 1) ||
                       (edge.Direction == false && edge.X == cell.X + 1 && edge.Y == cell.Y)));
 }
Exemple #8
0
 public RDNumber NumberOf(RDCell cell, object factPool)
 {
     return(new RDNumber(((FactPool)factPool).Cell[cell.X, cell.Y]));
 }