private void ConnectPrimaryNodes(PrimaryNode node1, PrimaryNode node2) { LocationConnection newConnection = new LocationConnection(node1, node2); connections.Add(newConnection); node1.connections.Add(newConnection); node2.connections.Add(newConnection); }
private void GeneratePrimaryNodes() { primaryNodes = new List <PrimaryNode>(); foreach (GraphEdge edge in graphEdges) { PrimaryNode node1 = new PrimaryNode(edge.point1); PrimaryNode node2 = new PrimaryNode(edge.point2); if (edge.point1 == edge.point2 || edge.cell1 == null || edge.cell2 == null) { continue; } if (primaryNodes.Any(n => n.mapPosition == node1.mapPosition)) { node1 = primaryNodes.Find(n => n.mapPosition == node1.mapPosition); } else { primaryNodes.Add(node1); } if (primaryNodes.Any(n => n.mapPosition == node2.mapPosition)) { node2 = primaryNodes.Find(n => n.mapPosition == node2.mapPosition); } else { primaryNodes.Add(node2); } edge.node1 = node1; edge.node2 = node2; node1.AddEdge(edge); } /*foreach (PrimaryNode node in primaryNodes) * { * List<int> adjacentGroups = new List<int>(); * * foreach (VoronoiCell cell in node.adjacentCells) * { * if (cell == null) * { * adjacentGroups = new List<int>(1); * break; * } * if (!adjacentGroups.Contains(cell.group)) * adjacentGroups.Add(cell.group); * } * if (adjacentGroups.Count == 1 && adjacentGroups[0] != -1) * node.invalid = true; * }*/ }
private bool isTooCloseToExistingNode(PrimaryNode newNode, out PrimaryNode outNode) { bool tooClose = false; outNode = null; foreach (PrimaryNode node in primaryNodes) { tooClose = (Vector2.Distance(node.mapPosition, newNode.mapPosition) <= minDistance) == true ? true : tooClose; outNode = node; } return(tooClose); }
public void AddEdge(GraphEdge edge, PrimaryNode newNode = null) { connectedEdges.Add(edge); if (!adjacentCells.Contains(edge.cell1)) { adjacentCells.Add(edge.cell1); } if (!adjacentCells.Contains(edge.cell2)) { adjacentCells.Add(edge.cell2); } if (edge.node1 == newNode) { edge.node1 = this; } else if (edge.node2 == newNode) { edge.node2 = this; } group = edge.cell1.cellState == VoronoiCell.CELLSTATE.ASSIGNED ? edge.cell1.group : edge.cell2.group; }
public LocationConnection(PrimaryNode node1, PrimaryNode node2) { primaryNodes = new PrimaryNode[] { node1, node2 }; missionsCompleted = 0; }