X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Flibr2c2%2Fsignal.cpp;h=650c36232e87d82559fc36cfbb6aba2bc160ab55;hb=b88d3630a0e3fdd763db018bbe5dbfe3180a95f2;hp=72cf235193e6a9c537e67a003ede7a221b8c7673;hpb=2910db1364914c0ab98a0f80250cc39137821577;p=r2c2.git diff --git a/source/libr2c2/signal.cpp b/source/libr2c2/signal.cpp index 72cf235..650c362 100644 --- a/source/libr2c2/signal.cpp +++ b/source/libr2c2/signal.cpp @@ -56,12 +56,15 @@ void Signal::set_position(const Vector &p) for(set::const_iterator i=tracks.begin(); i!=tracks.end(); ++i) if(!(*i)->get_type().is_turnout()) { - TrackPoint n = (*i)->get_nearest_point(p); - float d = distance(p, n.pos); + Snap sn; + sn.position = p; + sn.rotation = rotation; + (*i)->snap(sn, 1000, SNAP_SEGMENT); + float d = distance(p, sn.position); if(dget_type().get_endpoints().size(); for(unsigned j=0; jget_endpoint_direction(j)-rotation; + float a = track->get_snap_node(j).rotation-rotation; while(a<-M_PI/2) a += M_PI*2; while(a>M_PI*3/2) @@ -107,6 +110,30 @@ void Signal::set_rotation(float r) normalize_location(); } +unsigned Signal::get_n_snap_nodes() const +{ + return 1; +} + +Snap Signal::get_snap_node(unsigned i) const +{ + if(i>=1) + throw out_of_range("Signal::get_snap_node"); + + Snap sn; + sn.position = position; + sn.rotation = rotation; + return sn; +} + +SnapType Signal::get_default_snap_type_to(const Object &other) const +{ + if(dynamic_cast(&other)) + return SNAP_SEGMENT; + + return NO_SNAP; +} + bool Signal::collide_ray(const Vector &start, const Vector &ray) const { // XXX Totally hardcoded stuff, should be replaced with a geometry system