]> git.tdb.fi Git - r2c2.git/commitdiff
Use path coercion in track iterators
authorMikko Rasa <tdb@tdb.fi>
Thu, 10 Apr 2014 19:04:03 +0000 (22:04 +0300)
committerMikko Rasa <tdb@tdb.fi>
Thu, 10 Apr 2014 19:29:10 +0000 (22:29 +0300)
This enforces common traversal rules in all places.  It also fixes a bug
in TrackOffsetIter where moving to a turnout from an endpoint not on the
selected path would potentially cause an out-of-range iterator to be
created.

source/libr2c2/trackiter.cpp
source/libr2c2/trackoffsetiter.cpp

index da949e75160351363b0ec2513deb81143a5ec6ea..330e2f66c810bd9ee2c38cd0c6f2f1ebd14ae6d7 100644 (file)
@@ -70,6 +70,7 @@ const TrackType::Endpoint &TrackIter::endpoint() const
 
 int TrackIter::get_exit(unsigned path) const
 {
+       path = _track->get_type().coerce_path(_entry, path);
        const vector<TrackType::Endpoint> &eps = _track->get_type().get_endpoints();
        
        // Find an endpoint that's connected to the entry and has the requested path
index 9676985b5b971a659bb6918c95c40f3d1f4bc5e5..8f21e950a5e3de4dfa3cfa5b1462b455cf90c9bb 100644 (file)
@@ -117,6 +117,7 @@ TrackOffsetIter TrackOffsetIter::advance(float d, const Route *r) const
        {
                if(p<0)
                        p = (r ? r->get_path(*t) : t->get_active_path());
+               p = t->get_type().coerce_path(t.entry(), p);
 
                float length = t->get_type().get_path_length(p);
                if(o<length)