Skip to content

Commit

Permalink
fix #3907
Browse files Browse the repository at this point in the history
  • Loading branch information
namdre committed Jan 19, 2019
1 parent 202a62a commit 90d225c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 21 deletions.
41 changes: 21 additions & 20 deletions src/guisim/GUIVehicle.cpp
Expand Up @@ -494,25 +494,26 @@ GUIVehicle::drawRouteHelper(const GUIVisualizationSettings& s, const MSRoute& r)


MSLane*
GUIVehicle::getPreviousLane(MSLane* current, int& furtherIndex) const {
if (furtherIndex < (int)myFurtherLanes.size()) {
return myFurtherLanes[furtherIndex++];
} else {
const int routeIndex = (int)(getCurrentRouteEdge() - myRoute->begin());
int backIndex = furtherIndex + 1;
for (MSLane* l : myFurtherLanes) {
if (l->isInternal()) {
backIndex--;
GUIVehicle::getPreviousLane(MSLane* current, int& routeIndex) const {
if (current->isInternal()) {
return current->getIncomingLanes().front().lane;
}
if (routeIndex > 0) {
routeIndex--;
const MSEdge* prevNormal = myRoute->getEdges()[routeIndex];
for (MSLane* cand : prevNormal->getLanes()) {
for (MSLink* link : cand->getLinkCont()) {
if (link->getLane() == current) {
if (link->getViaLane() != nullptr) {
return link->getViaLane();
} else {
return const_cast<MSLane*>(link->getLaneBefore());
}
}
}
}
if (routeIndex >= backIndex) {
furtherIndex++;
// could also look for the first lane that allows this vehicle class
// but this is probably not an issue for trains
return (*(getCurrentRouteEdge() - backIndex))->getLanes()[0];
}
return current;
}
return current;
}


Expand Down Expand Up @@ -546,10 +547,10 @@ GUIVehicle::drawAction_drawRailCarriages(const GUIVisualizationSettings& s, doub
const double carriageLength = carriageLengthWithGap - carriageGap;
// lane on which the carriage front is situated
MSLane* lane = myLane;
int furtherIndex = 0;
int routeIndex = getRoutePosition();
// lane on which the carriage back is situated
MSLane* backLane = myLane;
int backFurtherIndex = furtherIndex;
int backRouteIndex = routeIndex;
// offsets of front and back
double carriageOffset = myState.pos();
double carriageBackOffset = myState.pos() - carriageLength;
Expand All @@ -563,7 +564,7 @@ GUIVehicle::drawAction_drawRailCarriages(const GUIVisualizationSettings& s, doub
// draw individual carriages
for (int i = 0; i < numCarriages; ++i) {
while (carriageOffset < 0) {
MSLane* prev = getPreviousLane(lane, furtherIndex);
MSLane* prev = getPreviousLane(lane, routeIndex);
if (prev != lane) {
carriageOffset += prev->getLength();
} else {
Expand All @@ -573,7 +574,7 @@ GUIVehicle::drawAction_drawRailCarriages(const GUIVisualizationSettings& s, doub
lane = prev;
}
while (carriageBackOffset < 0) {
MSLane* prev = getPreviousLane(backLane, backFurtherIndex);
MSLane* prev = getPreviousLane(backLane, backRouteIndex);
if (prev != backLane) {
carriageBackOffset += prev->getLength();
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/guisim/GUIVehicle.h
Expand Up @@ -169,7 +169,7 @@ class GUIVehicle : public MSVehicle, public GUIBaseVehicle {
* @param[in] current The lane of which the predecessor should be returned
* @param[in,out] routeIndex The index of the current or previous non-internal edge in the route
*/
MSLane* getPreviousLane(MSLane* current, int& furtherIndex) const;
MSLane* getPreviousLane(MSLane* current, int& routeIndex) const;

/// @brief return the number of passengers
int getNumPassengers() const;
Expand Down

0 comments on commit 90d225c

Please sign in to comment.