Added edge creation and rendering

This commit is contained in:
2024-06-30 23:02:15 +02:00
parent 25f1b20a7a
commit f53dab338a
2 changed files with 28 additions and 4 deletions

View File

@ -15,6 +15,12 @@ class Graph:
def add_edge(self, start_index: int, end_index: int, length: float) -> None:
self.edges.append(Edge(start_index, end_index, length))
def number_of_nodes(self) -> int:
return len(self.nodes)
def get_edge_nodes(self, edge) -> tuple[Node, Node]:
return self.nodes[edge.start], self.nodes[edge.end]
def edges_adjacent_to(self, node_i: int) -> Iterator[Edge]:
return filter(lambda e: e.start == node_i or e.end == node_i, self.edges)