- int cur_path = -1;
- if(track->get_turnout_id() && route)
- cur_path = route->get_turnout(track->get_turnout_id());
- if(cur_path==-1)
- cur_path = track->get_active_path();
-
- if(len)
- *len += track->get_type().get_path_length(cur_path);
-
- unsigned other_ep = track->traverse(track_ep, cur_path);
- for(unsigned i=0; i<endpoints.size(); ++i)
- if(endpoints[i].track==track && endpoints[i].track_ep==static_cast<unsigned>(other_ep))
- return i;
-
- Track *next = track->get_link(other_ep);
- if(!tracks.count(next))
- throw LogicError("Block traversal strayed out of the block");
- track_ep = next->get_endpoint_by_link(*track);
- track = next;
+ unsigned path = (route ? route->get_path(*t_iter) : t_iter->get_active_path());
+ result += t_iter->get_type().get_path_length(path);
+
+ t_iter = t_iter.next(path);