@@ -204,31 +204,45 @@ def createUTurnConnectionRoads(self, nextRoadId, outsideRoads, cp1, strategy=Lan
204204
205205
206206 def createRoadsForLinkConfig (self , nextRoadId , roadDic , firstRoadId , incomingRoad , cp1 , linkConfig ):
207- newConnectionRoads = []
208- for link in linkConfig :
207+ """[summary]
209208
210- fromUniqueLaneId = link [0 ]
211- incomingLaneId = int (fromUniqueLaneId .split (':' )[1 ])
209+ Args:
210+ nextRoadId ([type]): [description]
211+ roadDic ([type]): Instead of a list of current roads, supply a dictionary where each road is keyed with its id as a string.
212+ firstRoadId ([type]): [description]
213+ incomingRoad ([type]): [description]
214+ cp1 ([type]): cp of the first road that is connected to the intersection.
215+ linkConfig ([type]): a list of tuples where each tuple defines a unique connection between two lanes. A link is a tuple ('incoming-road-id:lane-id', 'outgoing-road-id:lane-id')
212216
213- toUniqueLaneId = link [1 ]
214- outgoingRoadId = int (toUniqueLaneId .split (':' )[0 ])
215- outgoingLaneId = int (toUniqueLaneId .split (':' )[1 ])
217+ Returns:
218+ [type]: [description]
219+ """
220+ newConnectionRoads = []
221+ for link in linkConfig :
222+
223+
224+ fromUniqueLaneId = link [0 ]
225+ incomingLaneId = int (fromUniqueLaneId .split (':' )[1 ])
216226
217- outgoingRoad = roadDic [outgoingRoadId ]
227+ toUniqueLaneId = link [1 ]
228+ outgoingRoadId = int (toUniqueLaneId .split (':' )[0 ])
229+ outgoingLaneId = int (toUniqueLaneId .split (':' )[1 ])
218230
219- if firstRoadId == incomingRoad .id and firstRoadId == outgoingRoad .id : # for U-turns
220- newConnection = self .createSingleLaneConnectionRoad (nextRoadId , incomingRoad , outgoingRoad , incomingLaneId , outgoingLaneId , cp1 , cp1 )
221- elif firstRoadId == incomingRoad .id :
222- newConnection = self .createSingleLaneConnectionRoad (nextRoadId , incomingRoad , outgoingRoad , incomingLaneId , outgoingLaneId , cp1 , pyodrx .ContactPoint .start )
223- elif firstRoadId == outgoingRoad .id :
224- newConnection = self .createSingleLaneConnectionRoad (nextRoadId , incomingRoad , outgoingRoad , incomingLaneId , outgoingLaneId , pyodrx .ContactPoint .start , cp1 )
225- else :
226- newConnection = self .createSingleLaneConnectionRoad (nextRoadId , incomingRoad , outgoingRoad , incomingLaneId , outgoingLaneId , pyodrx .ContactPoint .start , pyodrx .ContactPoint .start )
231+ outgoingRoad = roadDic [outgoingRoadId ]
232+
233+ if firstRoadId == incomingRoad .id and firstRoadId == outgoingRoad .id : # for U-turns
234+ newConnection = self .createSingleLaneConnectionRoad (nextRoadId , incomingRoad , outgoingRoad , incomingLaneId , outgoingLaneId , cp1 , cp1 )
235+ elif firstRoadId == incomingRoad .id :
236+ newConnection = self .createSingleLaneConnectionRoad (nextRoadId , incomingRoad , outgoingRoad , incomingLaneId , outgoingLaneId , cp1 , pyodrx .ContactPoint .start )
237+ elif firstRoadId == outgoingRoad .id :
238+ newConnection = self .createSingleLaneConnectionRoad (nextRoadId , incomingRoad , outgoingRoad , incomingLaneId , outgoingLaneId , pyodrx .ContactPoint .start , cp1 )
239+ else :
240+ newConnection = self .createSingleLaneConnectionRoad (nextRoadId , incomingRoad , outgoingRoad , incomingLaneId , outgoingLaneId , pyodrx .ContactPoint .start , pyodrx .ContactPoint .start )
227241
228- newConnectionRoads .append (newConnection )
242+ newConnectionRoads .append (newConnection )
229243
230- nextRoadId += 1
244+ nextRoadId += 1
231245
232- logging .debug (f"{ self .name } : created connection for link { link } " )
246+ logging .debug (f"{ self .name } : created connection for link { link } " )
233247
234- return newConnectionRoads
248+ return newConnectionRoads
0 commit comments