public Cell GetCell(Vector2 position, Satsuma.Node node, bool createOK, out bool didCreate)
        {
            Cell cell = cellList.Find(delegate(Cell c)
            {
                Vector2 vector = c.position - position;
                return(vector.x < 1f && vector.x > -1f && vector.y < 1f && vector.y > -1f);
            });

            didCreate = false;
            if (cell == null)
            {
                if (!createOK)
                {
                    Debug.LogWarning("Cant create Cell but no cell found");
                    return(null);
                }
                cell = cellList.Find((Cell c) => c.node == node);
                if (cell == null)
                {
                    cell      = new Cell(node);
                    didCreate = true;
                    cell.SetPosition(position);
                    cellList.Add(cell);
                }
                else
                {
                    Debug.LogWarning("GetCell Same node [" + node.Id + "] differnt position!");
                }
            }
            return(cell);
        }
        public PointD GetPositionForNode(Satsuma.Node node)
        {
            Node    node2     = nodeList.Find((Node n) => n.node == node);
            Vector2 position  = node2.position;
            double  x         = (double)position.x;
            Vector2 position2 = node2.position;

            return(new PointD(x, (double)position2.y));
        }
        public bool Layout(Polygon bounds = null)
        {
            bool    flag   = false;
            int     num    = 0;
            Vector2 vector = default(Vector2);

            while (!flag && num < 100)
            {
                flag = true;
                Func <Satsuma.Node, PointD> initialPositions = (Satsuma.Node n) => GetPositionForNode(n);
                CustomGraph         baseGraph           = this.baseGraph;
                int                 seed                = num;
                ForceDirectedLayout forceDirectedLayout = new ForceDirectedLayout(baseGraph, initialPositions, seed);
                forceDirectedLayout.ExternalForce = ((PointD point) => GetForceForBoundry(point, bounds));
                forceDirectedLayout.Run(0.01);
                IEnumerator <Satsuma.Node> enumerator = this.baseGraph.Nodes().GetEnumerator();
                int num2 = 0;
                while (enumerator.MoveNext())
                {
                    Satsuma.Node node  = enumerator.Current;
                    Node         node2 = nodeList.Find((Node n) => n.node == node);
                    if (node2 != null)
                    {
                        vector.x = (float)forceDirectedLayout.NodePositions[node].X;
                        vector.y = (float)forceDirectedLayout.NodePositions[node].Y;
                        if (!bounds.Contains(vector))
                        {
                            flag = false;
                            Debug.LogWarning("Re-doing layout - cell was off map");
                            break;
                        }
                        node2.SetPosition(vector);
                    }
                    if (!flag)
                    {
                        break;
                    }
                    num2++;
                }
                num++;
            }
            if (num >= 10)
            {
                Debug.LogWarning("Re-ran layout " + num + " times");
            }
            return(flag);
        }
 public Cell(Satsuma.Node node)
     : base(node, WorldGenTags.Cell.Name)
 {
     Init();
 }
Esempio n. 5
0
 public Node(Satsuma.Node node, string type)
 {
     this.node = node;
     this.type = type;
 }
        public Cell GetCell(Vector2 position, Satsuma.Node node, bool createOK = true)
        {
            bool didCreate;

            return(GetCell(position, node, createOK, out didCreate));
        }
 public Cell GetCell(Satsuma.Node node)
 {
     return(cellList.Find((Cell c) => c.node == node));
 }
 public Corner(Satsuma.Node node)
     : base(node, WorldGenTags.Corner.Name)
 {
     Init();
 }