Ejemplo n.º 1
0
        public RDList SuccessiveEdgesOf(RDEdge lhs, object factPool)
        {
            int x = lhs.X, y = lhs.Y;

            if (lhs.Direction == false)//(-)
            {
                return(new RDList(new RDElement[]
                {
                    new RDEdge(x, y, true),
                    new RDEdge(x - 1, y, true),
                    new RDEdge(x, y + 1, true),
                    new RDEdge(x - 1, y + 1, true),
                    new RDEdge(x, y - 1, false),
                    new RDEdge(x, y + 1, false)
                }));
            }
            else//(|)
            {
                return(new RDList(new RDElement[]
                {
                    new RDEdge(x, y, false),
                    new RDEdge(x, y - 1, false),
                    new RDEdge(x + 1, y, false),
                    new RDEdge(x + 1, y - 1, false),
                    new RDEdge(x - 1, y, true),
                    new RDEdge(x + 1, y, true)
                }));
            }
        }
Ejemplo n.º 2
0
        public RDNumber ColorOf(RDEdge edge, object factPool)
        {
            FactPool pool = (FactPool)factPool;

            int[,] arr = edge.Direction ? pool.VLine : pool.HLine;
            return(new RDNumber(arr[edge.X, edge.Y]));
        }
        private int GetEdgeState(RDEdge edge, object factPool)
        {
            FactPool pool = (FactPool)factPool;

            if (edge.Direction == false)
            {
                return(pool.HLine[edge.X, edge.Y]);
            }
            else
            {
                return(pool.VLine[edge.X, edge.Y]);
            }
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
0
        public bool ColorOf(RDEdge edge, RDNumber result, object factPool)
        {
            //Console.WriteLine(edge.X + "::" + edge.Y);
            FactPool pool = (FactPool)factPool;

            int[,] arr = edge.Direction ? pool.VLine : pool.HLine;
            if (arr[edge.X, edge.Y] != 0)
            {
                if (arr[edge.X, edge.Y] != result.Data)
                {
                    throw new Exception("结果冲突!");
                }
                return(false);
            }
            arr[edge.X, edge.Y] = result.Data;
            return(true);
        }
Ejemplo n.º 6
0
 public RDList OppositeEdgesOf(RDEdge edge, object factPool)
 {
     if (edge.Direction == false)
     {
         return(new RDList(new RDElement[]
         {
             new RDEdge(edge.X + 1, edge.Y, edge.Direction),
             new RDEdge(edge.X - 1, edge.Y, edge.Direction)
         }));
     }
     else
     {
         return(new RDList(new RDElement[]
         {
             new RDEdge(edge.X, edge.Y + 1, edge.Direction),
             new RDEdge(edge.X, edge.Y - 1, edge.Direction)
         }));
     }
 }
Ejemplo n.º 7
0
        public RDList CommonSuccessiveEdgesOf(RDEdge lhs, RDEdge rhs, object factPool)
        {
            RDList llist  = SuccessiveEdgesOf(lhs, factPool);
            RDList rlist  = SuccessiveEdgesOf(rhs, factPool);
            RDList result = new RDList();

            foreach (RDElement e1 in llist.Data)
            {
                foreach (RDElement e2 in rlist.Data)
                {
                    if ((e1 as RDEdge).X == (e2 as RDEdge).X && (e1 as RDEdge).Y == (e2 as RDEdge).Y && (e1 as RDEdge).Direction == (e2 as RDEdge).Direction)
                    {
                        result.Data.Add(e1);
                        break;
                    }
                }
            }
            return(result);
        }
Ejemplo n.º 8
0
 public RDBool IsEdgeTouch(RDEdge lhs, RDEdge rhs, object factPool)
 {
     if (lhs.X == rhs.X && lhs.Y == rhs.Y)
     {
         return(new RDBool(true));
     }
     if (lhs.X + (lhs.Direction ? 1 : 0) == rhs.X && lhs.Y + (lhs.Direction ? 0 : 1) == rhs.Y)
     {
         return(new RDBool(true));
     }
     if (lhs.X + (lhs.Direction ? 1 : 0) == rhs.X + (rhs.Direction ? 1 : 0) && lhs.Y + (lhs.Direction ? 0 : 1) == rhs.Y + (rhs.Direction ? 0 : 1))
     {
         return(new RDBool(true));
     }
     if (lhs.X == rhs.X + (rhs.Direction ? 1 : 0) && lhs.Y == rhs.Y + (rhs.Direction ? 0 : 1))
     {
         return(new RDBool(true));
     }
     return(new RDBool(false));
 }
Ejemplo n.º 9
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)));
 }