X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;ds=sidebyside;f=source%2Flibr2c2%2Ftracktype.cpp;h=3c6876b0cc8b5bd72a7e0f476f45b6d631f2aa6a;hb=2875ea548e0567ad2ce1b8f9bda58e6452813204;hp=7a1f27ad5adcc69ee282a028d10755dabf68d37a;hpb=d405b9943c888e3945c7ea4e496f9d300b114fe0;p=r2c2.git diff --git a/source/libr2c2/tracktype.cpp b/source/libr2c2/tracktype.cpp index 7a1f27a..3c6876b 100644 --- a/source/libr2c2/tracktype.cpp +++ b/source/libr2c2/tracktype.cpp @@ -1,5 +1,6 @@ #include #include +#include "trackappearance.h" #include "tracktype.h" using namespace std; @@ -14,6 +15,11 @@ TrackType::TrackType(const ArticleNumber &an, const TrackAppearance &ta): autofit_preference(1) { } +float TrackType::get_gauge() const +{ + return appearance.get_gauge(); +} + float TrackType::get_total_length() const { return get_path_length(-1); @@ -44,6 +50,36 @@ unsigned TrackType::get_n_paths() const return n; } +unsigned TrackType::coerce_path(unsigned entry, unsigned path) const +{ + const Endpoint &ep = get_endpoint(entry); + if(ep.has_path(path)) + return path; + + unsigned paths = get_paths(); + if(paths>>(1<>p; p+=step) + if(ep.has_path(p)) + return p; + } + + // Find an endpoint that's connected to the entry and has the requested path + for(vector::const_iterator i=endpoints.begin(); i!=endpoints.end(); ++i) + if(i->has_path(path) && i->has_common_paths(ep)) + { + unsigned p = 1; + for(unsigned m=i->paths&ep.paths; m>>p; ++p) ; + return p-1; + } + + // TODO crossings fall here + throw logic_error("TrackType::coerce_path"); +} + bool TrackType::is_turnout() const { return endpoints.size()>2;