]> git.tdb.fi Git - r2c2.git/blobdiff - source/libr2c2/vehicleplacement.cpp
Clear the critical flag one track earlier
[r2c2.git] / source / libr2c2 / vehicleplacement.cpp
index 9f9001fb0b7562c073b5c99634d5b98793d40a93..273a9cc32e43091396bb04ab5b7ee3cf2e1a84f5 100644 (file)
@@ -51,6 +51,9 @@ VehiclePlacement::VehiclePlacement(const VehicleType &t):
 
 void VehiclePlacement::place(const TrackOffsetIter &p, Anchor a)
 {
+       if(!p)
+               return unplace();
+
        float anchor = get_anchor_position(a);
 
        for(vector<Axle>::iterator i=axles.begin(); i!=axles.end(); ++i)
@@ -178,7 +181,7 @@ OrientedPoint VehiclePlacement::create_point(const Vector &front, const Vector &
        OrientedPoint result;
        result.position = front*(1-ratio)+back*ratio;
        result.rotation = Geometry::atan2<float>(front.y-back.y, front.x-back.x);
-       result.tilt = Geometry::atan2<float>(front.z-back.z, LinAl::Vector<float, 2>(front-back).norm());
+       result.tilt = Geometry::atan2<float>(front.z-back.z, (front-back).slice<2>(0).norm());
        return result;
 }
 
@@ -246,9 +249,9 @@ float VehiclePlacement::compute_adjustment(const Vector &p1, const Vector &p2, f
        float span = distance(p1, p2);
        float adjust = target-span;
 
-       /* If the adjustment is larger than the last one, we've hit a gap or
+       /* If the adjustment is not smaller than the last one, we've hit a gap or
        other oddity in the track.  Terminate to avoid an infinite loop. */
-       if(last>0 && abs(adjust)>last)
+       if(last>0 && abs(adjust)>=last)
                return 0;
 
        if(abs(adjust)*10000<target)