From f0a07b42d7be7af5e3330c7733bc3d28a1b6f30e Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Mon, 8 Jun 2009 19:59:08 +0100 Subject: [PATCH] Calculate the (non)displaced entry points for points --- src/Map.cpp | 10 ++++----- src/Points.cpp | 56 +++++++++++++++++++++++++++++++++----------------- 2 files changed, 42 insertions(+), 24 deletions(-) diff --git a/src/Map.cpp b/src/Map.cpp index e7a3ade..49dbdd5 100644 --- a/src/Map.cpp +++ b/src/Map.cpp @@ -717,11 +717,11 @@ void Map::renderSector(IGraphicsPtr aContext, int id, tile.track->setMark(); // Draw the endpoints for debugging - //list > endpoints; - //tile.track->get()->getEndpoints(endpoints); - //for_each(endpoints.begin(), endpoints.end(), - // bind(&Map::highlightTile, this, aContext, placeholders::_1, - // make_tuple(0.9f, 0.1f, 0.1f))); + list > endpoints; + tile.track->get()->getEndpoints(endpoints); + for_each(endpoints.begin(), endpoints.end(), + bind(&Map::highlightTile, this, aContext, placeholders::_1, + make_tuple(0.9f, 0.1f, 0.1f))); } // Draw the station, if any diff --git a/src/Points.cpp b/src/Points.cpp index 8777fc4..458f0ec 100644 --- a/src/Points.cpp +++ b/src/Points.cpp @@ -45,6 +45,9 @@ public: private: void transform(const track::Direction& aDirection, double aDelta) const; void ensureValidDirection(track::Direction aDirection) const; + + Point displacedEndpoint() const; + Point straightEndpoint() const; int myX, myY; track::Direction myAxis; @@ -191,28 +194,43 @@ track::Connection Points::nextPosition(const track::TravelToken& aToken) const assert(false); } -void Points::getEndpoints(std::list >& aList) const +// Get the endpoint that follows the curve +Point Points::displacedEndpoint() const { - aList.push_back(makePoint(myX, myY)); - const int reflect = amReflected ? -1 : 1; - if (myAxis == axis::X) { - aList.push_back(makePoint(myX + 2, myY)); - aList.push_back(makePoint(myX + 2, myY + 1*reflect)); - } - else if (myAxis == -axis::X) { - aList.push_back(makePoint(myX - 2, myY)); - aList.push_back(makePoint(myX - 2, myY - 1*reflect)); - } - else if (myAxis == axis::Y) { - aList.push_back(makePoint(myX, myY + 2)); - aList.push_back(makePoint(myX - 1*reflect, myY + 2)); - } - else if (myAxis == -axis::Y) { - aList.push_back(makePoint(myX, myY - 2)); - aList.push_back(makePoint(myX + 1*reflect, myY - 2)); - } + if (myAxis == axis::X) + return makePoint(myX + 2, myY + 1*reflect); + else if (myAxis == -axis::X) + return makePoint(myX - 2, myY - 1*reflect); + else if (myAxis == axis::Y) + return makePoint(myX - 1*reflect, myY + 2); + else if (myAxis == -axis::Y) + return makePoint(myX + 1*reflect, myY - 2); + else + assert(false); +} + +// Get the endpoint that follows the straight track +Point Points::straightEndpoint() const +{ + if (myAxis == axis::X) + return makePoint(myX + 2, myY); + else if (myAxis == -axis::X) + return makePoint(myX - 2, myY); + else if (myAxis == axis::Y) + return makePoint(myX, myY + 2); + else if (myAxis == -axis::Y) + return makePoint(myX, myY - 2); + else + assert(false); +} + +void Points::getEndpoints(std::list >& aList) const +{ + aList.push_back(makePoint(myX, myY)); + aList.push_back(straightEndpoint()); + aList.push_back(displacedEndpoint()); } ITrackSegmentPtr Points::mergeExit(const Point& aPoint, -- 2.39.2