return length;
}
-TrackPoint TrackPart::get_point(float d) const
+OrientedPoint TrackPart::get_point(float d) const
{
- TrackPoint result;
+ OrientedPoint result;
Transform dir_trans = Transform::rotation(dir, Vector(0, 0, 1));
if(radius)
{
Angle a = Angle::from_radians(d/radius);
Vector r = dir_trans.transform(Vector(0, -radius, 0));
- result.pos = pos-r+Transform::rotation(a, Vector(0, 0, 1)).transform(r);
- result.dir = dir+a;
+ result.position = pos-r+Transform::rotation(a, Vector(0, 0, 1)).transform(r);
+ result.rotation = dir+a;
}
else
{
- result.pos = pos+dir_trans.transform(Vector(d, 0, 0));
- result.dir = dir;
+ result.position = pos+dir_trans.transform(Vector(d, 0, 0));
+ result.rotation = dir;
}
return result;
}
-TrackPoint TrackPart::get_nearest_point(const Vector &p) const
+OrientedPoint TrackPart::get_nearest_point(const Vector &p) const
{
- TrackPoint tp;
+ OrientedPoint result;
Transform dir_trans = Transform::rotation(dir, Vector(0, 0, 1));
if(radius)
{
a = min(max(a, Angle::zero()), Angle::from_radians(length));
if(radius<0)
a = -a;
- tp.pos = pos-r+Transform::rotation(a, Vector(0, 0, 1)).transform(r);
- tp.dir = dir+a;
+ result.position = pos-r+Transform::rotation(a, Vector(0, 0, 1)).transform(r);
+ result.rotation = dir+a;
}
else
{
Vector v = p-pos;
Vector dir_vec = dir_trans.transform(Vector(1, 0, 0));
float d = min(max(dot(dir_vec, v), 0.0f), length);
- tp.pos = pos+dir_vec*d;
- tp.dir = dir;
+ result.position = pos+dir_vec*d;
+ result.rotation = dir;
}
- return tp;
+ return result;
}
void TrackPart::check_link(TrackPart &other)
unsigned n_other_eps = (other.is_dead_end() ? 1 : 2);
for(unsigned i=0; i<n_eps; ++i)
{
- TrackPoint p1 = get_point(i ? get_length() : 0);
+ OrientedPoint p1 = get_point(i ? get_length() : 0);
for(unsigned j=0; j<n_other_eps; ++j)
{
- TrackPoint p2 = other.get_point(j ? other.get_length() : 0);
+ OrientedPoint p2 = other.get_point(j ? other.get_length() : 0);
- Vector span = p2.pos-p1.pos;
+ Vector span = p2.position-p1.position;
- Angle da = wrap_balanced(p2.dir-p1.dir+Angle::half_turn()*float((i+j+1)%2));
+ Angle da = wrap_balanced(p2.rotation-p1.rotation+Angle::half_turn()*float((i+j+1)%2));
if(dot(span, span)<1e-6 && abs(da).radians()<=0.01)
{