Skip to content

Commit

Permalink
fix #10595
Browse files Browse the repository at this point in the history
  • Loading branch information
namdre committed Apr 26, 2022
1 parent 969521b commit 0b0bf3b
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/microsim/MSLane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3376,9 +3376,9 @@ MSLane::getFollowersOnConsecutive(const MSVehicle* ego, double backOffset,
// be between itself and the first "actual" sublane
// shift the offset so that we "see" this vehicle
if (ego->getLeftSideOnLane() < -MSGlobals::gLateralResolution) {
result.setSublaneOffset(floor(-ego->getLeftSideOnLane() / MSGlobals::gLateralResolution) * MSGlobals::gLateralResolution);
result.setSublaneOffset(floor(-ego->getLeftSideOnLane() / MSGlobals::gLateralResolution));
} else if (ego->getRightSideOnLane() > getWidth() + MSGlobals::gLateralResolution) {
result.setSublaneOffset(-floor((ego->getRightSideOnLane() - getWidth()) / MSGlobals::gLateralResolution) * MSGlobals::gLateralResolution);
result.setSublaneOffset(-floor((ego->getRightSideOnLane() - getWidth()) / MSGlobals::gLateralResolution));
}
#ifdef DEBUG_CONTEXT
if (DEBUG_COND2(ego)) {
Expand Down
6 changes: 3 additions & 3 deletions src/microsim/MSLaneChangerSublane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -615,12 +615,12 @@ MSLaneChangerSublane::getLeaders(const ChangerIt& target, const MSVehicle* vehic
MSLeaderDistanceInfo result(target->lane, nullptr, 0);
if (target->lane == vehicle->getLane()) {
if (vehicle->getLeftSideOnLane() < -MSGlobals::gLateralResolution) {
result.setSublaneOffset(floor(-vehicle->getLeftSideOnLane() / MSGlobals::gLateralResolution) * MSGlobals::gLateralResolution);
result.setSublaneOffset(floor(-vehicle->getLeftSideOnLane() / MSGlobals::gLateralResolution));
} else if (vehicle->getRightSideOnLane() > target->lane->getWidth() + MSGlobals::gLateralResolution) {
result.setSublaneOffset(-floor((vehicle->getRightSideOnLane() - target->lane->getWidth()) / MSGlobals::gLateralResolution) * MSGlobals::gLateralResolution);
result.setSublaneOffset(-floor((vehicle->getRightSideOnLane() - target->lane->getWidth()) / MSGlobals::gLateralResolution));
}
}
int sublaneShift = result.getSublaneOffset() / MSGlobals::gLateralResolution;
const int sublaneShift = result.getSublaneOffset();
for (int i = 0; i < target->ahead.numSublanes(); ++i) {
const MSVehicle* veh = target->ahead[i];
if (veh != nullptr) {
Expand Down
13 changes: 10 additions & 3 deletions src/microsim/MSLeaderInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ MSLeaderInfo::getSubLanes(const MSVehicle* veh, double latOffset, int& rightmost
return;
}
// map center-line based coordinates into [0, myWidth] coordinates
const double vehCenter = veh->getLateralPositionOnLane() + 0.5 * myWidth + latOffset + myOffset;
const double vehCenter = veh->getLateralPositionOnLane() + 0.5 * myWidth + latOffset + myOffset * MSGlobals::gLateralResolution;
const double vehHalfWidth = 0.5 * veh->getVehicleType().getWidth();
double rightVehSide = vehCenter - vehHalfWidth;
double leftVehSide = vehCenter + vehHalfWidth;
Expand Down Expand Up @@ -155,8 +155,8 @@ MSLeaderInfo::getSublaneBorders(int sublane, double latOffset, double& rightSide
assert(sublane >= 0);
assert(sublane < (int)myVehicles.size());
const double res = MSGlobals::gLateralResolution > 0 ? MSGlobals::gLateralResolution : myWidth;
rightSide = sublane * res + latOffset - myOffset;
leftSide = MIN2((sublane + 1) * res, myWidth) + latOffset - myOffset;
rightSide = sublane * res + latOffset - myOffset * MSGlobals::gLateralResolution;
leftSide = MIN2((sublane + 1) * res, myWidth) + latOffset - myOffset * MSGlobals::gLateralResolution;
}


Expand Down Expand Up @@ -184,6 +184,13 @@ MSLeaderInfo::toString() const {
}


void
MSLeaderInfo::setSublaneOffset(int offset) {
assert(MSGlobals::gLateralResolution > 0);
myOffset = offset;
}


bool
MSLeaderInfo::hasStoppedVehicle() const {
if (!myHasVehicles) {
Expand Down
9 changes: 4 additions & 5 deletions src/microsim/MSLeaderInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,12 @@ class MSLeaderInfo {
return myVehicles;
}

double getSublaneOffset() const {
int getSublaneOffset() const {
return myOffset;
}

void setSublaneOffset(double offset) {
myOffset = offset;
}
/// @brief set number of sublanes by which to shift positions
void setSublaneOffset(int offset);

/// @brief whether a stopped vehicle is leader
bool hasStoppedVehicle() const;
Expand All @@ -122,7 +121,7 @@ class MSLeaderInfo {
double myWidth;

/// @brief an extra offset for shifting the interpretation of sublane borders (default [0,myWidth])
double myOffset;
int myOffset;

std::vector<const MSVehicle*> myVehicles;

Expand Down
4 changes: 2 additions & 2 deletions src/microsim/MSVehicle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2162,9 +2162,9 @@ MSVehicle::planMoveInternal(const SUMOTime t, MSLeaderInfo ahead, DriveItemVecto
// potential leaders that are also outside lane bounds
const bool outsideLeft = getLeftSideOnLane(lane) < 0;
if (outsideLeft) {
ahead.setSublaneOffset(ceil(-getLeftSideOnLane(lane) / MSGlobals::gLateralResolution) * MSGlobals::gLateralResolution);
ahead.setSublaneOffset(ceil(-getLeftSideOnLane(lane) / MSGlobals::gLateralResolution));
} else if (getRightSideOnLane(lane) > lane->getWidth()) {
ahead.setSublaneOffset(-ceil((getRightSideOnLane(lane) - getWidth()) / MSGlobals::gLateralResolution) * MSGlobals::gLateralResolution);
ahead.setSublaneOffset(-ceil((getRightSideOnLane(lane) - getWidth()) / MSGlobals::gLateralResolution));
}
for (const MSVehicle* cand : lane->getVehiclesSecure()) {
if ((lane != myLane || cand->getPositionOnLane() > getPositionOnLane())
Expand Down

0 comments on commit 0b0bf3b

Please sign in to comment.