Skip to content

Commit

Permalink
fixing internal junction position. refs #4252
Browse files Browse the repository at this point in the history
  • Loading branch information
namdre committed Jun 20, 2021
1 parent ba7ce3e commit cee8340
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 4 deletions.
18 changes: 15 additions & 3 deletions src/netbuild/NBEdge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1678,8 +1678,9 @@ NBEdge::buildInnerEdges(const NBNode& n, int noInternalNoSplits, int& linkIndex,
if (avoidedIntersectingLeftOriginLane == std::numeric_limits<int>::max()
|| avoidedIntersectingLeftOriginLane < con.fromLane) {
for (const PositionVector& otherShape : otherShapes) {
const bool secondIntersection = con.indirectLeft && this == i2 && con.fromLane == k2.fromLane;
const double minDV = firstIntersection(shape, otherShape, width2,
"Could not compute intersection of conflicting internal lanes at node '" + myTo->getID() + "'");
"Could not compute intersection of conflicting internal lanes at node '" + myTo->getID() + "'", secondIntersection);
if (minDV < shape.length() - POSITION_EPS && minDV > POSITION_EPS) { // !!!?
assert(minDV >= 0);
if (crossingPositions.first < 0 || crossingPositions.first > minDV) {
Expand All @@ -1699,8 +1700,9 @@ NBEdge::buildInnerEdges(const NBNode& n, int noInternalNoSplits, int& linkIndex,
crossingPositions.second.push_back(index);
const PositionVector otherShape = n.computeInternalLaneShape(i2, k2, numPoints, 0, shapeFlag);
otherShapes.push_back(otherShape);
const bool secondIntersection = con.indirectLeft && this == i2 && con.fromLane == k2.fromLane;
const double minDV = firstIntersection(shape, otherShape, width2,
"Could not compute intersection of conflicting internal lanes at node '" + myTo->getID() + "'");
"Could not compute intersection of conflicting internal lanes at node '" + myTo->getID() + "'", secondIntersection);
if (minDV < shape.length() - POSITION_EPS && minDV > POSITION_EPS) { // !!!?
assert(minDV >= 0);
if (crossingPositions.first < 0 || crossingPositions.first > minDV) {
Expand Down Expand Up @@ -1904,7 +1906,7 @@ NBEdge::assignInternalLaneLength(std::vector<Connection>::iterator i, int numLan
}

double
NBEdge::firstIntersection(const PositionVector& v1, const PositionVector& v2, double width2, const std::string& error) {
NBEdge::firstIntersection(const PositionVector& v1, const PositionVector& v2, double width2, const std::string& error, bool secondIntersection) {
double intersect = std::numeric_limits<double>::max();
if (v2.length() < POSITION_EPS) {
return intersect;
Expand All @@ -1917,10 +1919,20 @@ NBEdge::firstIntersection(const PositionVector& v1, const PositionVector& v2, do
v2Left.move2side(-width2);

// intersect center line of v1 with left and right border of v2
bool skip = secondIntersection;
for (double cand : v1.intersectsAtLengths2D(v2Right)) {
if (skip) {
skip = false;
continue;
}
intersect = MIN2(intersect, cand);
}
skip = secondIntersection;
for (double cand : v1.intersectsAtLengths2D(v2Left)) {
if (skip) {
skip = false;
continue;
}
intersect = MIN2(intersect, cand);
}
} catch (InvalidArgument&) {
Expand Down
2 changes: 1 addition & 1 deletion src/netbuild/NBEdge.h
Original file line number Diff line number Diff line change
Expand Up @@ -1404,7 +1404,7 @@ class NBEdge : public Named, public Parameterised, public NBRouterEdge {
void debugPrintConnections(bool outgoing = true, bool incoming = false) const;

/// @brief compute the first intersection point between the given lane geometries considering their rspective widths
static double firstIntersection(const PositionVector& v1, const PositionVector& v2, double width2, const std::string& error = "");
static double firstIntersection(const PositionVector& v1, const PositionVector& v2, double width2, const std::string& error = "", bool secondIntersection=false);

/** returns a modified version of laneShape which starts at the outside of startNode. laneShape may be shorted or extended
* @note see [wiki:Developer/Network_Building_Process]
Expand Down
3 changes: 3 additions & 0 deletions src/netbuild/NBNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -887,6 +887,9 @@ NBNode::needsCont(const NBEdge* fromE, const NBEdge* otherFromE,
if (thisRight && !rightTurnConflict) {
return false;
}
if (myRequest && myRequest->indirectLeftTurnConflict(fromE, c, otherFromE, otherC, false)) {
return true;
}
if (!(foes(otherFromE, otherToE, fromE, toE) || myRequest == nullptr || rightTurnConflict)) {
// if they do not cross, no waiting place is needed
return false;
Expand Down
17 changes: 17 additions & 0 deletions src/netbuild/NBRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,7 @@ NBRequest::getResponseString(const NBEdge* const from, const NBEdge::Connection&
|| rightTurnConflict(from, queryCon, *i, connected[k])
|| mergeConflict(from, queryCon, *i, connected[k], zipper)
|| oppositeLeftTurnConflict(from, queryCon, *i, connected[k], zipper)
|| indirectLeftTurnConflict(from, queryCon, *i, connected[k], zipper)
|| myJunction->rightOnRedConflict(c.tlLinkIndex, connected[k].tlLinkIndex)
|| (myJunction->tlsContConflict(from, c, *i, connected[k]) && hasLaneConflict
&& !OptionsCont::getOptions().getBool("tls.ignore-internal-junction-jam"))
Expand Down Expand Up @@ -725,6 +726,7 @@ NBRequest::getFoesString(NBEdge* from, NBEdge* to, int fromLane, int toLane, con
|| myJunction->turnFoes(from, to, fromLane, *i, connected[k].toEdge, connected[k].fromLane, lefthand)
|| mergeConflict(from, queryCon, *i, connected[k], true)
|| oppositeLeftTurnConflict(from, queryCon, *i, connected[k], true)
|| indirectLeftTurnConflict(from, queryCon, *i, connected[k], true)
) {
result += '1';
} else {
Expand Down Expand Up @@ -830,6 +832,21 @@ NBRequest::oppositeLeftTurnConflict(const NBEdge* from, const NBEdge::Connection
}
}

bool
NBRequest::indirectLeftTurnConflict(const NBEdge* from, const NBEdge::Connection& con,
const NBEdge* prohibitorFrom, const NBEdge::Connection& prohibitorCon, bool foes) const {
if (from == prohibitorFrom) {
if (con.indirectLeft) {
LinkDirection dir = myJunction->getDirection(prohibitorFrom, prohibitorCon.toEdge);
return (dir == LinkDirection::STRAIGHT);
} else if (foes && prohibitorCon.indirectLeft) {
LinkDirection dir = myJunction->getDirection(from, con.toEdge);
return (dir == LinkDirection::STRAIGHT);
}
}
return false;
}

bool
NBRequest::checkLaneFoesByClass(const NBEdge::Connection& con,
const NBEdge* prohibitorFrom, const NBEdge::Connection& prohibitorCon) const {
Expand Down
4 changes: 4 additions & 0 deletions src/netbuild/NBRequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ class NBRequest {
bool oppositeLeftTurnConflict(const NBEdge* from, const NBEdge::Connection& con,
const NBEdge* prohibitorFrom, const NBEdge::Connection& prohibitorCon, bool foes) const;

/// @brief whether straight and indirect left turn are in conflict
bool indirectLeftTurnConflict(const NBEdge* from, const NBEdge::Connection& con,
const NBEdge* prohibitorFrom, const NBEdge::Connection& prohibitorCon, bool foes) const;


/// @brief whether there are conflicting streams of traffic at this node
bool hasConflict() const;
Expand Down

0 comments on commit cee8340

Please sign in to comment.