Skip to content

Commit

Permalink
building shape for indirect left turn. refs #4252
Browse files Browse the repository at this point in the history
  • Loading branch information
namdre committed Jun 20, 2021
1 parent 730be8d commit ba7ce3e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/netbuild/NBNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ const int NBNode::AVOID_WIDE_RIGHT_TURN(2);
const int NBNode::FOUR_CONTROL_POINTS(4);
const int NBNode::AVOID_INTERSECTING_LEFT_TURNS(8);
const int NBNode::SCURVE_IGNORE(16);
const int NBNode::INDIRECT_LEFT(32);

// ===========================================================================
// method definitions
Expand Down Expand Up @@ -520,6 +521,9 @@ NBNode::computeSmoothShape(const PositionVector& begShape,
int shapeFlag) const {

bool ok = true;
if ((shapeFlag & INDIRECT_LEFT) != 0) {
return indirectLeftShape(begShape, endShape, numPoints);
}
PositionVector init = bezierControlPoints(begShape, endShape, isTurnaround, extrapolateBeg, extrapolateEnd, ok, recordError, DEG2RAD(5), shapeFlag);
#ifdef DEBUG_SMOOTH_GEOM
if (DEBUGCOND) {
Expand Down Expand Up @@ -700,6 +704,30 @@ NBNode::bezierControlPoints(
return init;
}

PositionVector
NBNode::indirectLeftShape(const PositionVector& begShape, const PositionVector& endShape, int numPoints) const {
UNUSED_PARAMETER(numPoints);
PositionVector result;
result.push_back(begShape.back());
//const double angle = GeomHelper::angleDiff(begShape.angleAt2D(-2), endShape.angleAt2D(0));
PositionVector endShapeBegLine(endShape[0], endShape[1]);
PositionVector begShapeEndLineRev(begShape[-1], begShape[-2]);
endShapeBegLine.extrapolate2D(100, true);
begShapeEndLineRev.extrapolate2D(100, true);
Position intersect = endShapeBegLine.intersectionPosition2D(begShapeEndLineRev);
if (intersect == Position::INVALID) {
WRITE_WARNING("Could not compute indirect left turn shape at node '" + getID() + "'");
} else {
Position dir = intersect;
dir.sub(endShape[0]);
dir.norm2d();
const double radius = myRadius == NBNode::UNSPECIFIED_RADIUS ? OptionsCont::getOptions().getFloat("default.junctions.radius") : myRadius;
dir.mul(radius);
result.push_back(intersect + dir);
}
result.push_back(endShape.front());
return result;
}

PositionVector
NBNode::computeInternalLaneShape(const NBEdge* fromE, const NBEdge::Connection& con, int numPoints, NBNode* recordError, int shapeFlag) const {
Expand Down Expand Up @@ -760,6 +788,9 @@ NBNode::computeInternalLaneShape(const NBEdge* fromE, const NBEdge::Connection&
if (dir == LinkDirection::LEFT || dir == LinkDirection::TURN) {
shapeFlag += AVOID_WIDE_LEFT_TURN;
}
if (con.indirectLeft) {
shapeFlag += INDIRECT_LEFT;
}
#ifdef DEBUG_SMOOTH_GEOM
if (DEBUGCOND) {
std::cout << "computeInternalLaneShape node " << getID() << " fromE=" << fromE->getID() << " toE=" << con.toEdge->getID() << "\n";
Expand Down
3 changes: 3 additions & 0 deletions src/netbuild/NBNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ class NBNode : public Named, public Parameterised {
static const int FOUR_CONTROL_POINTS;
static const int AVOID_INTERSECTING_LEFT_TURNS;
static const int SCURVE_IGNORE;
static const int INDIRECT_LEFT;

public:
/**@brief Constructor
Expand Down Expand Up @@ -607,6 +608,8 @@ class NBNode : public Named, public Parameterised {
bool& ok, NBNode* recordError = 0, double straightThresh = DEG2RAD(5),
int shapeFlag = 0);

/// @brief compute shape of indirect left turn
PositionVector indirectLeftShape(const PositionVector& begShape, const PositionVector& endShape, int numPoints) const;

/// @brief compute the displacement error during s-curve computation
double getDisplacementError() const {
Expand Down

0 comments on commit ba7ce3e

Please sign in to comment.