]> git.tdb.fi Git - r2c2.git/blobdiff - source/libr2c2/tracktype.cpp
Make use of the mspmath library
[r2c2.git] / source / libr2c2 / tracktype.cpp
index bf038c52d76c2d19576e5b9a1b30e059a4837306..fbed4c1d8d6020b9b19ed4c234b1c002d43f8b64 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)
 { }
@@ -76,9 +76,8 @@ TrackPoint TrackType::get_point(unsigned epi, unsigned path, float d) const
                for(unsigned j=0; j<n_part_eps; ++j)
                {
                        TrackPoint p = i->get_point(j ? i->get_length() : 0);
-                       float dx = p.pos.x-endpoints[epi].pos.x;
-                       float dy = p.pos.y-endpoints[epi].pos.y;
-                       if(dx*dx+dy*dy<1e-6)
+                       Vector span = p.pos-endpoints[epi].pos;
+                       if(dot(span, span)<1e-6)
                        {
                                part = &*i;
                                part_ep = j;
@@ -98,7 +97,7 @@ TrackPoint TrackType::get_point(unsigned epi, unsigned path, float d) const
                                d = plen-d;
                        TrackPoint p = part->get_point(d);
                        if(part_ep==1)
-                               p.dir += M_PI;
+                               p.dir += Angle::half_turn();
                        return p;
                }
                else
@@ -156,21 +155,16 @@ void TrackType::collect_endpoints()
                        {
                                TrackPoint p = i->get_point(j ? i->get_length() : 0);
                                if(j==0)
-                                       p.dir += M_PI;
+                                       p.dir += Angle::half_turn();
 
                                bool found = false;
                                for(vector<Endpoint>::iterator k=endpoints.begin(); k!=endpoints.end(); ++k)
                                {
-                                       float dx = k->pos.x-p.pos.x;
-                                       float dy = k->pos.y-p.pos.y;
+                                       Vector d = k->pos-p.pos;
 
-                                       float da = k->dir-p.dir;
-                                       while(da>M_PI)
-                                               da -= M_PI*2;
-                                       while(da<-M_PI)
-                                               da += M_PI*2;
+                                       Angle da = wrap_balanced(k->dir-p.dir);
 
-                                       if(dx*dx+dy*dy<1e-6 && da>-0.01 && da<0.01)
+                                       if(dot(d, d)<1e-6 && abs(da).radians()<0.01)
                                        {
                                                k->paths |= 1<<i->get_path();
                                                found = true;
@@ -184,19 +178,18 @@ void TrackType::collect_endpoints()
        }
 }
 
-TrackType::Endpoint::Endpoint(float x, float y, float d, unsigned p):
-       pos(x, y),
+TrackType::Endpoint::Endpoint(float x, float y, const Angle &d, unsigned p):
+       pos(x, y, 0),
        dir(d),
        paths(p)
 { }
 
 
 TrackType::Loader::Loader(TrackType &t):
-       Msp::DataFile::ObjectLoader<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);