]> git.tdb.fi Git - r2c2.git/blob - source/libr2c2/tracktype.h
Make use of the mspmath library
[r2c2.git] / source / libr2c2 / tracktype.h
1 #ifndef LIBR2C2_TRACKTYPE_H_
2 #define LIBR2C2_TRACKTYPE_H_
3
4 #include <msp/datafile/objectloader.h>
5 #include "articlenumber.h"
6 #include "geometry.h"
7 #include "objecttype.h"
8 #include "trackpart.h"
9
10 namespace R2C2 {
11
12 class TrackType: public ObjectType
13 {
14 public:
15         struct Endpoint
16         {
17                 Vector pos;
18                 Angle dir;  // Direction outwards from the endpoint
19                 unsigned paths;
20
21                 Endpoint(float, float, const Angle &, unsigned);
22
23                 bool has_path(unsigned p) const { return paths&(1<<p); }
24                 bool has_common_paths(const Endpoint &e) const { return paths&e.paths; }
25         };
26
27         class Loader: public Msp::DataFile::DerivedObjectLoader<TrackType, ObjectType::Loader>
28         {
29         private:
30                 bool state_bits_set;
31
32         public:
33                 Loader(TrackType &);
34         private:
35                 virtual void finish();
36                 void part();
37                 void position(float, float, float);
38                 void state_bits(unsigned);
39         };
40
41 private:
42         std::vector<TrackPart> parts;
43         std::vector<Endpoint> endpoints;
44         unsigned state_bits;
45         unsigned autofit_preference;
46         std::string object;
47
48 public:
49         TrackType(const ArticleNumber &);
50
51         float get_total_length() const;
52         float get_path_length(int) const;
53         unsigned get_paths() const;
54         unsigned get_n_paths() const;
55         unsigned get_state_bits() const { return state_bits; }
56         bool is_turnout() const;
57         bool is_dead_end() const;
58         unsigned get_autofit_preference() const { return autofit_preference; }
59         const std::string &get_object() const { return object; }
60         const std::vector<TrackPart> &get_parts() const { return parts; }
61         const std::vector<Endpoint> &get_endpoints() const { return endpoints; }
62         const Endpoint &get_endpoint(unsigned) const;
63         TrackPoint get_point(unsigned, unsigned, float) const;
64         TrackPoint get_nearest_point(const Vector &) const;
65         bool collide_ray(const Vector &, const Vector &, float) const;
66
67 private:
68         void collect_endpoints();
69 };
70
71 } // namespace R2C2
72
73 #endif