team-3/src/c3nav/routing/connection.py

16 lines
541 B
Python
Raw Normal View History

2016-12-05 13:49:23 +01:00
import numpy as np
2016-12-03 19:09:39 +01:00
class GraphConnection():
2016-12-05 13:49:23 +01:00
def __init__(self, graph, from_point, to_point, distance=None):
2016-12-03 19:09:39 +01:00
self.graph = graph
self.from_point = from_point
self.to_point = to_point
2016-12-05 13:49:23 +01:00
self.distance = distance if distance is not None else np.linalg.norm(from_point.xy - to_point.xy)
2016-12-03 19:09:39 +01:00
if to_point in from_point.connections:
self.graph.connections.remove(from_point.connections[to_point])
from_point.connections[to_point] = self
to_point.connections_in[from_point] = self