Files
sunnypilot/selfdrive/mapd/lib/WayRelationIndex.py
T
Jason Wen bf659453aa move-fast: mapd, Speed Limit Control, Vision & Map Turn Speed Control (#111)
* move-fast: Hands on wheel monitoring: Implementation according to r079r4e regulation

* move-fast: VisionTurnController Implementation & UI prerequisites

* move-fast: LiveMapData: Implementation & UI prerequisites

* add dependencies

* move-fast: SpeedLimitControl: Implementation & UI prerequisites

* move-fast: TurnSpeedController: Implementation & UI prerequisites

* move-fast: Debug: Tap on Ui to capture snapshot of debug data & UI prerequisites

* Debug UI: Toggle to display debug UI elements & UI prerequisites
2023-02-13 11:38:11 -05:00

35 lines
1.3 KiB
Python

class WayRelationIndex():
"""
A class containing an index of WayRelations by node ids of internal nodes and edge nodes.
"""
def __init__(self, way_relations):
self._edge_nodes_index_dict = {}
self._full_nodes_index_dict = {}
for wr in way_relations:
self.add(wr)
def add(self, way_relation):
for node in way_relation.way.nodes:
node_id = node.id
self._full_nodes_index_dict[node_id] = self._full_nodes_index_dict.get(node_id, []) + [way_relation]
if node_id in way_relation.edge_nodes_ids:
self._edge_nodes_index_dict[node_id] = self._edge_nodes_index_dict.get(node_id, []) + [way_relation]
def remove(self, way_relation):
for node in way_relation.way.nodes:
node_id = node.id
self._full_nodes_index_dict[node_id] = [wr for wr in self._full_nodes_index_dict.get(node_id, [])
if wr is not way_relation]
if node_id in way_relation.edge_nodes_ids:
self._edge_nodes_index_dict[node_id] = [wr for wr in self._edge_nodes_index_dict.get(node_id, [])
if wr is not way_relation]
def way_relations_with_edge_node_id(self, node_id):
return self._edge_nodes_index_dict.get(node_id, [])
def way_relations_with_node_id(self, node_id):
return self._full_nodes_index_dict.get(node_id, [])