X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Flibmarklin%2Ftrackpart.cpp;h=37c5f97a90b0fc81cae5eb150bb2cbd8a654e8d5;hb=9b05c573a38639827697fe393d55b7c76f5bde45;hp=046b9276ac23025a34ac586ef2509d74ca2b1d7f;hpb=319f90fd59587efc1242c34f307abc29f323642b;p=r2c2.git diff --git a/source/libmarklin/trackpart.cpp b/source/libmarklin/trackpart.cpp index 046b927..37c5f97 100644 --- a/source/libmarklin/trackpart.cpp +++ b/source/libmarklin/trackpart.cpp @@ -1,7 +1,7 @@ /* $Id$ This file is part of the MSP Märklin suite -Copyright © 2006-2009 Mikkosoft Productions, Mikko Rasa +Copyright © 2006-2010 Mikkosoft Productions, Mikko Rasa Distributed under the GPL */ @@ -9,6 +9,7 @@ Distributed under the GPL #include "trackpart.h" using namespace std; +using namespace Msp; namespace Marklin { @@ -16,71 +17,111 @@ TrackPart::TrackPart(): dir(0), length(0), radius(0), - route(0), + path(0), dead_end(false) -{ } +{ + links[0] = 0; + links[1] = 0; +} + +float TrackPart::get_length() const +{ + if(radius) + return abs(radius)*length; + else + return length; +} -void TrackPart::collect_endpoints(vector &eps) const +TrackPoint TrackPart::get_point(float d) const { - eps.push_back(Endpoint(pos.x, pos.y, dir+M_PI, 1<M_PI) + da -= M_PI*2; + while(da<-M_PI) + da += M_PI*2; + + if(dx*dx+dy*dy<1e-6 && da>=-0.01 && da<=0.01) + { + links[i] = &other; + other.links[j] = this; + return; + } + } } - else - return Point(pos.x+cos(dir)*d, pos.y+sin(dir)*d); +} + +TrackPart *TrackPart::get_link(unsigned i) const +{ + if(i>=2) + throw InvalidParameterValue("Index out of range"); + return links[i]; } TrackPart::Loader::Loader(TrackPart &p): - part(p) + Msp::DataFile::BasicLoader(p) { add("start", &Loader::start); add("length", &TrackPart::length); add("radius", &TrackPart::radius); - add("route", &TrackPart::route); + add("path", &TrackPart::path); add("dead_end", &TrackPart::dead_end); } void TrackPart::Loader::finish() { - if(part.radius) + if(obj.radius) { - part.length*=M_PI/180; - part.radius/=1000; + obj.length *= M_PI/180; + obj.radius /= 1000; } else - part.length/=1000; + obj.length /= 1000; - part.pos.x/=1000; - part.pos.y/=1000; - part.dir*=M_PI/180; + obj.pos.x /= 1000; + obj.pos.y /= 1000; + obj.dir *= M_PI/180; } void TrackPart::Loader::start(float x, float y, float d) { - part.pos=Point(x, y); - part.dir=d; + obj.pos = Point(x, y); + obj.dir = d; } } // namespace Marklin