Example #1
0
		public Node RemoveConnection(Node node, bool recur)
		{
			if (_nodeConntections.Contains(node))
			{
				Debug.Log("Node: there is no connection to the given node");
				return this;
			}
			_nodeConntections.Remove(node);
			if (recur)
				node.RemoveConnection(this, false);
			return this;
		}
Example #2
0
		public Node AddConnection(Node node, bool recur)
		{
			if (_nodeConntections.Count == _maxConnections)
			{
				Debug.LogWarning("Node: too many node connections");
				return this;
			}
			if (node.connectionCount == node.maxConnections && recur)
			{
				Debug.LogWarning("Node: target node has too many connections");
				return this;
			}
			_nodeConntections.Add(node);
			if (recur)
				node.AddConnection(this, false);
			return this;
		}
Example #3
0
		//Find the closest nodes to a given node
		List<Node> GetClosestNodes(Node node)
		{
			List<Node> cNodes = new List<Node>();
			float d = float.PositiveInfinity;
			foreach(Node n in nodes)
			{
				if (n.isConnected(node))
					continue;
				if (n == node)
					continue;
				float cd = Vector2.Distance(node.position, n.position);
				if(cd < d)
				{
					if (cNodes.Count >= node.maxConnections)
						cNodes.RemoveAt(0);
					d = cd;
					cNodes.Add(n);
				}
				
			}
			return cNodes;
		}
Example #4
0
		//Check if a given node has a connection to this node
		public bool isConnected(Node n)
		{
			return _nodeConntections.Contains(n);
		}
Example #5
0
		//Remove connection between nodes
		public Node RemoveConnection(Node node)
		{
			return RemoveConnection(node, true);
		}
Example #6
0
		//Connect to other nodes
		public Node AddConnection(Node node)
		{
			return AddConnection(node, true);
		}