]> git.tdb.fi Git - r2c2.git/blobdiff - source/libmarklin/block.cpp
Compute Z bounds for Track3D
[r2c2.git] / source / libmarklin / block.cpp
index 9a9164ea292770380548aea3a2c517ac4fbe327d..d4a6878a68b1b6ba475b85fd17014fe490b6cceb 100644 (file)
@@ -5,7 +5,6 @@ Copyright © 2006-2009 Mikkosoft Productions, Mikko Rasa
 Distributed under the GPL
 */
 
-#include <iostream>
 #include "control.h"
 #include "block.h"
 #include "tracktype.h"
@@ -68,7 +67,7 @@ int Block::get_endpoint_by_link(const Block &other) const
        return -1;
 }
 
-int Block::traverse(unsigned epi, float *len) const
+unsigned Block::traverse(unsigned epi, float *len) const
 {
        if(epi>=endpoints.size())
                throw InvalidParameterValue("Endpoint index out of range");
@@ -93,17 +92,14 @@ int Block::traverse(unsigned epi, float *len) const
                if(len)
                        *len += track->get_type().get_path_length(cur_path);
 
-               int other_ep = track->traverse(track_ep, cur_path);
-               if(other_ep<0)
-                       return -1;
-
+               unsigned other_ep = track->traverse(track_ep, cur_path);
                for(unsigned i=0; i<endpoints.size(); ++i)
                        if(endpoints[i].track==track && endpoints[i].track_ep==static_cast<unsigned>(other_ep))
                                return i;
 
                Track *next = track->get_link(other_ep);
-               if(tracks.count(next)==0)
-                       return -1;
+               if(!tracks.count(next))
+                       throw LogicError("Block traversal strayed out of the block");
                track_ep = next->get_endpoint_by_link(*track);
                track = next;
        }
@@ -144,23 +140,6 @@ bool Block::reserve(const Train *t)
                return false;
 }
 
-void Block::print_debug()
-{
-       cout<<"Block "<<id;
-       if((*tracks.begin())->get_sensor_id())
-               cout<<", sensor="<<(*tracks.begin())->get_sensor_id();
-       cout<<'\n';
-       for(vector<Endpoint>::iterator i=endpoints.begin(); i!=endpoints.end(); ++i)
-       {
-               cout<<"  Endpoint, link=";
-               if(i->link)
-                       cout<<i->link->id;
-               else
-                       cout<<"none";
-               cout<<", paths="<<i->paths<<'\n';
-       }
-}
-
 void Block::find_paths(Track &track, unsigned track_ep, unsigned path, set<Track *> &visited)
 {
        visited.insert(&track);