]> git.tdb.fi Git - r2c2.git/blob - source/libr2c2/vehicleplacement.h
Don't use bool for a counter variable
[r2c2.git] / source / libr2c2 / vehicleplacement.h
1 #ifndef LIBR2C2_VEHICLEPLACEMENT_H_
2 #define LIBR2C2_VEHICLEPLACEMENT_H_
3
4 #include <vector>
5 #include "trackoffsetiter.h"
6 #include "vehicletype.h"
7
8 namespace R2C2 {
9
10 class VehiclePlacement
11 {
12 public:
13         enum Anchor
14         {
15                 CENTER,
16                 FRONT_AXLE,
17                 FRONT_BUFFER,
18                 BACK_AXLE,
19                 BACK_BUFFER
20         };
21
22 private:
23         struct Axle
24         {
25                 const VehicleType::Axle *type;
26                 TrackOffsetIter position;
27
28                 Axle(const VehicleType::Axle &);
29         };
30
31         const VehicleType &type;
32         std::vector<Axle> axles;
33         float front_back_span;
34         float front_back_ratio;
35
36 public:
37         VehiclePlacement(const VehicleType &);
38
39         void place(const TrackOffsetIter &, Anchor = CENTER);
40 private:
41         float get_anchor_position(Anchor) const;
42 public:
43         void place_after(const VehiclePlacement &);
44         void place_before(const VehiclePlacement &);
45         void unplace();
46         bool is_placed() const;
47
48         OrientedPoint get_point() const;
49         const TrackOffsetIter &get_axle_position(unsigned) const;
50         TrackOffsetIter get_position(Anchor) const;
51         OrientedPoint get_axle_point(unsigned) const;
52         OrientedPoint get_bogie_point(unsigned) const;
53 private:
54         OrientedPoint get_front_point() const;
55         OrientedPoint get_back_point() const;
56         OrientedPoint get_bogie_point_from_axle(unsigned) const;
57         static OrientedPoint create_point(const Vector &, const Vector &, float);
58
59 public:
60         void advance(float, Anchor = CENTER);
61 private:
62         void fix_positions(float);
63         void fix_bogie_position(unsigned);
64         static float compute_adjustment(const Vector &, const Vector &, float, float &);
65 };
66
67 } // namespace R2C2
68
69 #endif