X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Flibr2c2%2Ftrackattachment.cpp;h=024166820dc8adcac64e2a2be16e710b19ed681b;hb=2875ea548e0567ad2ce1b8f9bda58e6452813204;hp=3d28651d882395bdd8baab18162e3e201ad3b1bc;hpb=e3e3a940c75dcad126d5cf08f0802efdab914568;p=r2c2.git diff --git a/source/libr2c2/trackattachment.cpp b/source/libr2c2/trackattachment.cpp index 3d28651..0241668 100644 --- a/source/libr2c2/trackattachment.cpp +++ b/source/libr2c2/trackattachment.cpp @@ -8,8 +8,7 @@ using namespace std; namespace R2C2 { TrackAttachment::TrackAttachment(Layout &l): - Object(l), - offset(0) + Object(l) { layout.signal_object_removed.connect(sigc::mem_fun(this, &TrackAttachment::object_removed)); } @@ -20,13 +19,20 @@ TrackAttachment::~TrackAttachment() track->remove_attachment(*this); } -void TrackAttachment::attach_to(const TrackIter &t, float o) +float TrackAttachment::get_offset_from_endpoint(unsigned epi) const +{ + if(epi==track.entry()) + return track.offset(); + else + return track->get_type().get_path_length(0)-track.offset(); +} + +void TrackAttachment::attach_to(const TrackOffsetIter &t) { if(track) track->remove_attachment(*this); track = t; - offset = o; if(track) track->add_attachment(*this); @@ -44,7 +50,8 @@ void TrackAttachment::attach_to_closest(float limit) Snap sn; sn.position = position; sn.rotation = rotation; - if((*i)->snap(sn, limit, SNAP_SEGMENT)) + float gauge = (*i)->get_type().get_gauge(); + if((*i)->snap(sn, gauge*limit, SNAP_SEGMENT)) { float d = distance(position, sn.position); if(dget_snap_node(trk.entry()).position; float dist = distance(epp, point); - float offs = dist; + float offs = min(dist, trk->get_type().get_path_length(0)); while(1) { - TrackPoint tp = trk->get_point(trk.entry(), offs); - float diff = dist-distance(epp, tp.pos); + OrientedPoint p = trk->get_point(trk.entry(), offs); + float diff = dist-distance(epp, p.position); if(abs(diff)