示例#1
0
        private void AddSites(List <Bubbles.Node> nodes)         //jf
        {
            Vector2 p = new Vector2();

            for (int i = 0; i < nodes.Count; ++i)
            {
                Bubbles.Node node = nodes[i];
                p.x = node.x; p.y = node.y;
                //move toward zero, so stay within plotBounds. Guarantee unique position of all nodes
                while (_sitesIndexedByLocation.ContainsKey(p))
                {
                    p.x += (p.x < 0)? UnityEngine.Random.Range(0, 0.000001f): -UnityEngine.Random.Range(0, 0.000001f);
                }
                if (node.site == null)
                {
                    node.site = Site.Create(p, (uint)i, node);
                }
                else
                {
                    node.site.Init(p, (uint)i, node);                   // both node and site reference each other
                }
                if (i >= _sites.Count)
                {
                    _sites.Add(node.site);
                }
                else
                {
                    _sites.Plant(node.site, i);
                }
                _sitesIndexedByLocation [p] = node.site;
            }
        }
示例#2
0
文件: Site.cs 项目: tliawi/bubbles
        private Site(Vector2 p, uint index, Bubbles.Node node)
        {
//			if (lock != PrivateConstructorEnforcer)
//			{
//				throw new Error("Site constructor is private");
//			}
            Init(p, index, node);
        }
示例#3
0
文件: Site.cs 项目: tliawi/bubbles
 public Site Init(Vector2 p, uint index, Bubbles.Node node) //jf made public
 {
     Clear();                                               //jf added, so I can recycle used sites
     _coord     = p;
     _siteIndex = index;
     this.node  = node;
     _edges     = new List <Edge> ();
     _region    = null;
     return(this);
 }
示例#4
0
文件: Site.cs 项目: tliawi/bubbles
 public static Site Create(Vector2 p, uint index, Bubbles.Node node)          //jf, using node where once there was 'color' throughout this class
 {
     if (_pool.Count > 0)
     {
         return(_pool.Pop().Init(p, index, node));
     }
     else
     {
         return(new Site(p, index, node));
     }
 }