3 This file is part of R²C²
4 Copyright © 2006-2010 Mikkosoft Productions, Mikko Rasa
5 Distributed under the GPL
16 TrackPart::TrackPart():
27 float TrackPart::get_length() const
30 return abs(radius)*length;
35 TrackPoint TrackPart::get_point(float d) const
44 float rx = radius*sin(dir);
45 float ry = -radius*cos(dir);
46 result.pos = Point(pos.x+c*rx-s*ry-rx, pos.y+c*ry+s*rx-ry);
51 result.pos = Point(pos.x+cos(dir)*d, pos.y+sin(dir)*d);
58 void TrackPart::check_link(TrackPart &other)
60 unsigned n_eps = (dead_end ? 1 : 2);
61 unsigned n_other_eps = (other.is_dead_end() ? 1 : 2);
62 for(unsigned i=0; i<n_eps; ++i)
64 TrackPoint p1 = get_point(i ? get_length() : 0);
65 for(unsigned j=0; j<n_other_eps; ++j)
67 TrackPoint p2 = other.get_point(j ? other.get_length() : 0);
69 float dx = p2.pos.x-p1.pos.x;
70 float dy = p2.pos.y-p1.pos.y;
72 float da = p2.dir-p1.dir+M_PI*((i+j+1)%2);
78 if(dx*dx+dy*dy<1e-6 && da>=-0.01 && da<=0.01)
81 other.links[j] = this;
88 TrackPart *TrackPart::get_link(unsigned i) const
91 throw InvalidParameterValue("Index out of range");
96 TrackPart::Loader::Loader(TrackPart &p):
97 Msp::DataFile::BasicLoader<TrackPart>(p)
99 add("start", &Loader::start);
100 add("length", &TrackPart::length);
101 add("radius", &TrackPart::radius);
102 add("path", &TrackPart::path);
103 add("dead_end", &TrackPart::dead_end);
106 void TrackPart::Loader::finish()
110 obj.length *= M_PI/180;
121 void TrackPart::Loader::start(float x, float y, float d)
123 obj.pos = Point(x, y);