]> git.tdb.fi Git - r2c2.git/blobdiff - source/libr2c2/tracktype.cpp
Perform check_slope automatically with certain operations
[r2c2.git] / source / libr2c2 / tracktype.cpp
index c7a6aef7ba70fa85bac12a2ac2c1ff1738cc6a6e..3be1ecb364e8631a84ac216960bc154a82277510 100644 (file)
@@ -7,7 +7,7 @@ using namespace Msp;
 namespace R2C2 {
 
 TrackType::TrackType(const ArticleNumber &an):
-       art_nr(an),
+       ObjectType(an),
        state_bits(0),
        autofit_preference(1)
 { }
@@ -69,7 +69,7 @@ TrackPoint TrackType::get_point(unsigned epi, unsigned path, float d) const
        unsigned part_ep = 0;
        for(vector<TrackPart>::const_iterator i=parts.begin(); i!=parts.end(); ++i)
        {
-               if((endpoints[epi].paths&(1<<path)) && i->get_path()!=path)
+               if(endpoints[epi].has_path(path) && i->get_path()!=path)
                        continue;
 
                unsigned n_part_eps = (i->is_dead_end() ? 1 : 2);
@@ -113,6 +113,25 @@ TrackPoint TrackType::get_point(unsigned epi, unsigned path, float d) const
        }
 }
 
+TrackPoint TrackType::get_nearest_point(const Vector &p) const
+{
+       TrackPoint result;
+       float dist = -1;
+
+       for(vector<TrackPart>::const_iterator i=parts.begin(); i!=parts.end(); ++i)
+       {
+               TrackPoint n = i->get_nearest_point(p);
+               float d = distance(n.pos, p);
+               if(d<dist || dist<0)
+               {
+                       result = n;
+                       dist = d;
+               }
+       }
+
+       return result;
+}
+
 bool TrackType::collide_ray(const Vector &start, const Vector &dir, float width) const
 {
        for(vector<TrackPart>::const_iterator i=parts.begin(); i!=parts.end(); ++i)
@@ -173,11 +192,10 @@ TrackType::Endpoint::Endpoint(float x, float y, float d, unsigned p):
 
 
 TrackType::Loader::Loader(TrackType &t):
-       Msp::DataFile::BasicLoader<TrackType>(t),
+       DataFile::DerivedObjectLoader<TrackType, ObjectType::Loader>(t),
        state_bits_set(false)
 {
        add("autofit_preference", &TrackType::autofit_preference);
-       add("description", &TrackType::description);
        add("object",      &TrackType::object);
        add("state_bits",  &Loader::state_bits);
        add("part",        &Loader::part);