]> git.tdb.fi Git - r2c2.git/blobdiff - source/libr2c2/tracktype.h
Move path coercion to TrackType
[r2c2.git] / source / libr2c2 / tracktype.h
index cc0cc517bffbff9686c8c6cae3a41fc139bdcfe6..56d164f1b652a308a58a7ec1b0cf7505d6491631 100644 (file)
@@ -1,26 +1,32 @@
 #ifndef LIBR2C2_TRACKTYPE_H_
 #define LIBR2C2_TRACKTYPE_H_
 
-#include <msp/datafile/loader.h>
+#include <msp/datafile/objectloader.h>
 #include "articlenumber.h"
 #include "geometry.h"
+#include "objecttype.h"
 #include "trackpart.h"
 
 namespace R2C2 {
 
-class TrackType
+class TrackAppearance;
+
+class TrackType: public ObjectType
 {
 public:
        struct Endpoint
        {
                Vector pos;
-               float dir;  // Direction outwards from the endpoint
+               Angle dir;  // Direction outwards from the endpoint
                unsigned paths;
 
-               Endpoint(float, float, float, unsigned);
+               Endpoint(float, float, const Angle &, unsigned);
+
+               bool has_path(unsigned p) const { return paths&(1<<p); }
+               bool has_common_paths(const Endpoint &e) const { return paths&e.paths; }
        };
 
-       class Loader: public Msp::DataFile::BasicLoader<TrackType>
+       class Loader: public Msp::DataFile::DerivedObjectLoader<TrackType, ObjectType::Loader>
        {
        private:
                bool state_bits_set;
@@ -35,8 +41,7 @@ public:
        };
 
 private:
-       ArticleNumber art_nr;
-       std::string description;
+       const TrackAppearance &appearance;
        std::vector<TrackPart> parts;
        std::vector<Endpoint> endpoints;
        unsigned state_bits;
@@ -44,14 +49,14 @@ private:
        std::string object;
 
 public:
-       TrackType(const ArticleNumber &);
+       TrackType(const ArticleNumber &, const TrackAppearance &);
 
-       const ArticleNumber &get_article_number() const { return art_nr; }
-       const std::string &get_description() const { return description; }
+       const TrackAppearance &get_appearance() const { return appearance; }
        float get_total_length() const;
        float get_path_length(int) const;
        unsigned get_paths() const;
        unsigned get_n_paths() const;
+       unsigned coerce_path(unsigned, unsigned) const;
        unsigned get_state_bits() const { return state_bits; }
        bool is_turnout() const;
        bool is_dead_end() const;
@@ -60,8 +65,8 @@ public:
        const std::vector<TrackPart> &get_parts() const { return parts; }
        const std::vector<Endpoint> &get_endpoints() const { return endpoints; }
        const Endpoint &get_endpoint(unsigned) const;
-       TrackPoint get_point(unsigned, unsigned, float) const;
-       bool collide_ray(const Vector &, const Vector &, float) const;
+       OrientedPoint get_point(unsigned, unsigned, float) const;
+       OrientedPoint get_nearest_point(const Vector &) const;
 
 private:
        void collect_endpoints();