}
// TODO profiling ... lookup done quite often even w/o any trafficlights
public TrafficLightLocationWithDistance getNextDownstreamTrafficLight(double position, int lane,
double maxLookAheadDistance) {
TrafficLightLocation trafficLightLocation = getNextDownstreamTrafficLight(position);
double distance = (trafficLightLocation != null) ? trafficLightLocation.position() - position : roadLength
- position;
RoadSegment segment = this;
while (trafficLightLocation == null && distance < maxLookAheadDistance) {
segment = segment.sinkRoadSegment(Math.min(lane, segment.laneCount));
if (segment == null) {
break;
}
trafficLightLocation = segment.getNextDownstreamTrafficLight(0);
distance += (trafficLightLocation != null) ? trafficLightLocation.position() : segment.roadLength();
}
return trafficLightLocation == null ? null : new TrafficLightLocationWithDistance(trafficLightLocation,
distance);
}