X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Flibr2c2%2Ftracktype.cpp;h=59b8f9ca275b4fe508b94fe77c32ec220ab83472;hb=df72b71642bbc5b9a4e5010ebca8643fbeea3ca8;hp=e9136ac741e704e574199f0d1630a499d6844306;hpb=64d23de66c33d0f77454c3db2e40cccc18f7851b;p=r2c2.git diff --git a/source/libr2c2/tracktype.cpp b/source/libr2c2/tracktype.cpp index e9136ac..59b8f9c 100644 --- a/source/libr2c2/tracktype.cpp +++ b/source/libr2c2/tracktype.cpp @@ -7,8 +7,9 @@ using namespace Msp; namespace R2C2 { -TrackType::TrackType(const ArticleNumber &an): +TrackType::TrackType(const ArticleNumber &an, const TrackAppearance &ta): ObjectType(an), + appearance(ta), state_bits(0), autofit_preference(1) { } @@ -43,6 +44,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;