/* $Id$
This file is part of the MSP Märklin suite
-Copyright © 2006-2008 Mikkosoft Productions, Mikko Rasa
+Copyright © 2006-2009 Mikkosoft Productions, Mikko Rasa
Distributed under the GPL
*/
namespace Marklin {
TrackPart::TrackPart():
- x(0),
- y(0),
dir(0),
length(0),
radius(0),
dead_end(false)
{ }
-void TrackPart::collect_endpoints(vector<Endpoint> &eps)
+void TrackPart::collect_endpoints(vector<Endpoint> &eps) const
{
- eps.push_back(Endpoint(x, y, dir+M_PI, 1<<route));
+ eps.push_back(Endpoint(pos.x, pos.y, dir+M_PI, 1<<route));
if(dead_end)
;
else if(radius)
{
float a=((radius<0) ? -length : length);
+ Point p=get_point(length*abs(radius));
+ eps.push_back(Endpoint(p.x, p.y, dir+a, 1<<route));
+ }
+ else
+ eps.push_back(Endpoint(pos.x+cos(dir)*length, pos.y+sin(dir)*length, dir, 1<<route));
+}
+
+Point TrackPart::get_point(float d) const
+{
+ if(radius)
+ {
+ float a=d/radius;
float c=cos(a);
float s=sin(a);
float rx=radius*sin(dir);
float ry=-radius*cos(dir);
- eps.push_back(Endpoint(x+c*rx-s*ry-rx, y+c*ry+s*rx-ry, dir+a, 1<<route));
+ return Point(pos.x+c*rx-s*ry-rx, pos.y+c*ry+s*rx-ry);
}
else
- eps.push_back(Endpoint(x+cos(dir)*length, y+sin(dir)*length, dir, 1<<route));
+ return Point(pos.x+cos(dir)*d, pos.y+sin(dir)*d);
}
else
part.length/=1000;
- part.x/=1000;
- part.y/=1000;
+ part.pos.x/=1000;
+ part.pos.y/=1000;
part.dir*=M_PI/180;
}
void TrackPart::Loader::start(float x, float y, float d)
{
- part.x=x;
- part.y=y;
+ part.pos=Point(x, y);
part.dir=d;
}